All of lore.kernel.org
 help / color / mirror / Atom feed
From: Huang Jianan <huangjianan@oppo.com>
To: Miklos Szeredi <miklos@szeredi.hu>
Cc: Chengguang Xu <cgxu519@139.com>,
	overlayfs <linux-unionfs@vger.kernel.org>,
	linux-erofs@lists.ozlabs.org, xiang@kernel.org, chao@kernel.org,
	guoweichao@oppo.com, yh@oppo.com, zhangshiming@oppo.com,
	guanyuwei@oppo.com, jnhuang95@gmail.com,
	linux-kernel@vger.kernel.org, linux-fsdevel@vger.kernel.org,
	Chengguang Xu <cgxu519@mykernel.net>
Subject: Re: [PATCH v3] ovl: fix null pointer when filesystemdoesn'tsupportdirect IO
Date: Tue, 28 Sep 2021 15:01:14 +0800	[thread overview]
Message-ID: <97977a2c-28d5-1324-fb1e-3e23ab4b1340@oppo.com> (raw)
In-Reply-To: <YVGRMoRTH4oJpxWZ@miu.piliscsaba.redhat.com>

在 2021/9/27 17:38, Miklos Szeredi 写道:
> On Wed, Sep 22, 2021 at 04:00:47PM +0200, Miklos Szeredi wrote:
>
>> First let's fix the oops: ovl_read_iter()/ovl_write_iter() must check
>> real file's ->direct_IO if IOCB_DIRECT is set in iocb->ki_flags and
>> return -EINVAL if not.
> And here's that fix.  Please test.

This patch can fix the oops.

Tested-by: Huang Jianan <huangjianan@oppo.com>

Thanks,
Jianan

