From: Andrew Morton <akpm@linux-foundation.org>
To: Tuo Li <islituo@gmail.com>
Cc: linux-kernel@vger.kernel.org
Subject: Re: [PATCH] lib/test_meminit: handle kmem_cache_alloc() failure
Date: Sat, 10 Oct 2026 16:08:58 -0700 [thread overview]
Message-ID: <20261010160858.453c904ce17dfa8868ba3f9b@linux-foundation.org> (raw)
In-Reply-To: <20261009073040.2995938-1-islituo@gmail.com>
On Fri, 9 Oct 2026 15:30:40 +0800 Tuo Li <islituo@gmail.com> wrote:
> In do_kmem_cache_size(), kmem_cache_alloc() may fail and return NULL.
> The returned pointer is subsequently passed to check_buf() and
> fill_with_garbage_skip() without being checked, which may result in a
> NULL pointer dereference.
>
> Handle the allocation failure by marking the test as failed and
> continuing with the next iteration.
>
> ...
>
> --- a/lib/test_meminit.c
> +++ b/lib/test_meminit.c
> @@ -241,6 +241,10 @@ static int __init do_kmem_cache_size(size_t size, bool want_ctor,
> }
>
> buf = kmem_cache_alloc(c, alloc_mask);
> + if (!buf) {
> + fail = true;
> + continue;
> + }
> /* Check that buf is zeroed, if it must be. */
> fail |= check_buf(buf, size, want_ctor, want_rcu, want_zero);
> fill_with_garbage_skip(buf, size, want_ctor ? CTOR_BYTES : 0);
Thanks, but we have an assumption that __init-time allocations cannot
fail and so they don't need to be checked. Because if they do fail,
something has gone horribly wrong and this kernel cannot work and a
later null-deref of "buf" is a suitable way of reporting this.
prev parent reply other threads:[~2026-10-10 23:08 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-10-09 7:30 Tuo Li
2026-10-10 23:08 ` Andrew Morton [this message]
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=20261010160858.453c904ce17dfa8868ba3f9b@linux-foundation.org \
--to=akpm@linux-foundation.org \
--cc=islituo@gmail.com \
--cc=linux-kernel@vger.kernel.org \
/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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®