linux-unionfs.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Christian Brauner <brauner@kernel.org>
To: linux-unionfs@vger.kernel.org
Cc: Miklos Szeredi <miklos@szeredi.hu>,
	Amir Goldstein <amir73il@gmail.com>,
	 Mike Baynton <mike@mbaynton.com>,
	linux-fsdevel@vger.kernel.org,
	 Christian Brauner <brauner@kernel.org>
Subject: [PATCH 1/2] fs: support O_PATH fds with FSCONFIG_SET_FD
Date: Fri, 07 Feb 2025 16:46:39 +0100	[thread overview]
Message-ID: <20250207-work-overlayfs-v1-1-611976e73373@kernel.org> (raw)
In-Reply-To: <20250207-work-overlayfs-v1-0-611976e73373@kernel.org>

Let FSCONFIG_SET_FD handle O_PATH file descriptors. This is particularly
useful in the context of overlayfs where layers can be specified via
file descriptors instead of paths. But userspace must currently use
non-O_PATH file desriptors which is often pointless especially if
the file descriptors have been created via open_tree(OPEN_TREE_CLONE).

Signed-off-by: Christian Brauner <brauner@kernel.org>
---
 fs/fs_parser.c             | 12 +++++++-----
 fs/fsopen.c                |  7 +++++--
 fs/overlayfs/params.c      | 10 ++++++----
 include/linux/fs_context.h |  1 +
 include/linux/fs_parser.h  |  6 +++---
 5 files changed, 22 insertions(+), 14 deletions(-)

diff --git a/fs/fs_parser.c b/fs/fs_parser.c
index e635a81e17d9..35aaea224007 100644
--- a/fs/fs_parser.c
+++ b/fs/fs_parser.c
@@ -310,15 +310,17 @@ int fs_param_is_fd(struct p_log *log, const struct fs_parameter_spec *p,
 }
 EXPORT_SYMBOL(fs_param_is_fd);
 
