Go to file
Kees Cook f96afdb3a3 uaccess: Add minimum bounds check on kernel buffer size
BugLink: https://bugs.launchpad.net/bugs/2017706

[ Upstream commit 04ffde1319a715bd0550ded3580d4ea3bc003776 ]

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>
Signed-off-by: Luke Nowakowski-Krijger <luke.nowakowskikrijger@canonical.com>
Signed-off-by: Stefan Bader <stefan.bader@canonical.com>
2023-05-12 17:15:07 +02:00
Documentation docs: Fix path paste-o for /sys/kernel/warn_count 2023-03-21 10:09:02 +01:00
LICENSES
arch m68k: Check syscall_trace_enter() return code 2023-05-12 17:15:07 +02:00
block blk-iocost: fix divide by 0 error in calc_lcoefs() 2023-05-12 17:15:06 +02:00
certs
crypto crypto: rsa-pkcs1pad - Use akcipher_request_complete 2023-05-12 17:15:01 +02:00
debian UBUNTU: [Packaging] update helper scripts 2023-05-12 17:13:10 +02:00
debian.master UBUNTU: [Config] update annotations for CONFIG_DRM_MXSFB 2023-05-12 17:15:02 +02:00
drivers net/mlx5: fw_tracer: Fix debug print 2023-05-12 17:15:07 +02:00
fs coda: Avoid partial allocation of sig_inputArgs 2023-05-12 17:15:07 +02:00
include uaccess: Add minimum bounds check on kernel buffer size 2023-05-12 17:15:07 +02:00
init
ipc
kernel timers: Prevent union confusion from unexpected restart_syscall() 2023-05-12 17:15:06 +02:00
lib lib/mpi: Fix buffer overrun when SG is too long 2023-05-12 17:15:00 +02:00
mm Revert "mm: Always release pages to the buddy allocator in memblock_free_late()." 2023-04-18 17:21:04 +02:00
net inet: fix fast path in __inet_hash_connect() 2023-05-12 17:15:07 +02:00
samples
scripts ftrace/scripts: Update the instructions for ftrace-bisect.sh 2023-03-21 10:08:59 +01:00
security tomoyo: fix broken dependency on *.conf.default 2023-03-21 10:08:57 +01:00
sound ASoC: soc-compress.c: fixup private_data on snd_soc_new_compress() 2023-05-12 17:15:03 +02:00
tools perf tools: Fix auto-complete on aarch64 2023-05-12 17:15:05 +02:00
ubuntu
usr
virt
.clang-format
.cocciconfig
.get_maintainer.ignore
.gitattributes
.gitignore
.mailmap
COPYING
CREDITS
Kbuild
Kconfig
MAINTAINERS net/phy/mdio-i2c: Move header file to include/linux/mdio 2023-03-21 10:09:00 +01:00
Makefile Linux 5.4.234 2023-05-12 17:14:57 +02:00
README
Ubuntu.md
dropped.txt
snapcraft.yaml
update-dkms-versions
update-version-dkms

README

Linux kernel
============

There are several guides for kernel developers and users. These guides can
be rendered in a number of formats, like HTML and PDF. Please read
Documentation/admin-guide/README.rst first.

In order to build the documentation, use ``make htmldocs`` or
``make pdfdocs``.  The formatted documentation can also be read online at:

    https://www.kernel.org/doc/html/latest/

There are various text files in the Documentation/ subdirectory,
several of them using the Restructured Text markup notation.

Please read the Documentation/process/changes.rst file, as it contains the
requirements for building and running the kernel, and information about
the problems which may result by upgrading your kernel.