Skip to content

Commit 92c4cfa

Browse files
JordyZomersumitsemwal
authored andcommitted
dma-buf: heaps: Fix potential spectre v1 gadget
It appears like nr could be a Spectre v1 gadget as it's supplied by a user and used as an array index. Prevent the contents of kernel memory from being leaked to userspace via speculative execution by using array_index_nospec. Signed-off-by: Jordy Zomer <[email protected]> Fixes: c02a81f ("dma-buf: Add dma-buf heaps framework") Cc: <[email protected]> # v5.6+ Acked-by: John Stultz <[email protected]> Signed-off-by: Sumit Semwal <[email protected]> [sumits: added fixes and cc: stable tags] Link: https://patchwork.freedesktop.org/patch/msgid/[email protected]
1 parent 1b777d4 commit 92c4cfa

File tree

1 file changed

+2
-0
lines changed

1 file changed

+2
-0
lines changed

drivers/dma-buf/dma-heap.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
#include <linux/xarray.h>
1515
#include <linux/list.h>
1616
#include <linux/slab.h>
17+
#include <linux/nospec.h>
1718
#include <linux/uaccess.h>
1819
#include <linux/syscalls.h>
1920
#include <linux/dma-heap.h>
@@ -135,6 +136,7 @@ static long dma_heap_ioctl(struct file *file, unsigned int ucmd,
135136
if (nr >= ARRAY_SIZE(dma_heap_ioctl_cmds))
136137
return -EINVAL;
137138

139+
nr = array_index_nospec(nr, ARRAY_SIZE(dma_heap_ioctl_cmds));
138140
/* Get the kernel ioctl cmd that matches */
139141
kcmd = dma_heap_ioctl_cmds[nr];
140142

0 commit comments

Comments
 (0)