linux-stable/include
Kees Cook 0c2b778edd uaccess: Add minimum bounds check on kernel buffer size
[ Upstream commit 04ffde1319 ]

While there is logic about the difference between ksize and usize,
copy_struct_from_user() didn't check the size of the destination buffer
(when it was known) against ksize. Add this check so there is an upper
bounds check on the possible memset() call, otherwise lower bounds
checks made by callers will trigger bounds warnings under -Warray-bounds.
Seen under GCC 13:

In function 'copy_struct_from_user',
    inlined from 'iommufd_fops_ioctl' at
../drivers/iommu/iommufd/main.c:333:8:
../include/linux/fortify-string.h:59:33: warning: '__builtin_memset' offset [57, 4294967294] is out of the bounds [0, 56] of object 'buf' with type 'union ucmd_buffer' [-Warray-bounds=]
   59 | #define __underlying_memset     __builtin_memset
      |                                 ^
../include/linux/fortify-string.h:453:9: note: in expansion of macro '__underlying_memset'
  453 |         __underlying_memset(p, c, __fortify_size); \
      |         ^~~~~~~~~~~~~~~~~~~
../include/linux/fortify-string.h:461:25: note: in expansion of macro '__fortify_memset_chk'
  461 | #define memset(p, c, s) __fortify_memset_chk(p, c, s, \
      |                         ^~~~~~~~~~~~~~~~~~~~
../include/linux/uaccess.h:334:17: note: in expansion of macro 'memset'
  334 |                 memset(dst + size, 0, rest);
      |                 ^~~~~~
../drivers/iommu/iommufd/main.c: In function 'iommufd_fops_ioctl':
../drivers/iommu/iommufd/main.c:311:27: note: 'buf' declared here
  311 |         union ucmd_buffer buf;
      |                           ^~~

Cc: Christian Brauner <brauner@kernel.org>
Cc: Rasmus Villemoes <linux@rasmusvillemoes.dk>
Cc: Arnd Bergmann <arnd@arndb.de>
Cc: Dinh Nguyen <dinguyen@kernel.org>
Cc: Catalin Marinas <catalin.marinas@arm.com>
Cc: Andrew Morton <akpm@linux-foundation.org>
Cc: Geert Uytterhoeven <geert@linux-m68k.org>
Cc: Alexander Potapenko <glider@google.com>
Acked-by: Aleksa Sarai <cyphar@cyphar.com>
Signed-off-by: Kees Cook <keescook@chromium.org>
Link: https://lore.kernel.org/lkml/20230203193523.never.667-kees@kernel.org/
Signed-off-by: Sasha Levin <sashal@kernel.org>
2023-03-11 16:39:51 +01:00
..
acpi ACPI: APEI: Fix integer overflow in ghes_estatus_pool_init() 2022-11-10 18:14:22 +01:00
asm-generic mm/khugepaged: fix GUP-fast interaction by sending IPI 2022-12-14 11:31:55 +01:00
clocksource
crypto
drm drm/mipi-dsi: Fix byte order of 16-bit DCS set/get brightness 2023-03-11 16:39:33 +01:00
dt-bindings dt-bindings: clocks: imx8mp: Add ID for usb suspend clock 2023-01-18 11:44:56 +01:00
keys
kunit
kvm
linux uaccess: Add minimum bounds check on kernel buffer size 2023-03-11 16:39:51 +01:00
math-emu
media media: dvbdev: fix build warning due to comments 2023-01-14 10:16:24 +01:00
memory
misc
net net: add sock_init_data_uid() 2023-03-11 16:39:26 +01:00
pcmcia
ras
rdma
scsi scsi: iscsi: Fix multiple iSCSI session unbind events sent to userspace 2023-02-01 08:23:16 +01:00
soc
sound ASoC: soc-dapm.h: fixup warning struct snd_pcm_substream not declared 2023-03-11 16:39:39 +01:00
target
trace tracing: Use alignof__(struct {type b;}) instead of offsetof() 2023-01-24 07:20:01 +01:00
uapi uapi: add missing ip/ipv6 header dependencies for linux/stddef.h 2023-02-15 17:22:24 +01:00
vdso
video
xen