linux-mm.kvack.org archive mirror
 help / color / mirror / Atom feed
* [PATCH v2] lib/maple_tree: fix potential NULL dereference in mas_pop_node()
@ 2026-03-13  7:31 Josh Law
  2026-04-01  3:27 ` Liam R. Howlett
  0 siblings, 1 reply; 2+ messages in thread
From: Josh Law @ 2026-03-13  7:31 UTC (permalink / raw)
  To: Liam R . Howlett, Andrew Morton
  Cc: Alice Ryhl, Andrew Ballance, linux-kernel, maple-tree, linux-mm,
	Josh Law

If kmem_cache_alloc_from_sheaf() returns NULL (possible under
GFP_NOWAIT pressure), mas_pop_node() falls through to the out label
and dereferences the NULL pointer in memset(ret, 0, sizeof(*ret)).

Add a NULL check after the sheaf allocation to bail out early.

Signed-off-by: Josh Law <objecting@objecting.org>
---
v2: drop WARN_ON_ONCE — this is a recoverable allocation failure,
    not a state that warrants a warning splat.

 lib/maple_tree.c | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/lib/maple_tree.c b/lib/maple_tree.c
index 739918e859e5..1eaaa5f964e9 100644
--- a/lib/maple_tree.c
+++ b/lib/maple_tree.c
@@ -1063,6 +1063,8 @@ static __always_inline struct maple_node *mas_pop_node(struct ma_state *mas)
 		return NULL;

 	ret = kmem_cache_alloc_from_sheaf(maple_node_cache, GFP_NOWAIT, mas->sheaf);
+	if (!ret)
+		return NULL;

 out:
 	memset(ret, 0, sizeof(*ret));
--
2.34.1


^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: [PATCH v2] lib/maple_tree: fix potential NULL dereference in mas_pop_node()
  2026-03-13  7:31 [PATCH v2] lib/maple_tree: fix potential NULL dereference in mas_pop_node() Josh Law
@ 2026-04-01  3:27 ` Liam R. Howlett
  0 siblings, 0 replies; 2+ messages in thread
From: Liam R. Howlett @ 2026-04-01  3:27 UTC (permalink / raw)
  To: Josh Law
  Cc: Andrew Morton, Alice Ryhl, Andrew Ballance, linux-kernel,
	maple-tree, linux-mm, Josh Law

* Josh Law <hlcj1234567@gmail.com> [260313 03:31]:
> If kmem_cache_alloc_from_sheaf() returns NULL (possible under
> GFP_NOWAIT pressure), mas_pop_node() falls through to the out label
> and dereferences the NULL pointer in memset(ret, 0, sizeof(*ret)).
> 
> Add a NULL check after the sheaf allocation to bail out early.
> 
> Signed-off-by: Josh Law <objecting@objecting.org>
> ---
> v2: drop WARN_ON_ONCE — this is a recoverable allocation failure,
>     not a state that warrants a warning splat.
> 
>  lib/maple_tree.c | 2 ++
>  1 file changed, 2 insertions(+)
> 
> diff --git a/lib/maple_tree.c b/lib/maple_tree.c
> index 739918e859e5..1eaaa5f964e9 100644
> --- a/lib/maple_tree.c
> +++ b/lib/maple_tree.c
> @@ -1063,6 +1063,8 @@ static __always_inline struct maple_node *mas_pop_node(struct ma_state *mas)
>  		return NULL;
> 
>  	ret = kmem_cache_alloc_from_sheaf(maple_node_cache, GFP_NOWAIT, mas->sheaf);
> +	if (!ret)
> +		return NULL;
> 

This isn't necessary, as explained to v1 after this was sent, I think?

What a mess.  I'm objecting.

Liam


^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2026-04-01  3:27 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2026-03-13  7:31 [PATCH v2] lib/maple_tree: fix potential NULL dereference in mas_pop_node() Josh Law
2026-04-01  3:27 ` Liam R. Howlett

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox