Skip to content

Commit 540ead8

Browse files
icklejlahtine-intel
authored andcommitted
drm/i915/query: Protect tainted function pointer lookup
Smatch identifies i915_query_ioctl() as being a potential victim of Spectre due to its use of a tainted user index into a function pointer array. Use array_index_nospec() to defang the user index before using it to lookup the function pointer. Fixes: a446ae2 ("drm/i915: add query uAPI") Signed-off-by: Chris Wilson <[email protected]> Cc: Lionel Landwerlin <[email protected]> Cc: Joonas Lahtinen <[email protected]> Cc: Tvrtko Ursulin <[email protected]> Reviewed-by: Lionel Landwerlin <[email protected]> Link: https://patchwork.freedesktop.org/patch/msgid/[email protected] (cherry picked from commit 84b510e) Signed-off-by: Joonas Lahtinen <[email protected]>
1 parent b9eb9c9 commit 540ead8

File tree

1 file changed

+7
-3
lines changed

1 file changed

+7
-3
lines changed

drivers/gpu/drm/i915/i915_query.c

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@
44
* Copyright © 2018 Intel Corporation
55
*/
66

7+
#include <linux/nospec.h>
8+
79
#include "i915_drv.h"
810
#include "i915_query.h"
911
#include <uapi/drm/i915_drm.h>
@@ -111,10 +113,12 @@ int i915_query_ioctl(struct drm_device *dev, void *data, struct drm_file *file)
111113

112114
func_idx = item.query_id - 1;
113115

114-
if (func_idx < ARRAY_SIZE(i915_query_funcs))
116+
ret = -EINVAL;
117+
if (func_idx < ARRAY_SIZE(i915_query_funcs)) {
118+
func_idx = array_index_nospec(func_idx,
119+
ARRAY_SIZE(i915_query_funcs));
115120
ret = i915_query_funcs[func_idx](dev_priv, &item);
116-
else
117-
ret = -EINVAL;
121+
}
118122

119123
/* Only write the length back to userspace if they differ. */
120124
if (ret != item.length && put_user(ret, &user_item_ptr->length))

0 commit comments

Comments
 (0)