Re: [PATCH] MAINTAINERS: Add UBSAN section

2024-01-30 Thread Marco Elver
On Wed, 31 Jan 2024 at 00:46, Kees Cook wrote: > > The kernel hardening efforts have continued to depend more and more > heavily on UBSAN, so make an actual MAINTAINERS entry for it. > > Cc: Andrey Ryabinin > Cc: Marco Elver > Cc: Andrey Konovalov > Signed-off-by: Kees Cook > --- > Hi! I figur

Re: [PATCH] string: Allow 2-argument strscpy()

2024-01-30 Thread Andy Shevchenko
On Wed, Jan 31, 2024 at 7:53 AM Kees Cook wrote: > > Using sizeof(dst) for the "size" argument in strscpy() is the > overwhelmingly common case. Instead of requiring this everywhere, allow a > 2-argument version to be used that will use the sizeof() internally. There > are other functions in the k

Re: [PATCH] LoongArch: vDSO: Disable UBSAN instrumentation

2024-01-30 Thread Huacai Chen
Queued, thanks. Huacai On Wed, Jan 31, 2024 at 7:31 AM Kees Cook wrote: > > The vDSO executes in userspace, so the kernel's UBSAN should not > instrument it. Solves these kind of build errors: > > loongarch64-linux-ld: arch/loongarch/vdso/vgettimeofday.o: in function > `vdso_shift_ns': > li

Re: [PATCH] MAINTAINERS: Add UBSAN section

2024-01-30 Thread Kees Cook
On Wed, Jan 31, 2024 at 02:41:16AM +0100, Andrey Konovalov wrote: > On Wed, Jan 31, 2024 at 12:46 AM Kees Cook wrote: > > > > The kernel hardening efforts have continued to depend more and more > > heavily on UBSAN, so make an actual MAINTAINERS entry for it. > > > > Cc: Andrey Ryabinin > > Cc: M

[PATCH] string: Allow 2-argument strscpy()

2024-01-30 Thread Kees Cook
Using sizeof(dst) for the "size" argument in strscpy() is the overwhelmingly common case. Instead of requiring this everywhere, allow a 2-argument version to be used that will use the sizeof() internally. There are other functions in the kernel with optional arguments[1], so this isn't unprecedente

Re: [PATCH] MAINTAINERS: Add UBSAN section

2024-01-30 Thread Andrey Konovalov
On Wed, Jan 31, 2024 at 12:46 AM Kees Cook wrote: > > The kernel hardening efforts have continued to depend more and more > heavily on UBSAN, so make an actual MAINTAINERS entry for it. > > Cc: Andrey Ryabinin > Cc: Marco Elver > Cc: Andrey Konovalov > Signed-off-by: Kees Cook > --- > Hi! I fi

[PATCH] MAINTAINERS: Add UBSAN section

2024-01-30 Thread Kees Cook
The kernel hardening efforts have continued to depend more and more heavily on UBSAN, so make an actual MAINTAINERS entry for it. Cc: Andrey Ryabinin Cc: Marco Elver Cc: Andrey Konovalov Signed-off-by: Kees Cook --- Hi! I figured since I've been carrying UBSAN changes more and more lately, I w

[PATCH] LoongArch: vDSO: Disable UBSAN instrumentation

2024-01-30 Thread Kees Cook
The vDSO executes in userspace, so the kernel's UBSAN should not instrument it. Solves these kind of build errors: loongarch64-linux-ld: arch/loongarch/vdso/vgettimeofday.o: in function `vdso_shift_ns': lib/vdso/gettimeofday.c:23:(.text+0x3f8): undefined reference to `__ubsan_handle_shift_ou

[PATCH] sh: Fix build with CONFIG_UBSAN=y

2024-01-30 Thread Kees Cook
The early boot stub for sh had UBSan instrumentation present where it is not supported. Disable it for this part of the build. sh4-linux-ld: arch/sh/boot/compressed/misc.o: in function `zlib_inflate_table': misc.c:(.text+0x670): undefined reference to `__ubsan_handle_shift_out_of_bounds' Re

[PATCH v2 1/5] overflow: Adjust check_*_overflow() kern-doc to reflect results

2024-01-30 Thread Kees Cook
The check_*_overflow() helpers will return results with potentially wrapped-around values. These values have always been checked by the selftests, so avoid the confusing language in the kern-doc. The idea of "safe for use" was relative to the expectation of whether or not the caller wants a wrapped

[PATCH v2 5/5] overflow: Introduce inc_wrap() and dec_wrap()

2024-01-30 Thread Kees Cook
This allows replacements of the idioms "var += offset" and "var -= offset" with the inc_wrap() and dec_wrap() helpers respectively. They will avoid wrap-around sanitizer instrumentation. Add to the selftests to validate behavior and lack of side-effects. Cc: Rasmus Villemoes Cc: Mark Rutland Cc

