linux-fsdevel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: NeilBrown <neilb@suse.com>
To: Trond Myklebust <trond.myklebust@primarydata.com>,
	Anna.Schumaker@Netapp.com, Al Viro <viro@zeniv.linux.org.uk>,
	Andrew Morton <akpm@linux-foundation.org>,
	Linus Torvalds <torvalds@linux-foundation.org>
Cc: lkml <linux-kernel@vger.kernel.org>,
	"linux-nfs\@vger.kernel.org" <linux-nfs@vger.kernel.org>,
	linux-fsdevel <linux-fsdevel@vger.kernel.org>,
	Lennart Poettering <lennart@poettering.net>
Subject: [PATCH] fhandle: avoid -EINVAL if requested size is too large.
Date: Mon, 04 Dec 2017 14:27:14 +1100	[thread overview]
Message-ID: <87k1y3tbot.fsf@notabene.neil.brown.name> (raw)
In-Reply-To: <87po7zv62h.fsf@notabene.neil.brown.name>

[-- Attachment #1: Type: text/plain, Size: 1883 bytes --]


Lennart Poettering observes that if the newly increased
MAX_HANDLE_SZ is exported to user space, and then used in an
application running on an old kernel, name_to_handle_at() will
report -EINVAL, which is unhelpful and inconsistent with
the documentation.

So:
 1/ add a comment making it clear that the new value must
    not be exposed to user-space.
 2/ remove the completely unnecessary restriction on the size
    of buffer provided by the application.

Reported-by: Lennart Poettering <lennart@poettering.net>
Signed-off-by: NeilBrown <neilb@suse.com>
---

This is a followup to the previous fhandle-for-Amazon-EFS
patch which adds further refinements.

Thanks,
NeilBrown


 fs/fhandle.c             | 2 +-
 include/linux/exportfs.h | 4 ++++
 2 files changed, 5 insertions(+), 1 deletion(-)

diff --git a/fs/fhandle.c b/fs/fhandle.c
index 0ace128f5d23..30bf1c20e143 100644
--- a/fs/fhandle.c
+++ b/fs/fhandle.c
@@ -35,7 +35,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);
diff --git a/include/linux/exportfs.h b/include/linux/exportfs.h
index e7ab1b071c5e..097704e80c89 100644
--- a/include/linux/exportfs.h
+++ b/include/linux/exportfs.h
@@ -14,6 +14,10 @@ struct vfsmount;
 /* Must be larger than NFSv4 file handle, but small
  * enough for an on-stack allocation. overlayfs doesn't
  * want this too close to 255.
+ * NOTE: This value MUST NOT be exported to user-space.
+ * Applications must only ever see MAX_HANDLE_SZ == 128.
+ * If they try a larger number on older kernels, they
+ * will get -EINVAL which will be confusing.
  */
 #define MAX_HANDLE_SZ 200
 
-- 
2.14.0.rc0.dirty


[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 832 bytes --]

  reply	other threads:[~2017-12-04  3:27 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-11-30 20:56 [PATCH] NFS: allow name_to_handle_at() to work for Amazon EFS NeilBrown
2017-12-04  3:27 ` NeilBrown [this message]
2017-12-06 19:05 ` J. Bruce Fields
2017-12-07  2:07 ` Linus Torvalds
2017-12-07  3:20   ` NeilBrown
2017-12-07  4:04     ` Amir Goldstein
2017-12-08  2:17       ` NeilBrown
2017-12-19 12:42         ` Jan Kara
2017-12-20 21:23           ` NeilBrown
2017-12-07  5:34     ` Matthew Wilcox

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=87k1y3tbot.fsf@notabene.neil.brown.name \
    --to=neilb@suse.com \
    --cc=Anna.Schumaker@Netapp.com \
    --cc=akpm@linux-foundation.org \
    --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=trond.myklebust@primarydata.com \
    --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).