Re: [PATCH v3 2/3] overflow: Introduce add_wrap(), sub_wrap(), and mul_wrap()

2024-02-05 Thread Kees Cook
On February 5, 2024 11:17:12 PM GMT, Eric Biggers wrote: >On Mon, Feb 05, 2024 at 02:44:14PM -0800, Kees Cook wrote: >> On Mon, Feb 05, 2024 at 12:21:45PM -0800, Eric Biggers wrote: >> > On Mon, Feb 05, 2024 at 01:12:30AM -0800, Kees Cook wrote: >> > > Subject: Re: [PATCH v3 2/3] overflow:

Re: [PATCH v3 2/3] overflow: Introduce add_wrap(), sub_wrap(), and mul_wrap()

2024-02-05 Thread Eric Biggers
On Mon, Feb 05, 2024 at 02:44:14PM -0800, Kees Cook wrote: > On Mon, Feb 05, 2024 at 12:21:45PM -0800, Eric Biggers wrote: > > On Mon, Feb 05, 2024 at 01:12:30AM -0800, Kees Cook wrote: > > > Subject: Re: [PATCH v3 2/3] overflow: Introduce add_wrap(), sub_wrap(), > > > and mul_wrap() > > > >

Re: [PATCH v3 2/3] overflow: Introduce add_wrap(), sub_wrap(), and mul_wrap()

2024-02-05 Thread Kees Cook
On Mon, Feb 05, 2024 at 12:21:45PM -0800, Eric Biggers wrote: > On Mon, Feb 05, 2024 at 01:12:30AM -0800, Kees Cook wrote: > > Subject: Re: [PATCH v3 2/3] overflow: Introduce add_wrap(), sub_wrap(), and > > mul_wrap() > > Maybe these should be called wrapping_add, wrapping_sub, and wrapping_mul?

Re: [PATCH v3 2/3] overflow: Introduce add_wrap(), sub_wrap(), and mul_wrap()

2024-02-05 Thread Eric Biggers
On Mon, Feb 05, 2024 at 01:12:30AM -0800, Kees Cook wrote: > Subject: Re: [PATCH v3 2/3] overflow: Introduce add_wrap(), sub_wrap(), and > mul_wrap() Maybe these should be called wrapping_add, wrapping_sub, and wrapping_mul? Those names are more grammatically correct, and Rust chose those names

Re: [PATCH v3 1/3] overflow: Adjust check_*_overflow() kern-doc to reflect results

2024-02-05 Thread Gustavo A. R. Silva
On 2/5/24 03:12, Kees Cook wrote: 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

Re: [PATCH v3 2/3] overflow: Introduce add_wrap(), sub_wrap(), and mul_wrap()

2024-02-05 Thread Gustavo A. R. Silva
On 2/5/24 07:31, Marco Elver wrote: On Mon, 5 Feb 2024 at 10:12, Kees Cook wrote: 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

Re: [PATCH v2 3/4] string: Allow 2-argument strscpy_pad()

2024-02-05 Thread Andy Shevchenko
On Mon, Feb 05, 2024 at 01:48:51PM +0100, Geert Uytterhoeven wrote: > On Mon, Feb 5, 2024 at 1:36 PM Kees Cook wrote: ... > > +#define __strscpy_pad1(dst, src, size) sized_strscpy_pad(dst, src, size) > > (dst) etc. Makes a little sense here. Are you expecting, e.g., dst to be 'a, b' (w/o

Re: [PATCH v2 4/4] um: Convert strscpy() usage to 2-argument style

2024-02-05 Thread Andy Shevchenko
On Mon, Feb 05, 2024 at 01:50:14PM +0100, Geert Uytterhoeven wrote: > On Mon, Feb 5, 2024 at 1:36 PM Kees Cook wrote: ... > > +#define strscpy(dst, src) sized_strscpy(dst, src, sizeof(dst)) > > (dst), (src) No need. -- With Best Regards, Andy Shevchenko

Re: [PATCH v3 2/3] overflow: Introduce add_wrap(), sub_wrap(), and mul_wrap()

2024-02-05 Thread Marco Elver
On Mon, 5 Feb 2024 at 10:12, Kees Cook wrote: > > 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

Re: [PATCH v3] ubsan: Reintroduce signed overflow sanitizer

