archive mirror
 help / color / mirror / Atom feed
From: Huang Jianan via Linux-erofs <>
Subject: [PATCH] ovl: fix null pointer when filesystem doesn't support direct IO
Date: Sat, 18 Sep 2021 20:13:46 +0800	[thread overview]
Message-ID: <> (raw)

From: Huang Jianan <>

At present, overlayfs provides overlayfs inode to users. Overlayfs
inode provides ovl_aops with noop_direct_IO to avoid open failure
with O_DIRECT. But some compressed filesystems, such as erofs and
squashfs, don't support direct_IO.

Users who use f_mapping->a_ops->direct_IO to check O_DIRECT support,
will read file through this way. This will cause overlayfs to access
a non-existent direct_IO function and cause panic due to null pointer:

Kernel panic - not syncing: CFI failure (target: 0x0)
CPU: 6 PID: 247 Comm: loop0
Call Trace:

The filesystem may only support direct_IO for some file types. For
example, erofs supports direct_IO for uncompressed files. So fall
back to buffered io only when the file doesn't support direct_IO to
fix this problem.

Fixes: 5b910bd615ba ("ovl: fix GPF in swapfile_activate of file from overlayfs over xfs")
Signed-off-by: Huang Jianan <>
 fs/overlayfs/file.c | 4 ++++
 1 file changed, 4 insertions(+)

diff --git a/fs/overlayfs/file.c b/fs/overlayfs/file.c
index d081faa55e83..998c60770b81 100644
--- a/fs/overlayfs/file.c
+++ b/fs/overlayfs/file.c
@@ -296,6 +296,10 @@ static ssize_t ovl_read_iter(struct kiocb *iocb, struct iov_iter *iter)
 	if (ret)
 		return ret;
+	if ((iocb->ki_flags & IOCB_DIRECT) && (!real.file->f_mapping->a_ops ||
+		!real.file->f_mapping->a_ops->direct_IO))
+		iocb->ki_flags &= ~IOCB_DIRECT;
 	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,

             reply	other threads:[~2021-09-18 12:14 UTC|newest]

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

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \ \ \ \ \ \ \ \ \ \ \ \ \

* 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).