drm/xe: Fix array bounds check for queries
authorUmesh Nerlige Ramappa <umesh.nerlige.ramappa@intel.com>
Wed, 20 Sep 2023 19:29:21 +0000 (15:29 -0400)
committerRodrigo Vivi <rodrigo.vivi@intel.com>
Thu, 21 Dec 2023 16:43:01 +0000 (11:43 -0500)
Queries are 0-indexed, so a query with value N is invalid if the
ARRAY_SIZE is N. Modify the check to account for that.

Fixes: dd08ebf6c352 ("drm/xe: Introduce a new DRM driver for Intel GPUs")
Signed-off-by: Umesh Nerlige Ramappa <umesh.nerlige.ramappa@intel.com>
Reviewed-by: Niranjana Vishwanathapura <niranjana.vishwanathapura@intel.com>
Signed-off-by: Francois Dugast <francois.dugast@intel.com>
Signed-off-by: Rodrigo Vivi <rodrigo.vivi@intel.com>
drivers/gpu/drm/xe/xe_query.c

index a951205100fea15ff5f1544a709343f9a7bb2729..e0c2203e428e17aa0b4963600995bf3def34b541 100644 (file)
@@ -381,7 +381,7 @@ int xe_query_ioctl(struct drm_device *dev, void *data, struct drm_file *file)
            XE_IOCTL_DBG(xe, query->reserved[0] || query->reserved[1]))
                return -EINVAL;
 
-       if (XE_IOCTL_DBG(xe, query->query > ARRAY_SIZE(xe_query_funcs)))
+       if (XE_IOCTL_DBG(xe, query->query >= ARRAY_SIZE(xe_query_funcs)))
                return -EINVAL;
 
        idx = array_index_nospec(query->query, ARRAY_SIZE(xe_query_funcs));