> Thanks,
> Miklos
>
> ---
> From: Miklos Szeredi <mszeredi@redhat.com>
> Subject: ovl: fix IOCB_DIRECT if underlying fs doesn't support direct IO
>
> Normally the check at open time suffices, but e.g loop device does set
> IOCB_DIRECT after doing its own checks (which are not sufficent for
> overlayfs).
>
> Make sure we don't call the underlying filesystem read/write method with
> the IOCB_DIRECT if it's not supported.
>
> Reported-by: Huang Jianan <huangjianan@oppo.com>
> Fixes: 16914e6fc7e1 ("ovl: add ovl_read_iter()")
> Cc: <stable@vger.kernel.org> # v4.19
> Signed-off-by: Miklos Szeredi <mszeredi@redhat.com>
> ---
>   fs/overlayfs/file.c |   15 ++++++++++++++-
>   1 file changed, 14 insertions(+), 1 deletion(-)
>
> --- a/fs/overlayfs/file.c
> +++ b/fs/overlayfs/file.c
> @@ -296,6 +296,12 @@ static ssize_t ovl_read_iter(struct kioc
>   	if (ret)
>   		return ret;
>   
> +	ret = -EINVAL;
> +	if (iocb->ki_flags & IOCB_DIRECT &&
> +	    (!real.file->f_mapping->a_ops ||
> +	     !real.file->f_mapping->a_ops->direct_IO))
> +		goto out_fdput;
> +
>   	old_cred = ovl_override_creds(file_inode(file)->i_sb);
>   	if (is_sync_kiocb(iocb)) {
>   		ret = vfs_iter_read(real.file, iter, &iocb->ki_pos,
> @@ -320,7 +326,7 @@ static ssize_t ovl_read_iter(struct kioc
>   out:
>   	revert_creds(old_cred);
>   	ovl_file_accessed(file);
> -
> +out_fdput:
>   	fdput(real);
>   
>   	return ret;
> @@ -349,6 +355,12 @@ static ssize_t ovl_write_iter(struct kio
>   	if (ret)
>   		goto out_unlock;
>   
> +	ret = -EINVAL;
> +	if (iocb->ki_flags & IOCB_DIRECT &&
> +	    (!real.file->f_mapping->a_ops ||
> +	     !real.file->f_mapping->a_ops->direct_IO))
> +		goto out_fdput;
> +
>   	if (!ovl_should_sync(OVL_FS(inode->i_sb)))
>   		ifl &= ~(IOCB_DSYNC | IOCB_SYNC);
>   
> @@ -384,6 +396,7 @@ static ssize_t ovl_write_iter(struct kio
>   	}
>   out:
>   	revert_creds(old_cred);
> +out_fdput:
>   	fdput(real);
>   
>   out_unlock:


WARNING: multiple messages have this Message-ID (diff)
From: Huang Jianan via Linux-erofs <linux-erofs@lists.ozlabs.org>
To: Miklos Szeredi <miklos@szeredi.hu>
Cc: zhangshiming@oppo.com, linux-kernel@vger.kernel.org,
	overlayfs <linux-unionfs@vger.kernel.org>,
	Chengguang Xu <cgxu519@mykernel.net>,
	yh@oppo.com, guanyuwei@oppo.com, linux-fsdevel@vger.kernel.org,
	guoweichao@oppo.com, linux-erofs@lists.ozlabs.org,
	Chengguang Xu <cgxu519@139.com>
Subject: Re: [PATCH v3] ovl: fix null pointer when filesystemdoesn'tsupportdirect IO
Date: Tue, 28 Sep 2021 15:01:14 +0800	[thread overview]
Message-ID: <97977a2c-28d5-1324-fb1e-3e23ab4b1340@oppo.com> (raw)
In-Reply-To: <YVGRMoRTH4oJpxWZ@miu.piliscsaba.redhat.com>

在 2021/9/27 17:38, Miklos Szeredi 写道:
> On Wed, Sep 22, 2021 at 04:00:47PM +0200, Miklos Szeredi wrote:
>
>> First let's fix the oops: ovl_read_iter()/ovl_write_iter() must check
>> real file's ->direct_IO if IOCB_DIRECT is set in iocb->ki_flags and
>> return -EINVAL if not.
> And here's that fix.  Please test.

This patch can fix the oops.

Tested-by: Huang Jianan <huangjianan@oppo.com>

Thanks,
Jianan

> Thanks,
> Miklos
>
> ---
> From: Miklos Szeredi <mszeredi@redhat.com>
> Subject: ovl: fix IOCB_DIRECT if underlying fs doesn't support direct IO
>
> Normally the check at open time suffices, but e.g loop device does set
> IOCB_DIRECT after doing its own checks (which are not sufficent for
> overlayfs).
>
> Make sure we don't call the underlying filesystem read/write method with
> the IOCB_DIRECT if it's not supported.
>
> Reported-by: Huang Jianan <huangjianan@oppo.com>
> Fixes: 16914e6fc7e1 ("ovl: add ovl_read_iter()")
> Cc: <stable@vger.kernel.org> # v4.19
> Signed-off-by: Miklos Szeredi <mszeredi@redhat.com>
> ---
>   fs/overlayfs/file.c |   15 ++++++++++++++-
>   1 file changed, 14 insertions(+), 1 deletion(-)
>
> --- a/fs/overlayfs/file.c
> +++ b/fs/overlayfs/file.c
> @@ -296,6 +296,12 @@ static ssize_t ovl_read_iter(struct kioc
>   	if (ret)
>   		return ret;
>   
> +	ret = -EINVAL;
> +	if (iocb->ki_flags & IOCB_DIRECT &&
> +	    (!real.file->f_mapping->a_ops ||
> +	     !real.file->f_mapping->a_ops->direct_IO))
> +		goto out_fdput;
> +
>   	old_cred = ovl_override_creds(file_inode(file)->i_sb);
>   	if (is_sync_kiocb(iocb)) {
>   		ret = vfs_iter_read(real.file, iter, &iocb->ki_pos,
> @@ -320,7 +326,7 @@ static ssize_t ovl_read_iter(struct kioc
>   out:
>   	revert_creds(old_cred);
>   	ovl_file_accessed(file);
> -
> +out_fdput:
>   	fdput(real);
>   
>   	return ret;
> @@ -349,6 +355,12 @@ static ssize_t ovl_write_iter(struct kio
>   	if (ret)
>   		goto out_unlock;
>   
> +	ret = -EINVAL;
> +	if (iocb->ki_flags & IOCB_DIRECT &&
> +	    (!real.file->f_mapping->a_ops ||
> +	     !real.file->f_mapping->a_ops->direct_IO))
> +		goto out_fdput;
> +
>   	if (!ovl_should_sync(OVL_FS(inode->i_sb)))
>   		ifl &= ~(IOCB_DSYNC | IOCB_SYNC);
>   
> @@ -384,6 +396,7 @@ static ssize_t ovl_write_iter(struct kio
>   	}
>   out:
>   	revert_creds(old_cred);
> +out_fdput:
>   	fdput(real);
>   
>   out_unlock:


  reply	other threads:[~2021-09-28  7:01 UTC|newest]

Thread overview: 28+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-09-18 12:13 [PATCH] ovl: fix null pointer when filesystem doesn't support direct IO Huang Jianan
2021-09-18 12:13 ` Huang Jianan via Linux-erofs
2021-09-22  1:56 ` Chengguang Xu
2021-09-22  1:56   ` Chengguang Xu
2021-09-22  3:39   ` Huang Jianan
2021-09-22  3:39     ` Huang Jianan via Linux-erofs
2021-09-22  3:47 ` [PATCH v2] " Huang Jianan
2021-09-22  3:47   ` Huang Jianan via Linux-erofs
2021-09-22  5:09   ` Chengguang Xu
2021-09-22  5:09     ` Chengguang Xu
2021-09-22  7:18     ` Huang Jianan
2021-09-22  7:18       ` Huang Jianan via Linux-erofs
2021-09-22  7:23       ` [PATCH v3] " Huang Jianan
2021-09-22  7:23         ` Huang Jianan via Linux-erofs
2021-09-22  8:06         ` Chengguang Xu
2021-09-22  8:06           ` Chengguang Xu
2021-09-22  8:24           ` Huang Jianan
2021-09-22  8:24             ` Huang Jianan via Linux-erofs
2021-09-22 13:20             ` [PATCH v3] ovl: fix null pointer when filesystemdoesn'tsupportdirect IO Chengguang Xu
2021-09-22 13:20               ` Chengguang Xu
2021-09-22 14:00               ` Miklos Szeredi
2021-09-22 14:00                 ` Miklos Szeredi
2021-09-27  9:38                 ` Miklos Szeredi
2021-09-27  9:38                   ` Miklos Szeredi
2021-09-28  7:01                   ` Huang Jianan [this message]
2021-09-28  7:01                     ` Huang Jianan via Linux-erofs
2021-09-28  7:17                     ` Miklos Szeredi
2021-09-28  7:17                       ` Miklos Szeredi

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=97977a2c-28d5-1324-fb1e-3e23ab4b1340@oppo.com \
    --to=huangjianan@oppo.com \
    --cc=cgxu519@139.com \
    --cc=cgxu519@mykernel.net \
    --cc=chao@kernel.org \
    --cc=guanyuwei@oppo.com \
    --cc=guoweichao@oppo.com \
    --cc=jnhuang95@gmail.com \
    --cc=linux-erofs@lists.ozlabs.org \
    --cc=linux-fsdevel@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-unionfs@vger.kernel.org \
    --cc=miklos@szeredi.hu \
    --cc=xiang@kernel.org \
    --cc=yh@oppo.com \
    --cc=zhangshiming@oppo.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 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.