* [PATCH linux-next] alloc_tag: Fix boot failure due to NULL pointer dereference
@ 2025-09-26 8:06 ranxiaokai627
2025-09-26 8:54 ` Harry Yoo
2025-09-26 12:48 ` Vlastimil Babka
0 siblings, 2 replies; 4+ messages in thread
From: ranxiaokai627 @ 2025-09-26 8:06 UTC (permalink / raw)
To: vbabka, akpm, cl, rientjes, roman.gushchin, harry.yoo,
usamaarif642, surenb, shakeel.butt, hannes
Cc: linux-kernel, linux-mm, ran.xiaokai, ranxiaokai627
From: Ran Xiaokai <ran.xiaokai@zte.com.cn>
There is a boot failure when both CONFIG_DEBUG_KMEMLEAK and
CONFIG_MEM_ALLOC_PROFILING are enabled.
BUG: kernel NULL pointer dereference, address: 0000000000000000
RIP: 0010:__alloc_tagging_slab_alloc_hook+0x181/0x2f0
Call Trace:
kmem_cache_alloc_noprof+0x1c8/0x5c0
__alloc_object+0x2f/0x290
__create_object+0x22/0x80
kmemleak_init+0x122/0x190
mm_core_init+0xb6/0x160
start_kernel+0x39f/0x920
x86_64_start_reservations+0x18/0x30
x86_64_start_kernel+0x104/0x120
common_startup_64+0x12c/0x138
In kmemleak, mem_pool_alloc() directly calls kmem_cache_alloc_noprof(),
as a result, the alloc_tag structure associated with object_cache is not
defined neither initialized. So current->alloc_tag is NULL,
leading to a null pointer dereference.
Move the checks for SLAB_NO_OBJ_EXT, SLAB_NOLEAKTRACE, and
__GFP_NO_OBJ_EXT to the parent function __alloc_tagging_slab_alloc_hook()
to fix this.
Also this distinguishes the SLAB_NOLEAKTRACE case between the actual memory
allocation failures case, make CODETAG_FLAG_INACCURATE more accurate.
Fixes: b9e2f58ffb84 ("alloc_tag: mark inaccurate allocation counters in /proc/allocinfo output")
Signed-off-by: Ran Xiaokai <ran.xiaokai@zte.com.cn>
---
mm/slub.c | 18 +++++++++---------
1 file changed, 9 insertions(+), 9 deletions(-)
diff --git a/mm/slub.c b/mm/slub.c
index 867a07260acf..09cbe580842c 100644
--- a/mm/slub.c
+++ b/mm/slub.c
@@ -2197,15 +2197,6 @@ prepare_slab_obj_exts_hook(struct kmem_cache *s, gfp_t flags, void *p)
{
struct slab *slab;
- if (!p)
- return NULL;
-
- if (s->flags & (SLAB_NO_OBJ_EXT | SLAB_NOLEAKTRACE))
- return NULL;
-
- if (flags & __GFP_NO_OBJ_EXT)
- return NULL;
-
slab = virt_to_slab(p);
if (!slab_obj_exts(slab) &&
alloc_slab_obj_exts(slab, s, flags, false)) {
@@ -2223,6 +2214,15 @@ __alloc_tagging_slab_alloc_hook(struct kmem_cache *s, void *object, gfp_t flags)
{
struct slabobj_ext *obj_exts;
+ if (!object)
+ return;
+
+ if (s->flags & (SLAB_NO_OBJ_EXT | SLAB_NOLEAKTRACE))
+ return;
+
+ if (flags & __GFP_NO_OBJ_EXT)
+ return;
+
obj_exts = prepare_slab_obj_exts_hook(s, flags, object);
/*
* Currently obj_exts is used only for allocation profiling.
--
2.25.1
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH linux-next] alloc_tag: Fix boot failure due to NULL pointer dereference
2025-09-26 8:06 [PATCH linux-next] alloc_tag: Fix boot failure due to NULL pointer dereference ranxiaokai627
@ 2025-09-26 8:54 ` Harry Yoo
2025-09-26 12:48 ` Vlastimil Babka
1 sibling, 0 replies; 4+ messages in thread
From: Harry Yoo @ 2025-09-26 8:54 UTC (permalink / raw)
To: ranxiaokai627
Cc: vbabka, akpm, cl, rientjes, roman.gushchin, usamaarif642, surenb,
shakeel.butt, hannes, linux-kernel, linux-mm, ran.xiaokai
On Fri, Sep 26, 2025 at 08:06:59AM +0000, ranxiaokai627@163.com wrote:
> From: Ran Xiaokai <ran.xiaokai@zte.com.cn>
>
> There is a boot failure when both CONFIG_DEBUG_KMEMLEAK and
> CONFIG_MEM_ALLOC_PROFILING are enabled.
>
> BUG: kernel NULL pointer dereference, address: 0000000000000000
> RIP: 0010:__alloc_tagging_slab_alloc_hook+0x181/0x2f0
> Call Trace:
> kmem_cache_alloc_noprof+0x1c8/0x5c0
> __alloc_object+0x2f/0x290
> __create_object+0x22/0x80
> kmemleak_init+0x122/0x190
> mm_core_init+0xb6/0x160
> start_kernel+0x39f/0x920
> x86_64_start_reservations+0x18/0x30
> x86_64_start_kernel+0x104/0x120
> common_startup_64+0x12c/0x138
>
> In kmemleak, mem_pool_alloc() directly calls kmem_cache_alloc_noprof(),
> as a result, the alloc_tag structure associated with object_cache is not
> defined neither initialized.
nit: "the alloc_tag structure associated with object_cache is not
defined neither initialized" sounds weird because here we're talking
about current->alloc_tag being NULL, and it is not something we
associate with a slab cache.
> So current->alloc_tag is NULL,
> leading to a null pointer dereference.
> Move the checks for SLAB_NO_OBJ_EXT, SLAB_NOLEAKTRACE, and
> __GFP_NO_OBJ_EXT to the parent function __alloc_tagging_slab_alloc_hook()
> to fix this.
>
> Also this distinguishes the SLAB_NOLEAKTRACE case between the actual memory
> allocation failures case, make CODETAG_FLAG_INACCURATE more accurate.
>
> Fixes: b9e2f58ffb84 ("alloc_tag: mark inaccurate allocation counters in /proc/allocinfo output")
> Signed-off-by: Ran Xiaokai <ran.xiaokai@zte.com.cn>
> ---
In general, the fix makes sense and looks good to me.
Reviewed-by: Harry Yoo <harry.yoo@oracle.com>
--
Cheers,
Harry / Hyeonggon
> mm/slub.c | 18 +++++++++---------
> 1 file changed, 9 insertions(+), 9 deletions(-)
>
> diff --git a/mm/slub.c b/mm/slub.c
> index 867a07260acf..09cbe580842c 100644
> --- a/mm/slub.c
> +++ b/mm/slub.c
> @@ -2197,15 +2197,6 @@ prepare_slab_obj_exts_hook(struct kmem_cache *s, gfp_t flags, void *p)
> {
> struct slab *slab;
>
> - if (!p)
> - return NULL;
> -
> - if (s->flags & (SLAB_NO_OBJ_EXT | SLAB_NOLEAKTRACE))
> - return NULL;
> -
> - if (flags & __GFP_NO_OBJ_EXT)
> - return NULL;
> -
> slab = virt_to_slab(p);
> if (!slab_obj_exts(slab) &&
> alloc_slab_obj_exts(slab, s, flags, false)) {
> @@ -2223,6 +2214,15 @@ __alloc_tagging_slab_alloc_hook(struct kmem_cache *s, void *object, gfp_t flags)
> {
> struct slabobj_ext *obj_exts;
>
> + if (!object)
> + return;
> +
> + if (s->flags & (SLAB_NO_OBJ_EXT | SLAB_NOLEAKTRACE))
> + return;
> +
> + if (flags & __GFP_NO_OBJ_EXT)
> + return;
> +
> obj_exts = prepare_slab_obj_exts_hook(s, flags, object);
> /*
> * Currently obj_exts is used only for allocation profiling.
> --
> 2.25.1
>
>
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH linux-next] alloc_tag: Fix boot failure due to NULL pointer dereference
2025-09-26 8:06 [PATCH linux-next] alloc_tag: Fix boot failure due to NULL pointer dereference ranxiaokai627
2025-09-26 8:54 ` Harry Yoo
@ 2025-09-26 12:48 ` Vlastimil Babka
2025-09-26 15:36 ` Suren Baghdasaryan
1 sibling, 1 reply; 4+ messages in thread
From: Vlastimil Babka @ 2025-09-26 12:48 UTC (permalink / raw)
To: ranxiaokai627, akpm, cl, rientjes, roman.gushchin, harry.yoo,
usamaarif642, surenb, shakeel.butt, hannes
Cc: linux-kernel, linux-mm, ran.xiaokai
On 9/26/25 10:06, ranxiaokai627@163.com wrote:
> From: Ran Xiaokai <ran.xiaokai@zte.com.cn>
>
> There is a boot failure when both CONFIG_DEBUG_KMEMLEAK and
> CONFIG_MEM_ALLOC_PROFILING are enabled.
>
> BUG: kernel NULL pointer dereference, address: 0000000000000000
> RIP: 0010:__alloc_tagging_slab_alloc_hook+0x181/0x2f0
> Call Trace:
> kmem_cache_alloc_noprof+0x1c8/0x5c0
> __alloc_object+0x2f/0x290
> __create_object+0x22/0x80
> kmemleak_init+0x122/0x190
> mm_core_init+0xb6/0x160
> start_kernel+0x39f/0x920
> x86_64_start_reservations+0x18/0x30
> x86_64_start_kernel+0x104/0x120
> common_startup_64+0x12c/0x138
>
> In kmemleak, mem_pool_alloc() directly calls kmem_cache_alloc_noprof(),
> as a result, the alloc_tag structure associated with object_cache is not
> defined neither initialized. So current->alloc_tag is NULL,
> leading to a null pointer dereference.
Agree with Harry. This should be enough:
"as a result, current->alloc_tag is NULL, leading to a null pointer
dereference."
> Move the checks for SLAB_NO_OBJ_EXT, SLAB_NOLEAKTRACE, and
> __GFP_NO_OBJ_EXT to the parent function __alloc_tagging_slab_alloc_hook()
> to fix this.
>
> Also this distinguishes the SLAB_NOLEAKTRACE case between the actual memory
> allocation failures case, make CODETAG_FLAG_INACCURATE more accurate.
Good point.
> Fixes: b9e2f58ffb84 ("alloc_tag: mark inaccurate allocation counters in /proc/allocinfo output")
That's in mm-stable so the fix should go there (probably too late to fold
now) if it's to be in the merge window PR.
> Signed-off-by: Ran Xiaokai <ran.xiaokai@zte.com.cn>
Acked-by: Vlastimil Babka <vbabka@suse.cz>
> ---
> mm/slub.c | 18 +++++++++---------
> 1 file changed, 9 insertions(+), 9 deletions(-)
>
> diff --git a/mm/slub.c b/mm/slub.c
> index 867a07260acf..09cbe580842c 100644
> --- a/mm/slub.c
> +++ b/mm/slub.c
> @@ -2197,15 +2197,6 @@ prepare_slab_obj_exts_hook(struct kmem_cache *s, gfp_t flags, void *p)
> {
> struct slab *slab;
>
> - if (!p)
> - return NULL;
> -
> - if (s->flags & (SLAB_NO_OBJ_EXT | SLAB_NOLEAKTRACE))
> - return NULL;
> -
> - if (flags & __GFP_NO_OBJ_EXT)
> - return NULL;
> -
> slab = virt_to_slab(p);
> if (!slab_obj_exts(slab) &&
> alloc_slab_obj_exts(slab, s, flags, false)) {
> @@ -2223,6 +2214,15 @@ __alloc_tagging_slab_alloc_hook(struct kmem_cache *s, void *object, gfp_t flags)
> {
> struct slabobj_ext *obj_exts;
>
> + if (!object)
> + return;
> +
> + if (s->flags & (SLAB_NO_OBJ_EXT | SLAB_NOLEAKTRACE))
> + return;
> +
> + if (flags & __GFP_NO_OBJ_EXT)
> + return;
> +
> obj_exts = prepare_slab_obj_exts_hook(s, flags, object);
> /*
> * Currently obj_exts is used only for allocation profiling.
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH linux-next] alloc_tag: Fix boot failure due to NULL pointer dereference
2025-09-26 12:48 ` Vlastimil Babka
@ 2025-09-26 15:36 ` Suren Baghdasaryan
0 siblings, 0 replies; 4+ messages in thread
From: Suren Baghdasaryan @ 2025-09-26 15:36 UTC (permalink / raw)
To: Vlastimil Babka
Cc: ranxiaokai627, akpm, cl, rientjes, roman.gushchin, harry.yoo,
usamaarif642, shakeel.butt, hannes, linux-kernel, linux-mm,
ran.xiaokai
On Fri, Sep 26, 2025 at 5:48 AM Vlastimil Babka <vbabka@suse.cz> wrote:
>
> On 9/26/25 10:06, ranxiaokai627@163.com wrote:
> > From: Ran Xiaokai <ran.xiaokai@zte.com.cn>
> >
> > There is a boot failure when both CONFIG_DEBUG_KMEMLEAK and
> > CONFIG_MEM_ALLOC_PROFILING are enabled.
> >
> > BUG: kernel NULL pointer dereference, address: 0000000000000000
> > RIP: 0010:__alloc_tagging_slab_alloc_hook+0x181/0x2f0
> > Call Trace:
> > kmem_cache_alloc_noprof+0x1c8/0x5c0
> > __alloc_object+0x2f/0x290
> > __create_object+0x22/0x80
> > kmemleak_init+0x122/0x190
> > mm_core_init+0xb6/0x160
> > start_kernel+0x39f/0x920
> > x86_64_start_reservations+0x18/0x30
> > x86_64_start_kernel+0x104/0x120
> > common_startup_64+0x12c/0x138
> >
> > In kmemleak, mem_pool_alloc() directly calls kmem_cache_alloc_noprof(),
> > as a result, the alloc_tag structure associated with object_cache is not
> > defined neither initialized. So current->alloc_tag is NULL,
> > leading to a null pointer dereference.
>
> Agree with Harry. This should be enough:
>
> "as a result, current->alloc_tag is NULL, leading to a null pointer
> dereference."
Yes, that's much more clear.
>
> > Move the checks for SLAB_NO_OBJ_EXT, SLAB_NOLEAKTRACE, and
> > __GFP_NO_OBJ_EXT to the parent function __alloc_tagging_slab_alloc_hook()
> > to fix this.
> >
> > Also this distinguishes the SLAB_NOLEAKTRACE case between the actual memory
> > allocation failures case, make CODETAG_FLAG_INACCURATE more accurate.
Awsome!
>
> Good point.
>
> > Fixes: b9e2f58ffb84 ("alloc_tag: mark inaccurate allocation counters in /proc/allocinfo output")
>
> That's in mm-stable so the fix should go there (probably too late to fold
> now) if it's to be in the merge window PR.
>
> > Signed-off-by: Ran Xiaokai <ran.xiaokai@zte.com.cn>
>
> Acked-by: Vlastimil Babka <vbabka@suse.cz>
Reviewed-by: Suren Baghdasaryan <surenb@google.com>
Thanks for the fix!
>
> > ---
> > mm/slub.c | 18 +++++++++---------
> > 1 file changed, 9 insertions(+), 9 deletions(-)
> >
> > diff --git a/mm/slub.c b/mm/slub.c
> > index 867a07260acf..09cbe580842c 100644
> > --- a/mm/slub.c
> > +++ b/mm/slub.c
> > @@ -2197,15 +2197,6 @@ prepare_slab_obj_exts_hook(struct kmem_cache *s, gfp_t flags, void *p)
> > {
> > struct slab *slab;
> >
> > - if (!p)
> > - return NULL;
> > -
> > - if (s->flags & (SLAB_NO_OBJ_EXT | SLAB_NOLEAKTRACE))
> > - return NULL;
> > -
> > - if (flags & __GFP_NO_OBJ_EXT)
> > - return NULL;
> > -
> > slab = virt_to_slab(p);
> > if (!slab_obj_exts(slab) &&
> > alloc_slab_obj_exts(slab, s, flags, false)) {
> > @@ -2223,6 +2214,15 @@ __alloc_tagging_slab_alloc_hook(struct kmem_cache *s, void *object, gfp_t flags)
> > {
> > struct slabobj_ext *obj_exts;
> >
> > + if (!object)
> > + return;
> > +
> > + if (s->flags & (SLAB_NO_OBJ_EXT | SLAB_NOLEAKTRACE))
> > + return;
> > +
> > + if (flags & __GFP_NO_OBJ_EXT)
> > + return;
> > +
> > obj_exts = prepare_slab_obj_exts_hook(s, flags, object);
> > /*
> > * Currently obj_exts is used only for allocation profiling.
>
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2025-09-26 15:36 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2025-09-26 8:06 [PATCH linux-next] alloc_tag: Fix boot failure due to NULL pointer dereference ranxiaokai627
2025-09-26 8:54 ` Harry Yoo
2025-09-26 12:48 ` Vlastimil Babka
2025-09-26 15:36 ` Suren Baghdasaryan
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox