Commit d04e6ea0 authored by Gustavo A. R. Silva's avatar Gustavo A. R. Silva Committed by Greg Kroah-Hartman

drm/ioctl: Fix Spectre v1 vulnerabilities

commit 505b5240 upstream.

nr is indirectly controlled by user-space, hence leading to a
potential exploitation of the Spectre variant 1 vulnerability.

This issue was detected with the help of Smatch:

drivers/gpu/drm/drm_ioctl.c:805 drm_ioctl() warn: potential spectre issue 'dev->driver->ioctls' [r]
drivers/gpu/drm/drm_ioctl.c:810 drm_ioctl() warn: potential spectre issue 'drm_ioctls' [r] (local cap)
drivers/gpu/drm/drm_ioctl.c:892 drm_ioctl_flags() warn: potential spectre issue 'drm_ioctls' [r] (local cap)

Fix this by sanitizing nr before using it to index dev->driver->ioctls
and drm_ioctls.

Notice that given that speculation windows are large, the policy is
to kill the speculation on the first load and not worry if it can be
completed with a dependent load/store [1].

[1] https://marc.info/?l=linux-kernel&m=152449131114778&w=2

Cc: stable@vger.kernel.org
Signed-off-by: default avatarGustavo A. R. Silva <gustavo@embeddedor.com>
Signed-off-by: default avatarDaniel Vetter <daniel.vetter@ffwll.ch>
Link: https://patchwork.freedesktop.org/patch/msgid/20181220000015.GA18973@embeddedorSigned-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
parent 5cebd962
...@@ -37,6 +37,7 @@ ...@@ -37,6 +37,7 @@
#include <linux/pci.h> #include <linux/pci.h>
#include <linux/export.h> #include <linux/export.h>
#include <linux/nospec.h>
/** /**
* DOC: getunique and setversion story * DOC: getunique and setversion story
...@@ -778,13 +779,17 @@ long drm_ioctl(struct file *filp, ...@@ -778,13 +779,17 @@ long drm_ioctl(struct file *filp,
if (is_driver_ioctl) { if (is_driver_ioctl) {
/* driver ioctl */ /* driver ioctl */
if (nr - DRM_COMMAND_BASE >= dev->driver->num_ioctls) unsigned int index = nr - DRM_COMMAND_BASE;
if (index >= dev->driver->num_ioctls)
goto err_i1; goto err_i1;
ioctl = &dev->driver->ioctls[nr - DRM_COMMAND_BASE]; index = array_index_nospec(index, dev->driver->num_ioctls);
ioctl = &dev->driver->ioctls[index];
} else { } else {
/* core ioctl */ /* core ioctl */
if (nr >= DRM_CORE_IOCTL_COUNT) if (nr >= DRM_CORE_IOCTL_COUNT)
goto err_i1; goto err_i1;
nr = array_index_nospec(nr, DRM_CORE_IOCTL_COUNT);
ioctl = &drm_ioctls[nr]; ioctl = &drm_ioctls[nr];
} }
...@@ -866,6 +871,7 @@ bool drm_ioctl_flags(unsigned int nr, unsigned int *flags) ...@@ -866,6 +871,7 @@ bool drm_ioctl_flags(unsigned int nr, unsigned int *flags)
if (nr >= DRM_CORE_IOCTL_COUNT) if (nr >= DRM_CORE_IOCTL_COUNT)
return false; return false;
nr = array_index_nospec(nr, DRM_CORE_IOCTL_COUNT);
*flags = drm_ioctls[nr].flags; *flags = drm_ioctls[nr].flags;
return true; return true;
......
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