From: Amir Goldstein <amir73il@gmail.com>
To: youngjun <her0gyugyu@gmail.com>
Cc: Miklos Szeredi <miklos@szeredi.hu>,
overlayfs <linux-unionfs@vger.kernel.org>
Subject: Re: [PATCH] ovl: null dereference possibility fixup
Date: Sun, 21 Jun 2020 16:36:59 +0300 [thread overview]
Message-ID: <CAOQ4uxiOb6JKP6yyzppmrOWzfXUt8aptXxZXkUNHu8eFz4FH1Q@mail.gmail.com> (raw)
In-Reply-To: <20200621122747.58787-1-her0gyugyu@gmail.com>
On Sun, Jun 21, 2020 at 3:33 PM youngjun <her0gyugyu@gmail.com> wrote:
>
> lowerdentry could be NULL, and dereferenced by calling d_inode.
> code flow which described below
> shows possibility of null dereference in ovl_get_inode.
I think this is not possible...
>
> (export.c) ovl_lower_fh_to_d
> |_(export.c) ovl_get_dentry(sb, upper, NULL, NULL);
This gets called if ovl_index_upper() succeeded
and ovl_index_upper() can only return d_is_dir().
> |_(export.c) ovl_obtain_alias (sb, upper, NULL, NULL);
This only gets called for !d_is_dir()
> |_(inode.c) ovl_get_inode(sb, &oip);
> |_(in ovl_get_inode) realinode = d_inode(lowerdentry);
>
> Fixes: 09d8b586731bf("ovl: move __upperdentry to ovl_inode")
> Signed-off-by: youngjun <her0gyugyu@gmail.com>
> ---
> fs/overlayfs/inode.c | 4 +++-
> 1 file changed, 3 insertions(+), 1 deletion(-)
>
> diff --git a/fs/overlayfs/inode.c b/fs/overlayfs/inode.c
> index 8be6cd264f66..53d82ef68ba8 100644
> --- a/fs/overlayfs/inode.c
> +++ b/fs/overlayfs/inode.c
> @@ -958,8 +958,10 @@ struct inode *ovl_get_inode(struct super_block *sb,
> unsigned long ino = 0;
> int err = oip->newinode ? -EEXIST : -ENOMEM;
>
> - if (!realinode)
> + if (!realinode && lowerdentry)
> realinode = d_inode(lowerdentry);
> + else
> + return ERR_PTR(-EINVAL);
>
oip->lowerpath and oip->upperdentry should not be both NULL.
If you want you can add a WARN_ON about this and return EINVAL,
because that would be a bug that needs to be fixed, but I saw no
proof that this bug exists.
If the problem was reported by a static analysis tool, maybe you
can re-factor the helpers in export.c to be less entangled.
For example, ovl_obtain_alias() part can be open-coded
in the two call sites of ovl_get_dentry() that care about non-dir
and then we can assert that ovl_get_dentry() only handles directories.
Thanks,
Amir.
prev parent reply other threads:[~2020-06-21 13:37 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-06-21 12:27 [PATCH] ovl: null dereference possibility fixup youngjun
2020-06-21 13:36 ` Amir Goldstein [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=CAOQ4uxiOb6JKP6yyzppmrOWzfXUt8aptXxZXkUNHu8eFz4FH1Q@mail.gmail.com \
--to=amir73il@gmail.com \
--cc=her0gyugyu@gmail.com \
--cc=linux-unionfs@vger.kernel.org \
--cc=miklos@szeredi.hu \
/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;
as well as URLs for NNTP newsgroup(s).