All of lore.kernel.org
 help / color / mirror / Atom feed
From: Josh Law <hlcj1234567@gmail.com>
To: Pedro Falcato <pfalcato@suse.de>
Cc: Andrew Morton <akpm@linux-foundation.org>,
	"Liam R . Howlett" <Liam.Howlett@oracle.com>,
	Alice Ryhl <aliceryhl@google.com>,
	Andrew Ballance <andrewjballance@gmail.com>,
	Josh Law <objecting@objecting.org>,
	maple-tree@lists.infradead.org, linux-mm@kvack.org,
	linux-kernel@vger.kernel.org
Subject: Re: [PATCH 1/3] lib/maple_tree: fix potential NULL dereference in mas_pop_node()
Date: Fri, 13 Mar 2026 07:17:17 +0000	[thread overview]
Message-ID: <d73c8388-bcb5-4a8a-ad3e-da719b09fc40@gmail.com> (raw)
In-Reply-To: <i6tmfotangjjtzek5txtvoiav3xrfvwtw6cppooyja5mvywmz6@2c5rnyxqpgu6>

12 Mar 2026 23:22:48 Pedro Falcato <pfalcato@suse.de>:

> On Thu, Mar 12, 2026 at 01:45:31PM -0700, Andrew Morton wrote:
>> On Thu, 12 Mar 2026 18:40:53 +0000 Josh Law <hlcj1234567@gmail.com> wrote:
>>
>>> 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)).
>>
>> This is such a glaring bug that I wonder if we're missing something.
>
> According to my local copy of lib/maple_tree.c:
>
> mas_pop_node() - Get a previously allocated maple node from the maple state.
>
> Note the "previously" :) kmem_cache_alloc_from_sheaf() can only fail if you
> run out of objects in the sheaf.
>
> So yeah, this "bug" looks bogus.
>
> --
> Pedro

Hi Pedro,

I see the comment regarding 'previously allocated' nodes. However,
mas_pop_node() explicitly calls kmem_cache_alloc_from_sheaf() with
GFP_NOWAIT. If there is any path—even an unexpected one—where the
sheaf is exhausted or the allocator fails, the code immediately
performs a memset on the NULL pointer.

Even if this is a 'should never happen' scenario, returning NULL is
safer than a kernel panic. As Andrew noted, the current structure
allows a fall-through directly into a dereference. My patch ensures
we handle that edge case safely.


  reply	other threads:[~2026-03-13  7:17 UTC|newest]

Thread overview: 12+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
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-04-01  3:24   ` Liam R. Howlett
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 [this message]
2026-03-13  9:05       ` Pedro Falcato
2026-03-13 16:11         ` Josh Law

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=d73c8388-bcb5-4a8a-ad3e-da719b09fc40@gmail.com \
    --to=hlcj1234567@gmail.com \
    --cc=Liam.Howlett@oracle.com \
    --cc=akpm@linux-foundation.org \
    --cc=aliceryhl@google.com \
    --cc=andrewjballance@gmail.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-mm@kvack.org \
    --cc=maple-tree@lists.infradead.org \
    --cc=objecting@objecting.org \
    --cc=pfalcato@suse.de \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.