Linux filesystem development
 help / color / mirror / Atom feed
From: David Disseldorp <ddiss@suse.de>
To: longlong yan <yanlonglong@kylinos.cn>
Cc: viro@zeniv.linux.org.uk, brauner@kernel.org, jack@suse.cz,
	linux-fsdevel@vger.kernel.org, linux-kernel@vger.kernel.org
Subject: Re: [PATCH] initramfs_test: add NULL check for kmalloc in initramfs_test_fname_overrun
Date: Thu, 16 Jul 2026 23:47:18 +1000	[thread overview]
Message-ID: <20260716234718.31479e5d.ddiss@suse.de> (raw)
In-Reply-To: <20260715020820.425-1-yanlonglong@kylinos.cn>

Hi,

On Wed, 15 Jul 2026 10:08:19 +0800, longlong yan wrote:

> Add missing NULL check for kmalloc return value in
> initramfs_test_fname_overrun(). Without this check, if kmalloc fails,
> the subsequent memset() will dereference a NULL pointer, causing a
> kernel crash.
> 
> Fixes: 83c0b27266ec ("initramfs_test: kunit tests for initramfs unpacking")
> Signed-off-by: longlong yan <yanlonglong@kylinos.cn>
> ---
>  init/initramfs_test.c | 3 +++
>  1 file changed, 3 insertions(+)
> 
> diff --git a/init/initramfs_test.c b/init/initramfs_test.c
> index 1fc990a66563..c7aab7e5383e 100644
> --- a/init/initramfs_test.c
> +++ b/init/initramfs_test.c
> @@ -189,6 +189,9 @@ static void __init initramfs_test_fname_overrun(struct kunit *test)
>  	 * are already available (e.g. no compression).
>  	 */
>  	cpio_srcbuf = kmalloc(CPIO_HDRLEN + PATH_MAX + 3, GFP_KERNEL);
> +	if (!cpio_srcbuf)
> +		return;
> +
>  	memset(cpio_srcbuf, 'B', CPIO_HDRLEN + PATH_MAX + 3);

Panicking on kunit test alloc failure is reasonable behaviour IMO;
the Fixes tag isn't appropriate here. Also, your patch is only
handling one of the many allocations. KUNIT_ASSERT_NOT_NULL() would be
a better option if we wanted to explictly catch these failures.

      reply	other threads:[~2026-07-16 13:47 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-07-15  2:08 [PATCH] initramfs_test: add NULL check for kmalloc in initramfs_test_fname_overrun longlong yan
2026-07-16 13:47 ` David Disseldorp [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=20260716234718.31479e5d.ddiss@suse.de \
    --to=ddiss@suse.de \
    --cc=brauner@kernel.org \
    --cc=jack@suse.cz \
    --cc=linux-fsdevel@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=viro@zeniv.linux.org.uk \
    --cc=yanlonglong@kylinos.cn \
    /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