From: "Zqiang" <qiang.zhang@linux.dev>
To: "Baokun Li" <libaokun@linux.alibaba.com>
Cc: linux-ext4@vger.kernel.org, linux-kernel@vger.kernel.org,
tytso@mit.edu, adilger.kernel@dilger.ca,
libaokun@linux.alibaba.com
Subject: Re: [PATCH] ext4: Fix possible NULL pointer dereference in ext4_group_desc_free()
Date: Mon, 16 Mar 2026 23:33:30 +0000 [thread overview]
Message-ID: <584a552d5b5cf7554f4a1c607e62f308436ff3eb@linux.dev> (raw)
In-Reply-To: <e275a80b-df14-4d05-9334-b10d2e57fbbc@linux.alibaba.com>
>
> On 3/16/26 4:20 PM, Zqiang wrote:
>
> >
> > This can happen if the kvmalloc_objs() fails and sbi->s_group_desc pointer
> > is NULL in the ext4_group_desc_init(), and then the ext4_group_desc_free()
> > is called, leading to a NULL group_desc pointer dereference.
> >
> > This commit therefore adds a NULL check for sbi->s_group_desc before
> > accessing its internal members.
> >
> > Signed-off-by: Zqiang <qiang.zhang@linux.dev>
> > ---
> > fs/ext4/super.c | 8 +++++---
> > 1 file changed, 5 insertions(+), 3 deletions(-)
> >
> > diff --git a/fs/ext4/super.c b/fs/ext4/super.c
> > index 43f680c750ae..c4307dc04687 100644
> > --- a/fs/ext4/super.c
> > +++ b/fs/ext4/super.c
> > @@ -1256,9 +1256,11 @@ static void ext4_group_desc_free(struct ext4_sb_info *sbi)
> >
> > rcu_read_lock();
> > group_desc = rcu_dereference(sbi->s_group_desc);
> > - for (i = 0; i < sbi->s_gdb_count; i++)
> >
> In ext4_group_desc_init(), s_gdb_count is only assigned after kvmalloc_array
> allocation succeeds. Therefore, when kvmalloc_array fails, the
> brelse(group_desc[i]) in ext4_group_desc_free() will not actually be
> executed,
> and thus this NULL pointer dereference issue will not be triggered.
Thanks for replay, got it, sorry for make noise.
Just then, I find that warning may be trigger:
the kvfree() is called in RCU read critical section, if
the sbi->s_group_desc pointer comes from vmalloc(),
the vfree() is called to release it, but the might_sleep()
is called in the vfree(), this may be trigger warnings in
rcu_sleep_check() when the enable CONFIG_DEBUG_ATOMIC_SLEEP.
May be use rcu_access_pointer() to access sbi->s_group_desc
is enough.
Thanks
Zqiang
>
> Cheers,
> Baokun
>
> >
> > - brelse(group_desc[i]);
> > - kvfree(group_desc);
> > + if (group_desc) {
> > + for (i = 0; i < sbi->s_gdb_count; i++)
> > + brelse(group_desc[i]);
> > + kvfree(group_desc);
> > + }
> > rcu_read_unlock();
> > }
> >
>
next prev parent reply other threads:[~2026-03-16 23:33 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-03-16 8:20 [PATCH] ext4: Fix possible NULL pointer dereference in ext4_group_desc_free() Zqiang
2026-03-16 15:49 ` Baokun Li
2026-03-16 23:33 ` Zqiang [this message]
2026-03-17 6:32 ` Baokun Li
2026-03-17 13:23 ` Zqiang
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=584a552d5b5cf7554f4a1c607e62f308436ff3eb@linux.dev \
--to=qiang.zhang@linux.dev \
--cc=adilger.kernel@dilger.ca \
--cc=libaokun@linux.alibaba.com \
--cc=linux-ext4@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=tytso@mit.edu \
/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.