Re: [PATCH] mm/slub: Avoid recursive loop with kmemleak

2024-04-25 Thread Suren Baghdasaryan
On Thu, Apr 25, 2024 at 5:19 PM Kent Overstreet wrote: > > On Thu, Apr 25, 2024 at 04:49:17PM -0700, Andrew Morton wrote: > > On Thu, 25 Apr 2024 14:30:55 -0700 Suren Baghdasaryan > > wrote: > > > > > > > --- a/mm/kmemleak.c > > > > > +++ b/mm/kmemleak.c > > > > > @@ -463,7 +463,7 @@ static

Re: [PATCH] alloc_tag: Tighten file permissions on /proc/allocinfo

2024-04-25 Thread Kent Overstreet
On Fri, Apr 26, 2024 at 04:25:40AM +0100, Matthew Wilcox wrote: > On Thu, Apr 25, 2024 at 08:58:34PM -0400, Kent Overstreet wrote: > > On Thu, Apr 25, 2024 at 05:43:33PM -0700, Kees Cook wrote: > > > All this said, I'm still not excited about any of these files living > > > in /proc at all -- we

Re: [PATCH] alloc_tag: Tighten file permissions on /proc/allocinfo

2024-04-25 Thread Matthew Wilcox
On Thu, Apr 25, 2024 at 08:58:34PM -0400, Kent Overstreet wrote: > On Thu, Apr 25, 2024 at 05:43:33PM -0700, Kees Cook wrote: > > All this said, I'm still not excited about any of these files living > > in /proc at all -- we were supposed to use /sys for this kind of thing, > > but its interface

Re: [PATCH] alloc_tag: Tighten file permissions on /proc/allocinfo

2024-04-25 Thread Kent Overstreet
On Thu, Apr 25, 2024 at 05:43:33PM -0700, Kees Cook wrote: > On Thu, Apr 25, 2024 at 08:27:05PM -0400, Kent Overstreet wrote: > > On Thu, Apr 25, 2024 at 04:47:18PM -0700, Andrew Morton wrote: > > > On Thu, 25 Apr 2024 15:42:30 -0700 Kees Cook > > > wrote: > > > > > > > > The concern about

Re: [PATCH] alloc_tag: Tighten file permissions on /proc/allocinfo

2024-04-25 Thread Kees Cook
On Thu, Apr 25, 2024 at 08:27:05PM -0400, Kent Overstreet wrote: > On Thu, Apr 25, 2024 at 04:47:18PM -0700, Andrew Morton wrote: > > On Thu, 25 Apr 2024 15:42:30 -0700 Kees Cook wrote: > > > > > > The concern about leaking image layout could be addressed by sorting the > > > > output before

Re: [PATCH] alloc_tag: Tighten file permissions on /proc/allocinfo

2024-04-25 Thread Kees Cook
On Thu, Apr 25, 2024 at 04:47:18PM -0700, Andrew Morton wrote: > On Thu, 25 Apr 2024 15:42:30 -0700 Kees Cook wrote: > > > > The concern about leaking image layout could be addressed by sorting the > > > output before returning to userspace. > > > > It's trivial to change permissions from the

Re: [PATCH] alloc_tag: Tighten file permissions on /proc/allocinfo

2024-04-25 Thread Kent Overstreet
On Thu, Apr 25, 2024 at 04:47:18PM -0700, Andrew Morton wrote: > On Thu, 25 Apr 2024 15:42:30 -0700 Kees Cook wrote: > > > > The concern about leaking image layout could be addressed by sorting the > > > output before returning to userspace. > > > > It's trivial to change permissions from the

Re: [PATCH] mm/slub: Avoid recursive loop with kmemleak

2024-04-25 Thread Kent Overstreet
On Thu, Apr 25, 2024 at 04:49:17PM -0700, Andrew Morton wrote: > On Thu, 25 Apr 2024 14:30:55 -0700 Suren Baghdasaryan > wrote: > > > > > --- a/mm/kmemleak.c > > > > +++ b/mm/kmemleak.c > > > > @@ -463,7 +463,7 @@ static struct kmemleak_object *mem_pool_alloc(gfp_t > > > > gfp) > > > > > > > >

Re: [PATCH] mm/slub: Avoid recursive loop with kmemleak

