From: Wang Zhaolong <wangzhaolong1@huawei.com>
To: Markus Elfring <Markus.Elfring@web.de>, <linux-unionfs@vger.kernel.org>
Cc: LKML <linux-kernel@vger.kernel.org>,
Amir Goldstein <amir73il@gmail.com>,
Miklos Szeredi <miklos@szeredi.hu>,
Yang Erkun <yangerkun@huawei.com>, Zhang Yi <yi.zhang@huawei.com>
Subject: Re: [PATCH] overlayfs: fix potential NULL pointer dereferences in file handle code
Date: Mon, 28 Apr 2025 21:01:16 +0800 [thread overview]
Message-ID: <5e59d7ba-3b2a-40fb-b305-7b5a6316128f@huawei.com> (raw)
In-Reply-To: <0b8cbc01-0db9-48ae-ae13-7158a94a8908@web.de>
> …
>> +++ b/fs/overlayfs/namei.c
>> @@ -496,10 +496,13 @@ static int ovl_verify_fh(struct ovl_fs *ofs, struct dentry *dentry,
>> enum ovl_xattr ox, const struct ovl_fh *fh)
>> {
>> struct ovl_fh *ofh = ovl_get_fh(ofs, dentry, ox);
>> int err = 0;
>>
>> + if (!fh)
>> + return -ENODATA;
>> +
>> if (!ofh)
>> return -ENODATA;
> …
>
> How do you think about to reduce the scope for these local variables
> (according to adjustment possibilities for input parameter validation)?
>
> Regards,
> Markus
Hi Markus,
Thanks for your review!
Inspired by your suggestions, I would like to modify the approach as follows:
1. Postpone ofh initialization until after fh validation
2. Return -EINVAL for NULL fh (as invalid parameter rather than missing data)
```
@@ -493,13 +493,17 @@ static int ovl_check_origin(struct ovl_fs *ofs, struct dentry *upperdentry,
* Return 0 on match, -ESTALE on mismatch, < 0 on error.
*/
static int ovl_verify_fh(struct ovl_fs *ofs, struct dentry *dentry,
enum ovl_xattr ox, const struct ovl_fh *fh)
{
- struct ovl_fh *ofh = ovl_get_fh(ofs, dentry, ox);
+ struct ovl_fh *ofh;
int err = 0;
+ if (!fh)
+ return -EINVAL;
+
+ ofh = ovl_get_fh(ofs, dentry, ox);
if (!ofh)
return -ENODATA;
if (IS_ERR(ofh))
return PTR_ERR(ofh);
```
3. Drop the unnecessary "&& fh" check in ovl_verify_set_fh() since NULL fh would
return -EINVAL, not -ENODATA
This changes prevents unnecessary memory allocation and makes error handling more
precise.
What do you think of this modification? Does this approach work for you?
Regards,
Wang Zhaolong
next prev parent reply other threads:[~2025-04-28 13:01 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-04-28 11:11 Wang Zhaolong
2025-04-28 11:48 ` Markus Elfring
2025-04-28 13:01 ` Wang Zhaolong [this message]
2025-04-29 0:13 Wang Zhaolong
2025-04-29 12:01 ` Miklos Szeredi
2025-04-30 9:56 ` Wang Zhaolong
2025-04-29 18:34 ` Markus Elfring
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=5e59d7ba-3b2a-40fb-b305-7b5a6316128f@huawei.com \
--to=wangzhaolong1@huawei.com \
--cc=Markus.Elfring@web.de \
--cc=amir73il@gmail.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-unionfs@vger.kernel.org \
--cc=miklos@szeredi.hu \
--cc=yangerkun@huawei.com \
--cc=yi.zhang@huawei.com \
/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®