public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH 1/3] lib/maple_tree: fix potential NULL dereference in mas_pop_node()
@ 2026-03-12 18:40 Josh Law
  2026-03-12 18:40 ` [PATCH 2/3] lib/maple_tree: fix always-true condition in mas_erase() Josh Law
  2026-03-12 20:45 ` [PATCH 1/3] lib/maple_tree: fix potential NULL dereference in mas_pop_node() Andrew Morton
  0 siblings, 2 replies; 11+ messages in thread
From: Josh Law @ 2026-03-12 18:40 UTC (permalink / raw)
  To: Liam R . Howlett, Andrew Morton
  Cc: Alice Ryhl, Andrew Ballance, Josh Law, maple-tree, linux-mm,
	linux-kernel

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 WARN_ON_ONCE NULL check after the sheaf allocation to bail out
early, matching the existing pattern for the !mas->sheaf case above.

Signed-off-by: Josh Law <objecting@objecting.org>
---
 lib/maple_tree.c | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/lib/maple_tree.c b/lib/maple_tree.c
index 739918e859e5..87a2ba6468ca 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 (WARN_ON_ONCE(!ret))
+		return NULL;
 
 out:
 	memset(ret, 0, sizeof(*ret));
-- 
2.34.1


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

end of thread, other threads:[~2026-03-13 16:11 UTC | newest]

Thread overview: 11+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-03-12 18:40 [PATCH 1/3] lib/maple_tree: fix potential NULL dereference in mas_pop_node() Josh Law
2026-03-12 18:40 ` [PATCH 2/3] lib/maple_tree: fix always-true condition in mas_erase() Josh Law
2026-03-12 20:45 ` [PATCH 1/3] lib/maple_tree: fix potential NULL dereference in mas_pop_node() Andrew Morton
2026-03-12 20:49   ` Josh Law
2026-03-12 20:56     ` Josh Law
2026-03-12 21:14       ` Josh Law
2026-03-12 23:00     ` Alice Ryhl
2026-03-12 23:22   ` Pedro Falcato
2026-03-13  7:17     ` Josh Law
2026-03-13  9:05       ` Pedro Falcato
2026-03-13 16:11         ` Josh Law

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