2024-04-25 Thread Andrew Morton
On Thu, 25 Apr 2024 14:30:55 -0700 Suren Baghdasaryan wrote: > > > --- a/mm/kmemleak.c > > > +++ b/mm/kmemleak.c > > > @@ -463,7 +463,7 @@ static struct kmemleak_object *mem_pool_alloc(gfp_t > > > gfp) > > > > > > /* try the slab allocator first */ > > > if (object_cache) { > > > -

Re: [PATCH] alloc_tag: Tighten file permissions on /proc/allocinfo

2024-04-25 Thread Andrew Morton
On Thu, 25 Apr 2024 15:42:30 -0700 Kees Cook wrote: > > The concern about leaking image layout could be addressed by sorting the > > output before returning to userspace. > > It's trivial to change permissions from the default 0400 at boot time. > It can even have groups and ownership changed,

[PATCH] kunit/fortify: Fix mismatched kvalloc()/vfree() usage

2024-04-25 Thread Kees Cook
The kv*() family of tests were accidentally freeing with vfree() instead of kvfree(). Use kvfree() instead. Fixes: 9124a2640148 ("kunit/fortify: Validate __alloc_size attribute results") Signed-off-by: Kees Cook --- Cc: linux-hardening@vger.kernel.org --- lib/fortify_kunit.c | 16

Re: [PATCH] alloc_tag: Tighten file permissions on /proc/allocinfo

2024-04-25 Thread Kent Overstreet
On Thu, Apr 25, 2024 at 03:42:30PM -0700, Kees Cook wrote: > On Thu, Apr 25, 2024 at 05:04:47PM -0400, Kent Overstreet wrote: > > On Thu, Apr 25, 2024 at 09:51:56PM +0100, Matthew Wilcox wrote: > > > On Thu, Apr 25, 2024 at 04:45:51PM -0400, Kent Overstreet wrote: > > > > On Thu, Apr 25, 2024 at

Re: [PATCH] alloc_tag: Tighten file permissions on /proc/allocinfo

2024-04-25 Thread Kees Cook
On Thu, Apr 25, 2024 at 05:04:47PM -0400, Kent Overstreet wrote: > On Thu, Apr 25, 2024 at 09:51:56PM +0100, Matthew Wilcox wrote: > > On Thu, Apr 25, 2024 at 04:45:51PM -0400, Kent Overstreet wrote: > > > On Thu, Apr 25, 2024 at 01:08:50PM -0700, Kees Cook wrote: > > > > The /proc/allocinfo file

Re: [PATCH] alloc_tag: Tighten file permissions on /proc/allocinfo

2024-04-25 Thread Kent Overstreet
On Thu, Apr 25, 2024 at 02:38:42PM -0700, Andrew Morton wrote: > On Thu, 25 Apr 2024 14:21:39 -0700 Suren Baghdasaryan > wrote: > > > > > > The side effect of locking down more and more reporting interfaces is > > > > > that programs that consume those interfaces now have to run as root. > > >

Re: [PATCH] alloc_tag: Tighten file permissions on /proc/allocinfo

2024-04-25 Thread Andrew Morton
On Thu, 25 Apr 2024 14:21:39 -0700 Suren Baghdasaryan wrote: > > > > The side effect of locking down more and more reporting interfaces is > > > > that programs that consume those interfaces now have to run as root. > > > > > > sudo cat /proc/allocinfo | analyse-that-fie > > > > Even that is

Re: [PATCH] mm/slub: Avoid recursive loop with kmemleak

2024-04-25 Thread Suren Baghdasaryan
On Thu, Apr 25, 2024 at 2:09 PM Kent Overstreet wrote: > > On Thu, Apr 25, 2024 at 01:55:23PM -0700, Kees Cook wrote: > > The system will immediate fill up stack and crash when both > > CONFIG_DEBUG_KMEMLEAK and CONFIG_MEM_ALLOC_PROFILING are enabled. > > Avoid allocation tagging of kmemleak

Re: [PATCH 2/2] clk: bcm: rpi: Assign ->num before accessing ->hws

2024-04-25 Thread Florian Fainelli
On 4/25/24 09:55, Nathan Chancellor wrote: Commit f316cdff8d67 ("clk: Annotate struct clk_hw_onecell_data with __counted_by") annotated the hws member of 'struct clk_hw_onecell_data' with __counted_by, which informs the bounds sanitizer about the number of elements in hws, so that it can warn

Re: [PATCH 1/2] clk: bcm: dvp: Assign ->num before accessing ->hws

2024-04-25 Thread Florian Fainelli
On 4/25/24 09:55, Nathan Chancellor wrote: Commit f316cdff8d67 ("clk: Annotate struct clk_hw_onecell_data with __counted_by") annotated the hws member of 'struct clk_hw_onecell_data' with __counted_by, which informs the bounds sanitizer about the number of elements in hws, so that it can warn

Re: [PATCH] alloc_tag: Tighten file permissions on /proc/allocinfo

2024-04-25 Thread Kent Overstreet
On Thu, Apr 25, 2024 at 02:21:39PM -0700, Suren Baghdasaryan wrote: > On Thu, Apr 25, 2024 at 2:04 PM Kent Overstreet > wrote: > > > > On Thu, Apr 25, 2024 at 09:51:56PM +0100, Matthew Wilcox wrote: > > > On Thu, Apr 25, 2024 at 04:45:51PM -0400, Kent Overstreet wrote: > > > > On Thu, Apr 25,

Re: [PATCH] alloc_tag: Tighten file permissions on /proc/allocinfo

2024-04-25 Thread Suren Baghdasaryan
On Thu, Apr 25, 2024 at 2:04 PM Kent Overstreet wrote: > > On Thu, Apr 25, 2024 at 09:51:56PM +0100, Matthew Wilcox wrote: > > On Thu, Apr 25, 2024 at 04:45:51PM -0400, Kent Overstreet wrote: > > > On Thu, Apr 25, 2024 at 01:08:50PM -0700, Kees Cook wrote: > > > > The /proc/allocinfo file exposes

Re: [PATCH] mm/slub: Avoid recursive loop with kmemleak

2024-04-25 Thread Kent Overstreet
On Thu, Apr 25, 2024 at 01:55:23PM -0700, Kees Cook wrote: > The system will immediate fill up stack and crash when both > CONFIG_DEBUG_KMEMLEAK and CONFIG_MEM_ALLOC_PROFILING are enabled. > Avoid allocation tagging of kmemleak caches, otherwise recursive > allocation tracking occurs. > > Fixes:

Re: [PATCH] alloc_tag: Tighten file permissions on /proc/allocinfo

2024-04-25 Thread Kent Overstreet
On Thu, Apr 25, 2024 at 09:51:56PM +0100, Matthew Wilcox wrote: > On Thu, Apr 25, 2024 at 04:45:51PM -0400, Kent Overstreet wrote: > > On Thu, Apr 25, 2024 at 01:08:50PM -0700, Kees Cook wrote: > > > The /proc/allocinfo file exposes a tremendous about of information about > > > kernel build

Re: [PATCH] alloc_tag: Tighten file permissions on /proc/allocinfo

2024-04-25 Thread Kees Cook
On Thu, Apr 25, 2024 at 04:45:51PM -0400, Kent Overstreet wrote: > On Thu, Apr 25, 2024 at 01:08:50PM -0700, Kees Cook wrote: > > The /proc/allocinfo file exposes a tremendous about of information about > > kernel build details, memory allocations (obviously), and potentially > > even image layout

[PATCH] mm/slub: Avoid recursive loop with kmemleak

2024-04-25 Thread Kees Cook
The system will immediate fill up stack and crash when both CONFIG_DEBUG_KMEMLEAK and CONFIG_MEM_ALLOC_PROFILING are enabled. Avoid allocation tagging of kmemleak caches, otherwise recursive allocation tracking occurs. Fixes: 279bb991b4d9 ("mm/slab: add allocation accounting into slab allocation

Re: [PATCH] alloc_tag: Tighten file permissions on /proc/allocinfo

2024-04-25 Thread Matthew Wilcox
On Thu, Apr 25, 2024 at 04:45:51PM -0400, Kent Overstreet wrote: > On Thu, Apr 25, 2024 at 01:08:50PM -0700, Kees Cook wrote: > > The /proc/allocinfo file exposes a tremendous about of information about > > kernel build details, memory allocations (obviously), and potentially > > even image layout

Re: [PATCH] alloc_tag: Tighten file permissions on /proc/allocinfo

2024-04-25 Thread Kent Overstreet
On Thu, Apr 25, 2024 at 01:08:50PM -0700, Kees Cook wrote: > The /proc/allocinfo file exposes a tremendous about of information about > kernel build details, memory allocations (obviously), and potentially > even image layout (due to ordering). As this is intended to be consumed > by system owners

[PATCH] alloc_tag: Tighten file permissions on /proc/allocinfo

2024-04-25 Thread Kees Cook
The /proc/allocinfo file exposes a tremendous about of information about kernel build details, memory allocations (obviously), and potentially even image layout (due to ordering). As this is intended to be consumed by system owners (like /proc/slabinfo), use the same file permissions as there:

Re: [PATCH] wifi: nl80211: Avoid address calculations via out of bounds array indexing

2024-04-25 Thread Nathan Chancellor
On Wed, Apr 24, 2024 at 03:01:01PM -0700, Kees Cook wrote: > Before request->channels[] can be used, request->n_channels must be set. > Additionally, address calculations for memory after the "channels" array > need to be calculated from the allocation base ("request") rather than > via the first

Re: [PATCH 1/4] locking/atomic/x86: Silence intentional wrapping addition

2024-04-25 Thread Kees Cook
On Thu, Apr 25, 2024 at 11:17:52AM +0200, Peter Zijlstra wrote: > On Wed, Apr 24, 2024 at 04:20:20PM -0700, Kees Cook wrote: > > > > This is arse-about-face. Signed stuff wraps per -fno-strict-overflow. > > > We've been writing code for years under that assumption. > > > > Right, which is why

Re: [PATCH 1/4] locking/atomic/x86: Silence intentional wrapping addition

2024-04-25 Thread Kees Cook
On Thu, Apr 25, 2024 at 11:15:17AM +0100, Mark Rutland wrote: > To be clear, I dislike the function annotation because then it applies to > *everything* within the function, which is overly broad and the intent becomes > unclear. That makes it painful to refactor the code (since e.g. if we want to

Re: [PATCH 2/2] clk: bcm: rpi: Assign ->num before accessing ->hws

2024-04-25 Thread Kees Cook
On Thu, Apr 25, 2024 at 09:55:52AM -0700, Nathan Chancellor wrote: > Commit f316cdff8d67 ("clk: Annotate struct clk_hw_onecell_data with > __counted_by") annotated the hws member of 'struct clk_hw_onecell_data' > with __counted_by, which informs the bounds sanitizer about the number > of elements

Re: [PATCH 1/2] clk: bcm: dvp: Assign ->num before accessing ->hws

2024-04-25 Thread Kees Cook
On Thu, Apr 25, 2024 at 09:55:51AM -0700, Nathan Chancellor wrote: > Commit f316cdff8d67 ("clk: Annotate struct clk_hw_onecell_data with > __counted_by") annotated the hws member of 'struct clk_hw_onecell_data' > with __counted_by, which informs the bounds sanitizer about the number > of elements

[PATCH 2/2] clk: bcm: rpi: Assign ->num before accessing ->hws

2024-04-25 Thread Nathan Chancellor
Commit f316cdff8d67 ("clk: Annotate struct clk_hw_onecell_data with __counted_by") annotated the hws member of 'struct clk_hw_onecell_data' with __counted_by, which informs the bounds sanitizer about the number of elements in hws, so that it can warn when hws is accessed out of bounds. As noted in

[PATCH 1/2] clk: bcm: dvp: Assign ->num before accessing ->hws

2024-04-25 Thread Nathan Chancellor
Commit f316cdff8d67 ("clk: Annotate struct clk_hw_onecell_data with __counted_by") annotated the hws member of 'struct clk_hw_onecell_data' with __counted_by, which informs the bounds sanitizer about the number of elements in hws, so that it can warn when hws is accessed out of bounds. As noted in

[PATCH 0/2] clk: bcm: Move a couple of __counted_by initializations

2024-04-25 Thread Nathan Chancellor
Hi all, This series addresses two UBSAN warnings I see on my Raspberry Pi 4 with recent releases of clang that support __counted_by by moving the initializations of the element count member before any accesses of the flexible array member. I marked these for stable because more distributions are

Re: [PATCH 1/4] locking/atomic/x86: Silence intentional wrapping addition

2024-04-25 Thread Mark Rutland
On Thu, Apr 25, 2024 at 11:28:12AM +0200, Peter Zijlstra wrote: > On Wed, Apr 24, 2024 at 04:30:50PM -0700, Kees Cook wrote: > > > > That is, anything that actively warns about signed overflow when build > > > with -fno-strict-overflow is a bug. If you want this warning you have to > > >

Re: [PATCH 1/4] locking/atomic/x86: Silence intentional wrapping addition

2024-04-25 Thread Mark Rutland
On Wed, Apr 24, 2024 at 03:45:07PM -0700, Kees Cook wrote: > On Thu, Apr 25, 2024 at 12:41:41AM +0200, Peter Zijlstra wrote: > > On Wed, Apr 24, 2024 at 12:17:34PM -0700, Kees Cook wrote: > > > > > @@ -82,7 +83,7 @@ static __always_inline bool > > > arch_atomic_add_negative(int i, atomic_t *v) >

Re: [PATCH 1/4] locking/atomic/x86: Silence intentional wrapping addition

2024-04-25 Thread Peter Zijlstra
On Wed, Apr 24, 2024 at 04:30:50PM -0700, Kees Cook wrote: > > That is, anything that actively warns about signed overflow when build > > with -fno-strict-overflow is a bug. If you want this warning you have to > > explicitly mark things. > > This is confusing UB with "overflow detection". We're

Re: [PATCH 1/4] locking/atomic/x86: Silence intentional wrapping addition

2024-04-25 Thread Peter Zijlstra
On Wed, Apr 24, 2024 at 04:20:20PM -0700, Kees Cook wrote: > > This is arse-about-face. Signed stuff wraps per -fno-strict-overflow. > > We've been writing code for years under that assumption. > > Right, which is why this is going to take time to roll out. :) What we > were really doing with