Skip to content

Commit 1bc2f31

Browse files
Miklos Szeredigregkh
authored andcommitted
ovl: fix IOCB_DIRECT if underlying fs doesn't support direct IO
commit 1dc1eed upstream. 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: 16914e6 ("ovl: add ovl_read_iter()") Cc: <stable@vger.kernel.org> # v4.19 Tested-by: Huang Jianan <huangjianan@oppo.com> Signed-off-by: Miklos Szeredi <mszeredi@redhat.com> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
1 parent 9763ffd commit 1bc2f31

1 file changed

Lines changed: 14 additions & 1 deletion

File tree

‎fs/overlayfs/file.c‎

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -301,6 +301,12 @@ static ssize_t ovl_read_iter(struct kiocb *iocb, struct iov_iter *iter)
301301
if (ret)
302302
return ret;
303303

304+
ret = -EINVAL;
305+
if (iocb->ki_flags & IOCB_DIRECT &&
306+
(!real.file->f_mapping->a_ops ||
307+
!real.file->f_mapping->a_ops->direct_IO))
308+
goto out_fdput;
309+
304310
old_cred = ovl_override_creds(file_inode(file)->i_sb);
305311
if (is_sync_kiocb(iocb)) {
306312
ret = vfs_iter_read(real.file, iter, &iocb->ki_pos,
@@ -325,7 +331,7 @@ static ssize_t ovl_read_iter(struct kiocb *iocb, struct iov_iter *iter)
325331
out:
326332
revert_creds(old_cred);
327333
ovl_file_accessed(file);
328-
334+
out_fdput:
329335
fdput(real);
330336

331337
return ret;
@@ -354,6 +360,12 @@ static ssize_t ovl_write_iter(struct kiocb *iocb, struct iov_iter *iter)
354360
if (ret)
355361
goto out_unlock;
356362

363+
ret = -EINVAL;
364+
if (iocb->ki_flags & IOCB_DIRECT &&
365+
(!real.file->f_mapping->a_ops ||
366+
!real.file->f_mapping->a_ops->direct_IO))
367+
goto out_fdput;
368+
357369
if (!ovl_should_sync(OVL_FS(inode->i_sb)))
358370
ifl &= ~(IOCB_DSYNC | IOCB_SYNC);
359371

@@ -389,6 +401,7 @@ static ssize_t ovl_write_iter(struct kiocb *iocb, struct iov_iter *iter)
389401
}
390402
out:
391403
revert_creds(old_cred);
404+
out_fdput:
392405
fdput(real);
393406

394407
out_unlock:

0 commit comments

Comments
 (0)