2024-02-05 Thread Marco Elver
On Mon, 5 Feb 2024 at 13:59, Kees Cook wrote: > > On Mon, Feb 05, 2024 at 01:54:24PM +0100, Andrey Ryabinin wrote: > > > > > > On 2/5/24 10:37, Kees Cook wrote: > > > > > --- > > > include/linux/compiler_types.h | 9 - > > > lib/Kconfig.ubsan | 14 +++ > > >

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

2024-02-05 Thread Geert Uytterhoeven
Hi Kees, On Mon, Feb 5, 2024 at 2:01 PM Kees Cook wrote: > On Mon, Feb 05, 2024 at 01:47:08PM +0100, Geert Uytterhoeven wrote: > > > +/* > > > + * The 2 argument style can only be used when dst is an array with a > > > + * known size. > > > + */ > > > +#define __strscpy0(dst, src, ...) \ >

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

2024-02-05 Thread Kees Cook
On Mon, Feb 05, 2024 at 01:47:08PM +0100, Geert Uytterhoeven wrote: > > +/* > > + * The 2 argument style can only be used when dst is an array with a > > + * known size. > > + */ > > +#define __strscpy0(dst, src, ...) \ > > + sized_strscpy(dst, src, sizeof(dst) + __must_be_array(dst)) >

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

2024-02-05 Thread Andy Shevchenko
On Mon, Feb 05, 2024 at 01:47:08PM +0100, Geert Uytterhoeven wrote: > On Mon, Feb 5, 2024 at 1:37 PM Kees Cook wrote: ... > > +#define __strscpy1(dst, src, size) sized_strscpy(dst, src, size) > > (dst), (src), (size) etc. No need. ... > > +#define strscpy(dst, src, ...) \ > > +

Re: [PATCH v3] ubsan: Reintroduce signed overflow sanitizer

2024-02-05 Thread Kees Cook
On Mon, Feb 05, 2024 at 01:54:24PM +0100, Andrey Ryabinin wrote: > > > On 2/5/24 10:37, Kees Cook wrote: > > > --- > > include/linux/compiler_types.h | 9 - > > lib/Kconfig.ubsan | 14 +++ > > lib/test_ubsan.c | 37 ++ > > lib/ubsan.c

Re: [PATCH] MAINTAINERS: Add UBSAN section

2024-02-05 Thread Kees Cook
On Mon, Feb 05, 2024 at 01:54:08PM +0100, Andrey Ryabinin wrote: > > > On 2/2/24 10:55, Kees Cook wrote: > > On Tue, Jan 30, 2024 at 03:46:38PM -0800, Kees Cook wrote: > >> The kernel hardening efforts have continued to depend more and more > >> heavily on UBSAN, so make an actual MAINTAINERS

Re: [PATCH v3] ubsan: Reintroduce signed overflow sanitizer

2024-02-05 Thread Andrey Ryabinin
On 2/5/24 10:37, Kees Cook wrote: > --- > include/linux/compiler_types.h | 9 - > lib/Kconfig.ubsan | 14 +++ > lib/test_ubsan.c | 37 ++ > lib/ubsan.c| 68 ++ > lib/ubsan.h

Re: [PATCH] MAINTAINERS: Add UBSAN section

2024-02-05 Thread Andrey Ryabinin
On 2/2/24 10:55, Kees Cook wrote: > On Tue, Jan 30, 2024 at 03:46:38PM -0800, 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 > > I don't see Andrey on lkml in

Re: [PATCH v3] ubsan: Reintroduce signed overflow sanitizer

