From: NeilBrown <neilb@suse.com>
To: Linus Torvalds <torvalds@linux-foundation.org>,
Al Viro <viro@zeniv.linux.org.uk>
Cc: linux-fsdevel@vger.kernel.org, linux-nfs@vger.kernel.org,
Amir Goldstein <amir73il@gmail.com>,
lkml <linux-kernel@vger.kernel.org>,
Lennart Poettering <lennart@poettering.net>
Subject: [PATCH 4/4] fhandle: Improve error responses in name_to_handle_at()
Date: Mon, 11 Dec 2017 17:04:05 +1100 [thread overview]
Message-ID: <151297224523.7818.12267549679803980398.stgit@noble> (raw)
In-Reply-To: <151297214390.7818.7216826079527521005.stgit@noble>
1/ Always return the mnt_id, even if some other error occurs.
It can be useful without the file handle.
An application can initialise the memory to, e.g. -1
and if there is some other value after name_to_handle_at()
returns, then it is a valid mnt_id.
If the value is unchanged, then the kernel does not
have this patch.
2/ Don't return -EINVAL if the requested handle_bytes is
larger than MAX_HANDLE_SZ. There is no need for an
error and it causes unnecessary behavior change
in the kernel ever needs to increase MAX_HANDLE_SZ.
Simple limit handle_bytes to MAX_HANDLE_SZ silently.
Signed-off-by: NeilBrown <neilb@suse.com>
---
fs/fhandle.c | 16 ++++++++++------
1 file changed, 10 insertions(+), 6 deletions(-)
diff --git a/fs/fhandle.c b/fs/fhandle.c
index 0ace128f5d23..04afffaeb742 100644
--- a/fs/fhandle.c
+++ b/fs/fhandle.c
@@ -23,9 +23,16 @@ static long do_sys_name_to_handle(struct path *path,
int handle_dwords, handle_bytes;
struct file_handle *handle = NULL;
+ /*
+ * Always return the mnt_id, it might be useful even
+ * without the file handle
+ */
+ if (copy_to_user(mnt_id, &real_mount(path->mnt)->mnt_id,
+ sizeof(*mnt_id)))
+ return -EFAULT;
/*
* We need to make sure whether the file system
- * support decoding of the file handle
+ * supports decoding of the file handle.
*/
if (!path->dentry->d_sb->s_export_op ||
!path->dentry->d_sb->s_export_op->fh_to_dentry)
@@ -35,7 +42,7 @@ static long do_sys_name_to_handle(struct path *path,
return -EFAULT;
if (f_handle.handle_bytes > MAX_HANDLE_SZ)
- return -EINVAL;
+ f_handle.handle_bytes = MAX_HANDLE_SZ;
handle = kmalloc(sizeof(struct file_handle) + f_handle.handle_bytes,
GFP_KERNEL);
@@ -68,10 +75,7 @@ static long do_sys_name_to_handle(struct path *path,
retval = -EOVERFLOW;
} else
retval = 0;
- /* copy the mount id */
- if (copy_to_user(mnt_id, &real_mount(path->mnt)->mnt_id,
- sizeof(*mnt_id)) ||
- copy_to_user(ufh, handle,
+ if (copy_to_user(ufh, handle,
sizeof(struct file_handle) + handle_bytes))
retval = -EFAULT;
kfree(handle);
next prev parent reply other threads:[~2017-12-11 6:04 UTC|newest]
Thread overview: 17+ messages / expand[flat|nested] mbox.gz Atom feed top
2017-12-11 6:04 [PATCH 0/4] VFS: fix assorted issues with name_to_handle conversions NeilBrown
2017-12-11 6:04 ` [PATCH 3/4] NFS: allow name_to_handle_at() to work for Amazon EFS NeilBrown
2017-12-11 6:04 ` [PATCH 2/4] fs/notify: don't put file handle buffer on stack NeilBrown
2017-12-11 6:47 ` Amir Goldstein
2017-12-11 6:04 ` [PATCH 1/4] fs/notify: fdinfo can report unsupported file handles NeilBrown
2017-12-11 6:29 ` Al Viro
2017-12-11 22:12 ` NeilBrown
2017-12-11 6:41 ` Amir Goldstein
2017-12-11 7:05 ` Amir Goldstein
2017-12-11 13:46 ` Pavel Emelyanov
2017-12-11 14:08 ` Amir Goldstein
2017-12-11 15:21 ` Pavel Emelyanov
2017-12-11 21:52 ` NeilBrown
2017-12-12 6:39 ` Amir Goldstein
2017-12-13 2:20 ` NeilBrown
2017-12-11 6:04 ` NeilBrown [this message]
2017-12-11 16:08 ` [PATCH 4/4] fhandle: Improve error responses in name_to_handle_at() J. Bruce Fields
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=151297224523.7818.12267549679803980398.stgit@noble \
--to=neilb@suse.com \
--cc=amir73il@gmail.com \
--cc=lennart@poettering.net \
--cc=linux-fsdevel@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-nfs@vger.kernel.org \
--cc=torvalds@linux-foundation.org \
--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 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.