Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

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 <jordy@pwning.systems>
Fixes: c02a81fba74f ("dma-buf: Add dma-buf heaps framework")
Cc: <stable@vger.kernel.org> # v5.6+
Acked-by: John Stultz <john.stultz@linaro.org>
Signed-off-by: Sumit Semwal <sumit.semwal@linaro.org>
[sumits: added fixes and cc: stable tags]
Link: https://patchwork.freedesktop.org/patch/msgid/20220129150604.3461652-1-jordy@pwning.systems

authored by

Jordy Zomer and committed by
Sumit Semwal
92c4cfae 1b777d4d

+2
+2
drivers/dma-buf/dma-heap.c
··· 14 14 #include <linux/xarray.h> 15 15 #include <linux/list.h> 16 16 #include <linux/slab.h> 17 + #include <linux/nospec.h> 17 18 #include <linux/uaccess.h> 18 19 #include <linux/syscalls.h> 19 20 #include <linux/dma-heap.h> ··· 136 135 if (nr >= ARRAY_SIZE(dma_heap_ioctl_cmds)) 137 136 return -EINVAL; 138 137 138 + nr = array_index_nospec(nr, ARRAY_SIZE(dma_heap_ioctl_cmds)); 139 139 /* Get the kernel ioctl cmd that matches */ 140 140 kcmd = dma_heap_ioctl_cmds[nr]; 141 141