[<prev] [next>] [<thread-prev] [day] [month] [year] [list]
Message-ID: <aP9gjJJ33Zzo9TyF@hyeyoo>
Date: Mon, 27 Oct 2025 21:07:40 +0900
From: Harry Yoo <harry.yoo@...cle.com>
To: Vlastimil Babka <vbabka@...e.cz>
Cc: David Rientjes <rientjes@...gle.com>,
Alexander Potapenko <glider@...gle.com>,
Roman Gushchin <roman.gushchin@...ux.dev>,
Andrew Morton <akpm@...ux-foundation.org>,
Vincenzo Frascino <vincenzo.frascino@....com>,
Andrey Ryabinin <ryabinin.a.a@...il.com>,
Feng Tang <feng.79.tang@...il.com>, Christoph Lameter <cl@...two.org>,
Dmitry Vyukov <dvyukov@...gle.com>,
Andrey Konovalov <andreyknvl@...il.com>, linux-mm@...ck.org,
Pedro Falcato <pfalcato@...e.de>, linux-kernel@...r.kernel.org,
kasan-dev@...glegroups.com, stable@...r.kernel.org
Subject: Re: [PATCH V2] mm/slab: ensure all metadata in slab object are
word-aligned
On Mon, Oct 27, 2025 at 09:00:28PM +0900, Harry Yoo wrote:
> When the SLAB_STORE_USER debug flag is used, any metadata placed after
> the original kmalloc request size (orig_size) is not properly aligned
> on 64-bit architectures because its type is unsigned int. When both KASAN
> and SLAB_STORE_USER are enabled, kasan_alloc_meta is misaligned.
>
> Note that 64-bit architectures without HAVE_EFFICIENT_UNALIGNED_ACCESS
> are assumed to require 64-bit accesses to be 64-bit aligned.
> See HAVE_64BIT_ALIGNED_ACCESS and commit adab66b71abf ("Revert:
> "ring-buffer: Remove HAVE_64BIT_ALIGNED_ACCESS"") for more details.
>
> Because not all architectures support unaligned memory accesses,
> ensure that all metadata (track, orig_size, kasan_{alloc,free}_meta)
> in a slab object are word-aligned. struct track, kasan_{alloc,free}_meta
> are aligned by adding __aligned(__alignof__(unsigned long)).
>
> For orig_size, use ALIGN(sizeof(unsigned int), sizeof(unsigned long)) to
^ Uh, here I intended
to say:
__aligneof__(unsigned long))
> make clear that its size remains unsigned int but it must be aligned to
> a word boundary. On 64-bit architectures, this reserves 8 bytes for
> orig_size, which is acceptable since kmalloc's original request size
> tracking is intended for debugging rather than production use.
>
> Cc: stable@...r.kernel.org
> Fixes: 6edf2576a6cc ("mm/slub: enable debugging memory wasting of kmalloc")
> Acked-by: Andrey Konovalov <andreyknvl@...il.com>
> Signed-off-by: Harry Yoo <harry.yoo@...cle.com>
> ---
>
> v1 -> v2:
> - Added Andrey's Acked-by.
> - Added references to HAVE_64BIT_ALIGNED_ACCESS and the commit that
> resurrected it.
> - Used __alignof__() instead of sizeof(), as suggested by Pedro (off-list).
> Note: either __alignof__ or sizeof() produces the exactly same mm/slub.o
> files, so there's no functional difference.
>
> Thanks!
>
> mm/kasan/kasan.h | 4 ++--
> mm/slub.c | 16 +++++++++++-----
> 2 files changed, 13 insertions(+), 7 deletions(-)
--
Cheers,
Harry / Hyeonggon
Powered by blists - more mailing lists