($INBOX_DIR/description missing)
 help / color / Atom feed
* [PATCH] ovl: null dereference possibility fixup
@ 2020-06-21 12:27 youngjun
  2020-06-21 13:36 ` Amir Goldstein
  0 siblings, 1 reply; 2+ messages in thread
From: youngjun @ 2020-06-21 12:27 UTC (permalink / raw)
  To: Miklos Szeredi; +Cc: linux-unionfs, youngjun

lowerdentry could be NULL, and dereferenced by calling d_inode.
code flow which described below
shows possibility of null dereference in ovl_get_inode.

(export.c) ovl_lower_fh_to_d
|_(export.c) ovl_get_dentry(sb, upper, NULL, NULL);
 |_(export.c) ovl_obtain_alias (sb, upper, NULL, NULL);
  |_(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);
 
 	/*
 	 * Copy up origin (lower) may exist for non-indexed upper, but we must
-- 
2.17.1


^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: [PATCH] ovl: null dereference possibility fixup
  2020-06-21 12:27 [PATCH] ovl: null dereference possibility fixup youngjun
@ 2020-06-21 13:36 ` Amir Goldstein
  0 siblings, 0 replies; 2+ messages in thread
From: Amir Goldstein @ 2020-06-21 13:36 UTC (permalink / raw)
  To: youngjun; +Cc: Miklos Szeredi, overlayfs

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.

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, back to index

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-06-21 12:27 [PATCH] ovl: null dereference possibility fixup youngjun
2020-06-21 13:36 ` Amir Goldstein

($INBOX_DIR/description missing)

Archives are clonable:
	git clone --mirror https://lore.kernel.org/linux-unionfs/0 linux-unionfs/git/0.git

	# If you have public-inbox 1.1+ installed, you may
	# initialize and index your mirror using the following commands:
	public-inbox-init -V2 linux-unionfs linux-unionfs/ https://lore.kernel.org/linux-unionfs \
		linux-unionfs@vger.kernel.org
	public-inbox-index linux-unionfs

Example config snippet for mirrors

Newsgroup available over NNTP:
	nntp://nntp.lore.kernel.org/org.kernel.vger.linux-unionfs


AGPL code for this site: git clone https://public-inbox.org/public-inbox.git