2024-02-05 Thread Kees Cook
On Mon, Feb 05, 2024 at 12:29:21PM +0100, Marco Elver wrote: > On Mon, 5 Feb 2024 at 10:37, Kees Cook wrote: > > > > In order to mitigate unexpected signed wrap-around[1], bring back the > > signed integer overflow sanitizer. It was removed in commit 6aaa31aeb9cf > > ("ubsan: remove overflow

Re: [PATCH v2 4/4] um: Convert strscpy() usage to 2-argument style

2024-02-05 Thread Geert Uytterhoeven
Hi Kees, On Mon, Feb 5, 2024 at 1:36 PM Kees Cook wrote: > The ARCH=um build has its own idea about strscpy()'s definition. Adjust > the callers to remove the redundant sizeof() arguments ahead of treewide > changes, since it needs a manual adjustment for the newly named > sized_strscpy()

Re: [PATCH v2 3/4] string: Allow 2-argument strscpy_pad()

2024-02-05 Thread Geert Uytterhoeven
Hi Kees, On Mon, Feb 5, 2024 at 1:36 PM Kees Cook wrote: > Similar to strscpy(), update strscpy_pad()'s 3rd argument to be > optional when the destination is a compile-time known size array. > > Cc: Andy Shevchenko > Cc: linux-hardening@vger.kernel.org > Signed-off-by: Kees Cook Thanks for

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

2024-02-05 Thread Geert Uytterhoeven
Hi Kees, On Mon, Feb 5, 2024 at 1:37 PM 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

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

2024-02-05 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

[PATCH v2 1/4] string: Redefine strscpy_pad() as a macro

2024-02-05 Thread Kees Cook
In preparation for making strscpy_pad()'s 3rd argument optional, redefine it as a macro. This also has the benefit of allowing greater FORITFY introspection, as it couldn't see into the strscpy() nor the memset() within strscpy_pad(). Cc: Andy Shevchenko Cc: Andrew Morton Cc:

[PATCH v2 3/4] string: Allow 2-argument strscpy_pad()

2024-02-05 Thread Kees Cook
Similar to strscpy(), update strscpy_pad()'s 3rd argument to be optional when the destination is a compile-time known size array. Cc: Andy Shevchenko Cc: linux-hardening@vger.kernel.org Signed-off-by: Kees Cook --- include/linux/string.h | 29 ++--- 1 file changed, 18

[PATCH v2 4/4] um: Convert strscpy() usage to 2-argument style

2024-02-05 Thread Kees Cook
The ARCH=um build has its own idea about strscpy()'s definition. Adjust the callers to remove the redundant sizeof() arguments ahead of treewide changes, since it needs a manual adjustment for the newly named sized_strscpy() export. Cc: Richard Weinberger Cc: linux...@lists.infradead.org

[PATCH v2 0/4] string: Allow 2-argument strscpy()

2024-02-05 Thread Kees Cook
Hi, v2: - add strscpy_pad() coverage - fix up ARCH=um to handle the renaming - use __must_be_array() to validate sizeof() usage v1: https://lore.kernel.org/all/20240131055340.work.279-k...@kernel.org/ Make it possible for strscpy() and strscpy_pad() to use 2 arguments, making "sizeof(dst)" be

Re: [PATCH v3] ubsan: Reintroduce signed overflow sanitizer

2024-02-05 Thread Marco Elver
On Mon, 5 Feb 2024 at 10:37, Kees Cook wrote: > > In order to mitigate unexpected signed wrap-around[1], bring back the > signed integer overflow sanitizer. It was removed in commit 6aaa31aeb9cf > ("ubsan: remove overflow checks") because it was effectively a no-op > when combined with

Re: [PATCH v2] ubsan: Silence W=1 warnings in self-test

2024-02-05 Thread Marco Elver
On Mon, 5 Feb 2024 at 10:03, Kees Cook wrote: > > Silence a handful of W=1 warnings in the UBSan selftest, which set > variables without using them. For example: > >lib/test_ubsan.c:101:6: warning: variable 'val1' set but not used > [-Wunused-but-set-variable] > 101 | int val1 =

[PATCH v3] ubsan: Reintroduce signed overflow sanitizer

2024-02-05 Thread Kees Cook
In order to mitigate unexpected signed wrap-around[1], bring back the signed integer overflow sanitizer. It was removed in commit 6aaa31aeb9cf ("ubsan: remove overflow checks") because it was effectively a no-op when combined with -fno-strict-overflow (which correctly changes signed overflow from

[PATCH v3 3/3] overflow: Introduce inc_wrap() and dec_wrap()

2024-02-05 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

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

2024-02-05 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

[PATCH v3 2/3] overflow: Introduce add_wrap(), sub_wrap(), and mul_wrap()

2024-02-05 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:

[PATCH v3 0/3] overflow: Introduce wrapping helpers

2024-02-05 Thread Kees Cook
Hi, v3: - reduce patches to just docs and new helpers; we don't need pointer fixes yet. v2: https://lore.kernel.org/all/20240130220218.it.154-k...@kernel.org/ v1: https://lore.kernel.org/lkml/20240129182845.work.694-k...@kernel.org/ In preparation for gaining instrumentation for signed[1],

[PATCH v2] ubsan: Silence W=1 warnings in self-test

2024-02-05 Thread Kees Cook
Silence a handful of W=1 warnings in the UBSan selftest, which set variables without using them. For example: lib/test_ubsan.c:101:6: warning: variable 'val1' set but not used [-Wunused-but-set-variable] 101 | int val1 = 10; | ^ Reported-by: kernel test