From: Miklos Szeredi <miklos@szeredi.hu>
To: Huang Jianan <huangjianan@oppo.com>
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: Mon, 27 Sep 2021 11:38:58 +0200 [thread overview]
Message-ID: <YVGRMoRTH4oJpxWZ@miu.piliscsaba.redhat.com> (raw)
In-Reply-To: <CAJfpegs_T5BQ+e79T=1fqTScjfaOyAftykmzK6=hdS=WhVvWsg@mail.gmail.com>
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.
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:
next prev parent reply other threads:[~2021-09-27 9:39 UTC|newest]
Thread overview: 14+ 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-22 1:56 ` Chengguang Xu
2021-09-22 3:39 ` Huang Jianan
2021-09-22 3:47 ` [PATCH v2] " Huang Jianan
2021-09-22 5:09 ` Chengguang Xu
2021-09-22 7:18 ` Huang Jianan
2021-09-22 7:23 ` [PATCH v3] " Huang Jianan
2021-09-22 8:06 ` Chengguang Xu
2021-09-22 8:24 ` Huang Jianan
2021-09-22 13:20 ` [PATCH v3] ovl: fix null pointer when filesystemdoesn'tsupportdirect IO Chengguang Xu
2021-09-22 14:00 ` Miklos Szeredi
2021-09-27 9:38 ` Miklos Szeredi [this message]
2021-09-28 7:01 ` Huang Jianan
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=YVGRMoRTH4oJpxWZ@miu.piliscsaba.redhat.com \
--to=miklos@szeredi.hu \
--cc=cgxu519@139.com \
--cc=cgxu519@mykernel.net \
--cc=chao@kernel.org \
--cc=guanyuwei@oppo.com \
--cc=guoweichao@oppo.com \
--cc=huangjianan@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=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 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).