Commit 540ead8c authored by Chris Wilson's avatar Chris Wilson Committed by Joonas Lahtinen

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: a446ae2c ("drm/i915: add query uAPI")
Signed-off-by: default avatarChris Wilson <chris@chris-wilson.co.uk>
Cc: Lionel Landwerlin <lionel.g.landwerlin@intel.com>
Cc: Joonas Lahtinen <joonas.lahtinen@linux.intel.com>
Cc: Tvrtko Ursulin <tvrtko.ursulin@intel.com>
Reviewed-by: default avatarLionel Landwerlin <lionel.g.landwerlin@intel.com>
Link: https://patchwork.freedesktop.org/patch/msgid/20180521210530.26008-1-chris@chris-wilson.co.uk
(cherry picked from commit 84b510e2)
Signed-off-by: default avatarJoonas Lahtinen <joonas.lahtinen@linux.intel.com>
parent b9eb9c92
...@@ -4,6 +4,8 @@ ...@@ -4,6 +4,8 @@
* Copyright © 2018 Intel Corporation * Copyright © 2018 Intel Corporation
*/ */
#include <linux/nospec.h>
#include "i915_drv.h" #include "i915_drv.h"
#include "i915_query.h" #include "i915_query.h"
#include <uapi/drm/i915_drm.h> #include <uapi/drm/i915_drm.h>
...@@ -111,10 +113,12 @@ int i915_query_ioctl(struct drm_device *dev, void *data, struct drm_file *file) ...@@ -111,10 +113,12 @@ int i915_query_ioctl(struct drm_device *dev, void *data, struct drm_file *file)
func_idx = item.query_id - 1; func_idx = item.query_id - 1;
if (func_idx < ARRAY_SIZE(i915_query_funcs)) ret = -EINVAL;
if (func_idx < ARRAY_SIZE(i915_query_funcs)) {
func_idx = array_index_nospec(func_idx,
ARRAY_SIZE(i915_query_funcs));
ret = i915_query_funcs[func_idx](dev_priv, &item); ret = i915_query_funcs[func_idx](dev_priv, &item);
else }
ret = -EINVAL;
/* Only write the length back to userspace if they differ. */ /* Only write the length back to userspace if they differ. */
if (ret != item.length && put_user(ret, &user_item_ptr->length)) if (ret != item.length && put_user(ret, &user_item_ptr->length))
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment