Skip to contentSkip to conversation

drm/bufs: Fix Spectre v1 vulnerability

PATCH In review Gustavo A. R. Silva 2 participants 3 messages Oct 16, 2018 – Oct 17, 2018

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 drm/bufs: Fix Spectre v1 vulnerability

idx can be 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_bufs.c:1420 drm_legacy_freebufs() warn: potential spectre issue 'dma->buflist' [r] (local cap)

Fix this by sanitizing idx before using it to index dma->buflist

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

---
 drivers/gpu/drm/drm_bufs.c | 3 +++
 1 file changed, 3 insertions(+)
drivers/gpu/drm/drm_bufs.c +3 -0
index 7412aca..d7d10ca 100644
@@ -36,6 +36,8 @@
 #include <drm/drmP.h>
 #include "drm_legacy.h"
 
+#include <linux/nospec.h>
+
 static struct drm_map_list *drm_find_matching_map(struct drm_device *dev,
 						  struct drm_local_map *map)
 {
@@ -1417,6 +1419,7 @@ int drm_legacy_freebufs(struct drm_device *dev, void *data,
 				  idx, dma->buf_count - 1);
 			return -EINVAL;
 		}
+		idx = array_index_nospec(idx, dma->buf_count);
 		buf = dma->buflist[idx];
 		if (buf->file_priv != file_priv) {
 			DRM_ERROR("Process %d freeing buffer not owned\n",
Signature · 1 line
2.7.4
#1 lore raw
Quoted 10 lines · Gustavo A. R. Silva

idx can be 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_bufs.c:1420 drm_legacy_freebufs() warn: potential spectre issue 'dma->buflist' [r] (local cap)

Fix this by sanitizing idx before using it to index dma->buflist

Quoted 8 lines

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

Applied since it's correct, but I dropped the cc: stable. This code is very dead and full of security issues, and spectre is the least of your worries. If you want to a stab at fixing the real spectre issues in drm, then look anywhere that isn't full of drm_legacy_* functions.

The most important file is probably drm_ioctl.c.
-Daniel

Quoted 32 lines
---
 drivers/gpu/drm/drm_bufs.c | 3 +++
 1 file changed, 3 insertions(+)
drivers/gpu/drm/drm_bufs.c +3 -0
index 7412aca..d7d10ca 100644
@@ -36,6 +36,8 @@
 #include <drm/drmP.h>
 #include "drm_legacy.h"
 
+#include <linux/nospec.h>
+
 static struct drm_map_list *drm_find_matching_map(struct drm_device *dev,
 						  struct drm_local_map *map)
 {
@@ -1417,6 +1419,7 @@ int drm_legacy_freebufs(struct drm_device *dev, void *data,
 				  idx, dma->buf_count - 1);
 			return -EINVAL;
 		}
+		idx = array_index_nospec(idx, dma->buf_count);
 		buf = dma->buflist[idx];
 		if (buf->file_priv != file_priv) {
 			DRM_ERROR("Process %d freeing buffer not owned\n",
Signature · 6 lines
2.7.4

_______________________________________________
dri-devel mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/dri-devel
Signature · 3 lines
Daniel Vetter
Software Engineer, Intel Corporation
http://blog.ffwll.ch
#2 lore raw
Quoted 8 lines · Daniel Vetter
Quoted 2 lines

Applied since it's correct, but I dropped the cc: stable. This code is very dead and full of security issues, and spectre is the least of your worries. If you want to a stab at fixing the real spectre issues in drm, then look anywhere that isn't full of drm_legacy_* functions.

OK. I've got it.

Quoted 3 lines

The most important file is probably drm_ioctl.c.
-Daniel

Thanks for the feedback, Daniel.
--
Gustavo