-int fs_param_is_file_or_string(struct p_log *log,
-			       const struct fs_parameter_spec *p,
-			       struct fs_parameter *param,
-			       struct fs_parse_result *result)
+int fs_param_is_raw_file_or_string(struct p_log *log,
+				   const struct fs_parameter_spec *p,
+				   struct fs_parameter *param,
+				   struct fs_parse_result *result)
 {
 	switch (param->type) {
 	case fs_value_is_string:
 		return fs_param_is_string(log, p, param, result);
 	case fs_value_is_file:
+		fallthrough;
+	case fs_value_is_raw_file:
 		result->uint_32 = param->dirfd;
 		if (result->uint_32 <= INT_MAX)
 			return 0;
@@ -328,7 +330,7 @@ int fs_param_is_file_or_string(struct p_log *log,
 	}
 	return fs_param_bad_value(log, param);
 }
-EXPORT_SYMBOL(fs_param_is_file_or_string);
+EXPORT_SYMBOL(fs_param_is_raw_file_or_string);
 
 int fs_param_is_uid(struct p_log *log, const struct fs_parameter_spec *p,
 		    struct fs_parameter *param, struct fs_parse_result *result)
diff --git a/fs/fsopen.c b/fs/fsopen.c
index 094a7f510edf..3b5fc9f1f774 100644
--- a/fs/fsopen.c
+++ b/fs/fsopen.c
@@ -451,11 +451,14 @@ SYSCALL_DEFINE5(fsconfig,
 		param.size = strlen(param.name->name);
 		break;
 	case FSCONFIG_SET_FD:
-		param.type = fs_value_is_file;
 		ret = -EBADF;
-		param.file = fget(aux);
+		param.file = fget_raw(aux);
 		if (!param.file)
 			goto out_key;
+		if (param.file->f_mode & FMODE_PATH)
+			param.type = fs_value_is_raw_file;
+		else
+			param.type = fs_value_is_file;
 		param.dirfd = aux;
 		break;
 	default:
diff --git a/fs/overlayfs/params.c b/fs/overlayfs/params.c
index 1115c22deca0..846afa6081a5 100644
--- a/fs/overlayfs/params.c
+++ b/fs/overlayfs/params.c
@@ -141,10 +141,10 @@ static int ovl_verity_mode_def(void)
 
 const struct fs_parameter_spec ovl_parameter_spec[] = {
 	fsparam_string_empty("lowerdir",    Opt_lowerdir),
-	fsparam_file_or_string("lowerdir+", Opt_lowerdir_add),
-	fsparam_file_or_string("datadir+",  Opt_datadir_add),
-	fsparam_file_or_string("upperdir",  Opt_upperdir),
-	fsparam_file_or_string("workdir",   Opt_workdir),
+	fsparam_raw_file_or_string("lowerdir+", Opt_lowerdir_add),
+	fsparam_raw_file_or_string("datadir+",  Opt_datadir_add),
+	fsparam_raw_file_or_string("upperdir",  Opt_upperdir),
+	fsparam_raw_file_or_string("workdir",   Opt_workdir),
 	fsparam_flag("default_permissions", Opt_default_permissions),
 	fsparam_enum("redirect_dir",        Opt_redirect_dir, ovl_parameter_redirect_dir),
 	fsparam_enum("index",               Opt_index, ovl_parameter_bool),
@@ -438,6 +438,8 @@ static int ovl_parse_layer(struct fs_context *fc, struct fs_parameter *param,
 			return err;
 		err = ovl_do_parse_layer(fc, param->string, &layer_path, layer);
 		break;
+	case fs_value_is_raw_file:
+		fallthrough;
 	case fs_value_is_file: {
 		char *buf __free(kfree);
 		char *layer_name;
diff --git a/include/linux/fs_context.h b/include/linux/fs_context.h
index 4b4bfef6f053..4ba18211046e 100644
--- a/include/linux/fs_context.h
+++ b/include/linux/fs_context.h
@@ -55,6 +55,7 @@ enum fs_value_type {
 	fs_value_is_blob,		/* Value is a binary blob */
 	fs_value_is_filename,		/* Value is a filename* + dirfd */
 	fs_value_is_file,		/* Value is a file* */
+	fs_value_is_raw_file,		/* Value is an O_PATH/FMODE_PATH file* */
 };
 
 /*
diff --git a/include/linux/fs_parser.h b/include/linux/fs_parser.h
index 53e566efd5fd..77d5d3c78d39 100644
--- a/include/linux/fs_parser.h
+++ b/include/linux/fs_parser.h
@@ -29,7 +29,7 @@ typedef int fs_param_type(struct p_log *,
 fs_param_type fs_param_is_bool, fs_param_is_u32, fs_param_is_s32, fs_param_is_u64,
 	fs_param_is_enum, fs_param_is_string, fs_param_is_blob, fs_param_is_blockdev,
 	fs_param_is_path, fs_param_is_fd, fs_param_is_uid, fs_param_is_gid,
-	fs_param_is_file_or_string;
+	fs_param_is_raw_file_or_string;
 
 /*
  * Specification of the type of value a parameter wants.
@@ -136,8 +136,8 @@ static inline bool fs_validate_description(const char *name,
 #define fsparam_bdev(NAME, OPT)	__fsparam(fs_param_is_blockdev, NAME, OPT, 0, NULL)
 #define fsparam_path(NAME, OPT)	__fsparam(fs_param_is_path, NAME, OPT, 0, NULL)
 #define fsparam_fd(NAME, OPT)	__fsparam(fs_param_is_fd, NAME, OPT, 0, NULL)
-#define fsparam_file_or_string(NAME, OPT) \
-				__fsparam(fs_param_is_file_or_string, NAME, OPT, 0, NULL)
+#define fsparam_raw_file_or_string(NAME, OPT) \
+				__fsparam(fs_param_is_raw_file_or_string, NAME, OPT, 0, NULL)
 #define fsparam_uid(NAME, OPT) __fsparam(fs_param_is_uid, NAME, OPT, 0, NULL)
 #define fsparam_gid(NAME, OPT) __fsparam(fs_param_is_gid, NAME, OPT, 0, NULL)
 

-- 
2.47.2


  reply	other threads:[~2025-02-07 15:46 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-02-07 15:46 [PATCH 0/2] ovl: allow O_PATH file descriptor when specifying layers Christian Brauner
2025-02-07 15:46 ` Christian Brauner [this message]
2025-02-07 17:39   ` [PATCH 1/2] fs: support O_PATH fds with FSCONFIG_SET_FD Amir Goldstein
2025-02-07 18:09     ` Amir Goldstein
2025-02-10 12:07       ` Christian Brauner
2025-02-07 15:46 ` [PATCH 2/2] selftests/overlayfs: test specifying layers as O_PATH file descriptors Christian Brauner
2025-02-07 18:07   ` Amir Goldstein

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=20250207-work-overlayfs-v1-1-611976e73373@kernel.org \
    --to=brauner@kernel.org \
    --cc=amir73il@gmail.com \
    --cc=linux-fsdevel@vger.kernel.org \
    --cc=linux-unionfs@vger.kernel.org \
    --cc=mike@mbaynton.com \
    --cc=miklos@szeredi.hu \
    /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).