[PATCH v2 4/5] overflow: Introduce add_wrap(), sub_wrap(), and mul_wrap()

2024-01-30 Thread Kees Cook
Provide helpers that will perform wrapping addition, subtraction, or multiplication without tripping the arithmetic wrap-around sanitizers. The first argument is the type under which the wrap-around should happen with. In other words, these two calls will get very different results: mul_wr

[PATCH v2 3/5] overflow: Introduce add_would_overflow()

2024-01-30 Thread Kees Cook
For instances where only the overflow needs to be checked (and the sum isn't used), provide the new helper add_would_overflow(), which is a wrapper for check_add_overflow(). Cc: Rasmus Villemoes Cc: "Gustavo A. R. Silva" Cc: Justin Stitt Cc: linux-hardening@vger.kernel.org Signed-off-by: Kees C

[PATCH v2 0/5] overflow: Introduce wrapping helpers

2024-01-30 Thread Kees Cook
Hi, v2: - Define inc/dec_wrap() in terms of add/sub_wrap() and avoid side-effects (Rasmus) - Fix various typos (Rasmus) - Add selftests for all the new helpers v1: https://lore.kernel.org/lkml/20240129182845.work.694-k...@kernel.org/ In preparation for gaining instrumentation for signed[1], u

[PATCH v2 2/5] overflow: Expand check_add_overflow() for pointer addition

2024-01-30 Thread Kees Cook
The check_add_overflow() helper is mostly a wrapper around __builtin_add_overflow(), but GCC and Clang refuse to operate on pointer arguments that would normally be allowed if the addition were open-coded. For example, we have many places where pointer overflow is tested: struct foo *ptr;

Re: [PATCH 33/82] mm/vmalloc: Refactor intentional wrap-around calculation

2024-01-30 Thread Kees Cook
On Tue, Jan 30, 2024 at 08:54:00PM +0100, Uladzislau Rezki wrote: > On Tue, Jan 30, 2024 at 06:55:57PM +, Lorenzo Stoakes wrote: > > On Mon, Jan 22, 2024 at 04:27:08PM -0800, Kees Cook wrote: > > > In an effort to separate intentional arithmetic wrap-around from > > > unexpected wrap-around, we

Re: [PATCH 1/1] lib/vsprintf: Implement ssprintf() to catch truncated strings

2024-01-30 Thread Kees Cook
On Tue, Jan 30, 2024 at 04:18:42PM +0100, Rasmus Villemoes wrote: > So here scnprint() would have returned 1, leaving size at 1. scnprintf() > has the invariant that, for non-zero size, the return value is strictly > less than that size, so when passed a size of 1, all subsequent calls > return 0 (

Re: [PATCH 33/82] mm/vmalloc: Refactor intentional wrap-around calculation

2024-01-30 Thread Uladzislau Rezki
On Tue, Jan 30, 2024 at 06:55:57PM +, Lorenzo Stoakes wrote: > On Mon, Jan 22, 2024 at 04:27:08PM -0800, Kees Cook wrote: > > In an effort to separate intentional arithmetic wrap-around from > > unexpected wrap-around, we need to refactor places that depend on this > > kind of math. One of the

Re: [PATCH 78/82] mm/vmalloc: Refactor intentional wrap-around test

2024-01-30 Thread Lorenzo Stoakes
On Mon, Jan 22, 2024 at 04:27:53PM -0800, Kees Cook wrote: > In an effort to separate intentional arithmetic wrap-around from > unexpected wrap-around, we need to refactor places that depend on this > kind of math. One of the most common code patterns of this is: > > VAR + value < VAR > > Not

Re: [PATCH 33/82] mm/vmalloc: Refactor intentional wrap-around calculation

2024-01-30 Thread Lorenzo Stoakes
On Mon, Jan 22, 2024 at 04:27:08PM -0800, Kees Cook wrote: > In an effort to separate intentional arithmetic wrap-around from > unexpected wrap-around, we need to refactor places that depend on this > kind of math. One of the most common code patterns of this is: > > VAR + value < VAR > > Not

Re: [PATCH] dmaengine: pl08x: Use kcalloc() instead of kzalloc()

2024-01-30 Thread Gustavo A. R. Silva
On 1/28/24 05:52, Erick Archer wrote: This is an effort to get rid of all multiplications from allocation functions in order to prevent integer overflows [1]. Here the multiplication is obviously safe because the "channels" member can only be 8 or 2. This value is set when the "vendor_data" s

[PATCH v3 1/1] lib/vsprintf: Implement spprintf() to catch truncated strings

2024-01-30 Thread Lee Jones
There is an ongoing effort to replace the use of {v}snprintf() variants with safer alternatives - for a more in depth view, see Jon's write-up on LWN [0] and/or Alex's on the Kernel Self Protection Project [1]. Whist executing the task, it quickly became apparent that the initial thought of simply

Re: [PATCH 1/1] lib/vsprintf: Implement ssprintf() to catch truncated strings

2024-01-30 Thread Lee Jones
On Tue, 30 Jan 2024, Rasmus Villemoes wrote: > On 30/01/2024 16.07, Lee Jones wrote: > > On Mon, 29 Jan 2024, Lee Jones wrote: > > > >> On Mon, 29 Jan 2024, David Laight wrote: > >> > >>> ... > > I'm sure that the safest return for 'truncated' is the buffer length. > > The a series of sta

Re: [PATCH 1/1] lib/vsprintf: Implement ssprintf() to catch truncated strings

2024-01-30 Thread Rasmus Villemoes
On 30/01/2024 16.07, Lee Jones wrote: > On Mon, 29 Jan 2024, Lee Jones wrote: > >> On Mon, 29 Jan 2024, David Laight wrote: >> >>> ... > I'm sure that the safest return for 'truncated' is the buffer length. > The a series of statements like: > buf += xxx(buf, buf_end - buf, .); >

Re: [PATCH 1/1] lib/vsprintf: Implement ssprintf() to catch truncated strings

2024-01-30 Thread Lee Jones
On Mon, 29 Jan 2024, Lee Jones wrote: > On Mon, 29 Jan 2024, David Laight wrote: > > > ... > > > > I'm sure that the safest return for 'truncated' is the buffer length. > > > > The a series of statements like: > > > > buf += xxx(buf, buf_end - buf, .); > > > > can all be called with a

Re: [PATCH v2] bus: mhi: ep: Use kcalloc() instead of kzalloc()

2024-01-30 Thread Alex Elder
On 1/28/24 5:27 AM, Erick Archer wrote: This is an effort to get rid of all multiplications from allocation functions in order to prevent integer overflows [1]. Here the multiplication is obviously safe because the "event_rings" member never can have a value greater than 255 (8 bits). This membe

Re: [PATCH] select: Avoid wrap-around instrumentation in do_sys_poll()

2024-01-30 Thread Jan Kara
On Mon 29-01-24 10:40:15, Kees Cook wrote: > The mix of int, unsigned int, and unsigned long used by struct > poll_list::len, todo, len, and j meant that the signed overflow > sanitizer got worried it needed to instrument several places where > arithmetic happens between these variables. Since all

Re: [PATCH] select: Avoid wrap-around instrumentation in do_sys_poll()

2024-01-30 Thread Christian Brauner
On Mon, 29 Jan 2024 10:40:15 -0800, Kees Cook wrote: > The mix of int, unsigned int, and unsigned long used by struct > poll_list::len, todo, len, and j meant that the signed overflow > sanitizer got worried it needed to instrument several places where > arithmetic happens between these variables.

Re: [PATCH] iov_iter: Avoid wrap-around instrumentation in copy_compat_iovec_from_user()

2024-01-30 Thread Christian Brauner
On Mon, 29 Jan 2024 10:37:29 -0800, Kees Cook wrote: > The loop counter "i" in copy_compat_iovec_from_user() is an int, but > because the nr_segs argument is unsigned long, the signed overflow > sanitizer got worried "i" could wrap around. Instead of making "i" an > unsigned long (which may enlarge

Re: [PATCH v2] bus: mhi: ep: Use kcalloc() instead of kzalloc()

2024-01-30 Thread Manivannan Sadhasivam
On Sun, Jan 28, 2024 at 12:27:22PM +0100, Erick Archer wrote: > This is an effort to get rid of all multiplications from allocation > functions in order to prevent integer overflows [1]. > > Here the multiplication is obviously safe because the "event_rings" > member never can have a value greater

Re: [PATCH] bus: mhi: ep: Use kcalloc() instead of kzalloc()

2024-01-30 Thread Manivannan Sadhasivam
On Mon, Jan 22, 2024 at 10:15:20AM +0300, Dan Carpenter wrote: > This code does not have an integer overflow, but it might have a > different memory corruption bug. > > On Sat, Jan 20, 2024 at 04:25:18PM +0100, Erick Archer wrote: > > As noted in the "Deprecated Interfaces, Language Features, Attr

Re: Build regressions/improvements in v6.8-rc2

2024-01-30 Thread Sam James
Helge Deller writes: > On 1/29/24 15:58, Guenter Roeck wrote: >> On 1/29/24 03:06, Geert Uytterhoeven wrote: >> [ ... ] >>> parisc-gcc1[23]/parisc-{allmod,def}config >>> >>>    + /kisskb/src/drivers/hwmon/pc87360.c: error: writing 1 byte into a >>> region of size 0 [-Werror=stringop-overflow=]