From: Christian Brauner <brauner@kernel.org>
To: Jeff Layton <jlayton@kernel.org>,
Chuck Lever <chuck.lever@oracle.com>, Jan Kara <jack@suse.cz>,
Amir Goldstein <amir73il@gmail.com>,
Simona Vetter <simona@ffwll.ch>
Cc: linux-fsdevel@vger.kernel.org, linux-nfs@vger.kernel.org,
Christian Brauner <brauner@kernel.org>
Subject: [PATCH 2/9] fhandle: hoist copy_from_user() above get_path_from_fd()
Date: Mon, 23 Jun 2025 11:01:24 +0200 [thread overview]
Message-ID: <20250623-work-pidfs-fhandle-v1-2-75899d67555f@kernel.org> (raw)
In-Reply-To: <20250623-work-pidfs-fhandle-v1-0-75899d67555f@kernel.org>
In follow-up patches we need access to @file_handle->handle_type
before we start caring about get_path_from_fd().
Signed-off-by: Christian Brauner <brauner@kernel.org>
---
fs/fhandle.c | 35 ++++++++++++++---------------------
1 file changed, 14 insertions(+), 21 deletions(-)
diff --git a/fs/fhandle.c b/fs/fhandle.c
index 66ff60591d17..73f56f8e7d5d 100644
--- a/fs/fhandle.c
+++ b/fs/fhandle.c
@@ -323,13 +323,24 @@ static int handle_to_path(int mountdirfd, struct file_handle __user *ufh,
{
int retval = 0;
struct file_handle f_handle;
- struct file_handle *handle = NULL;
+ struct file_handle *handle __free(kfree) = NULL;
struct handle_to_path_ctx ctx = {};
const struct export_operations *eops;
+ if (copy_from_user(&f_handle, ufh, sizeof(struct file_handle)))
+ return -EFAULT;
+
+ if ((f_handle.handle_bytes > MAX_HANDLE_SZ) ||
+ (f_handle.handle_bytes == 0))
+ return -EINVAL;
+
+ if (f_handle.handle_type < 0 ||
+ FILEID_USER_FLAGS(f_handle.handle_type) & ~FILEID_VALID_USER_FLAGS)
+ return -EINVAL;
+
retval = get_path_from_fd(mountdirfd, &ctx.root);
if (retval)
- goto out_err;
+ return retval;
eops = ctx.root.mnt->mnt_sb->s_export_op;
if (eops && eops->permission)
@@ -339,21 +350,6 @@ static int handle_to_path(int mountdirfd, struct file_handle __user *ufh,
if (retval)
goto out_path;
- if (copy_from_user(&f_handle, ufh, sizeof(struct file_handle))) {
- retval = -EFAULT;
- goto out_path;
- }
- if ((f_handle.handle_bytes > MAX_HANDLE_SZ) ||
- (f_handle.handle_bytes == 0)) {
- retval = -EINVAL;
- goto out_path;
- }
- if (f_handle.handle_type < 0 ||
- FILEID_USER_FLAGS(f_handle.handle_type) & ~FILEID_VALID_USER_FLAGS) {
- retval = -EINVAL;
- goto out_path;
- }
-
handle = kmalloc(struct_size(handle, f_handle, f_handle.handle_bytes),
GFP_KERNEL);
if (!handle) {
@@ -366,7 +362,7 @@ static int handle_to_path(int mountdirfd, struct file_handle __user *ufh,
&ufh->f_handle,
f_handle.handle_bytes)) {
retval = -EFAULT;
- goto out_handle;
+ goto out_path;
}
/*
@@ -384,11 +380,8 @@ static int handle_to_path(int mountdirfd, struct file_handle __user *ufh,
handle->handle_type &= ~FILEID_USER_FLAGS_MASK;
retval = do_handle_to_path(handle, path, &ctx);
-out_handle:
- kfree(handle);
out_path:
path_put(&ctx.root);
-out_err:
return retval;
}
--
2.47.2
next prev parent reply other threads:[~2025-06-23 9:01 UTC|newest]
Thread overview: 33+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-06-23 9:01 [PATCH 0/9] fhandle, pidfs: allow open_by_handle_at() purely based on file handle Christian Brauner
2025-06-23 9:01 ` [PATCH 1/9] fhandle: raise FILEID_IS_DIR in handle_type Christian Brauner
2025-06-23 11:31 ` Jan Kara
2025-06-23 9:01 ` Christian Brauner [this message]
2025-06-23 11:33 ` [PATCH 2/9] fhandle: hoist copy_from_user() above get_path_from_fd() Jan Kara
2025-06-23 9:01 ` [PATCH 3/9] fhandle: rename to get_path_anchor() Christian Brauner
2025-06-23 11:34 ` Jan Kara
2025-06-23 9:01 ` [PATCH 4/9] pidfs: add pidfs_root_path() helper Christian Brauner
2025-06-23 11:46 ` Jan Kara
2025-06-23 9:01 ` [PATCH 5/9] fhandle: reflow get_path_anchor() Christian Brauner
2025-06-23 11:39 ` Jan Kara
2025-06-23 9:01 ` [PATCH 6/9] exportfs: add FILEID_PIDFS Christian Brauner
2025-06-23 11:55 ` Jan Kara
2025-06-23 11:58 ` Christian Brauner
2025-06-23 12:22 ` Amir Goldstein
2025-06-23 12:41 ` Jan Kara
2025-06-23 13:05 ` Amir Goldstein
2025-06-23 13:18 ` Jan Kara
2025-06-23 14:05 ` Amir Goldstein
2025-06-23 19:17 ` Christian Brauner
2025-06-24 8:25 ` Christian Brauner
2025-06-23 9:01 ` [PATCH 7/9] fhandle: add EXPORT_OP_AUTONOMOUS_HANDLES marker Christian Brauner
2025-06-23 11:58 ` Jan Kara
2025-06-23 12:37 ` Amir Goldstein
2025-06-23 9:01 ` [PATCH 8/9] fhandle, pidfs: support open_by_handle_at() purely based on file handle Christian Brauner
2025-06-23 12:06 ` Jan Kara
2025-06-23 12:25 ` Christian Brauner
2025-06-23 12:54 ` Amir Goldstein
2025-06-23 13:00 ` Christian Brauner
2025-06-23 13:21 ` Jan Kara
2025-06-23 14:00 ` Amir Goldstein
2025-06-23 13:29 ` Jan Kara
2025-06-23 9:01 ` [PATCH 9/9] selftests/pidfd: decode pidfd file handles withou having to specify an fd Christian Brauner
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=20250623-work-pidfs-fhandle-v1-2-75899d67555f@kernel.org \
--to=brauner@kernel.org \
--cc=amir73il@gmail.com \
--cc=chuck.lever@oracle.com \
--cc=jack@suse.cz \
--cc=jlayton@kernel.org \
--cc=linux-fsdevel@vger.kernel.org \
--cc=linux-nfs@vger.kernel.org \
--cc=simona@ffwll.ch \
/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).