From: Amir Goldstein <amir73il@gmail.com>
To: Miklos Szeredi <miklos@szeredi.hu>
Cc: Al Viro <viro@zeniv.linux.org.uk>, Eryu Guan <guaneryu@gmail.com>,
linux-unionfs@vger.kernel.org, linux-fsdevel@vger.kernel.org
Subject: [PATCH] vfs: fix FIGETBSZ ioctl on an overlayfs file
Date: Thu, 11 Oct 2018 14:24:01 +0300 [thread overview]
Message-ID: <20181011112401.5790-1-amir73il@gmail.com> (raw)
Implement the FIGETBSZ query with the statfs(2) filesystem
interface. Reading inode->i_sb->s_blocksize directly is incorrect
on stacked filesystems (i.e. overlayfs).
This fixes a Floating point exception in e2fsprogs utility filefrag,
which divides the size of the file with the value returned by FIGETBSZ.
Fixes: d1d04ef8572b ("ovl: stack file ops")
Signed-off-by: Amir Goldstein <amir73il@gmail.com>
---
Miklos,
Consider this for-rc8?
There is another trivial kfree(ERR_PTR()) fix I posted yesterday.
xfstests actually has coverage for FIGETBSZ with fiemap-tester
program. However, the tests that use fiemap-tester (generic/094
generic/225) did not fail on v4.19-rc1, but rather thier runtime
dropped from > 10s to 0s, so I'll need to go fix those tests.
Thanks,
Amir.
fs/ioctl.c | 15 ++++++++++++++-
1 file changed, 14 insertions(+), 1 deletion(-)
diff --git a/fs/ioctl.c b/fs/ioctl.c
index 2005529af560..a0e55a8e94fd 100644
--- a/fs/ioctl.c
+++ b/fs/ioctl.c
@@ -17,6 +17,7 @@
#include <linux/buffer_head.h>
#include <linux/falloc.h>
#include <linux/sched/signal.h>
+#include <linux/statfs.h>
#include "internal.h"
@@ -219,6 +220,18 @@ static int ioctl_fiemap(struct file *filp, unsigned long arg)
return error;
}
+static int ioctl_getbsize(struct file *file, int __user *argp)
+{
+ struct kstatfs buf;
+ int err;
+
+ err = vfs_statfs(&file->f_path, &buf);
+ if (err)
+ return err;
+
+ return put_user(buf.f_bsize, argp);
+}
+
static long ioctl_file_clone(struct file *dst_file, unsigned long srcfd,
u64 off, u64 olen, u64 destoff)
{
@@ -669,7 +682,7 @@ int do_vfs_ioctl(struct file *filp, unsigned int fd, unsigned int cmd,
return ioctl_fiemap(filp, arg);
case FIGETBSZ:
- return put_user(inode->i_sb->s_blocksize, argp);
+ return ioctl_getbsize(filp, argp);
case FICLONE:
return ioctl_file_clone(filp, arg, 0, 0, 0);
--
2.17.1
next reply other threads:[~2018-10-11 18:50 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2018-10-11 11:24 Amir Goldstein [this message]
2018-10-11 12:25 ` [PATCH] vfs: fix FIGETBSZ ioctl on an overlayfs file Miklos Szeredi
2018-10-11 12:47 ` Amir Goldstein
2018-10-11 13:16 ` 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=20181011112401.5790-1-amir73il@gmail.com \
--to=amir73il@gmail.com \
--cc=guaneryu@gmail.com \
--cc=linux-fsdevel@vger.kernel.org \
--cc=linux-unionfs@vger.kernel.org \
--cc=miklos@szeredi.hu \
--cc=viro@zeniv.linux.org.uk \
/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).