mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* [PATCH v2 0/2] fsconfig: minor fsparam_fd fixes
@ 2024-07-31 13:10 Aleksa Sarai
  2024-07-31 13:10 ` [PATCH v2 1/2] autofs: fix missing fput for FSCONFIG_SET_FD Aleksa Sarai
                   ` (2 more replies)
  0 siblings, 3 replies; 4+ messages in thread
From: Aleksa Sarai @ 2024-07-31 13:10 UTC (permalink / raw)
  To: Ian Kent, Bill O'Donnell, Christian Brauner, Jan Harkes,
	coda, Eric Sandeen, David Howells
  Cc: autofs, linux-kernel, codalist, Aleksa Sarai

While working on adding an fsparam_fd() argument to cgroupfs, I noticed
that there are only two users of fsparam_fd() and they both seemed to
have minor issues:

* autofs has a missing fput() when using FSCONFIG_SET_FD.
* coda uses fsparam_fd() but it ignores param->file and so ends up
  re-getting the file. This doesn't change the behaviour but it seems
  preferable to have all users of fsparam_fd() have the same logic.

I have tested this logic for the cgroupfs patch but I have only compile
tested the fixes for autofs and coda.

The second patch is not really required, so feel free to drop it if you
feel the original version was cleaner.

Signed-off-by: Aleksa Sarai <cyphar@cyphar.com>
---
Changes in v2:
- Fix fs/coda/inode.c build errors.
- Link to v1: https://lore.kernel.org/r/20240719-fsconfig-fsparam_fd-fixes-v1-0-7ccd315c2ad4@cyphar.com

---
Aleksa Sarai (2):
      autofs: fix missing fput for FSCONFIG_SET_FD
      coda: use param->file for FSCONFIG_SET_FD

 fs/autofs/inode.c |  3 +--
 fs/coda/inode.c   | 43 ++++++++++++++++++++++++++++++-------------
 2 files changed, 31 insertions(+), 15 deletions(-)
---
base-commit: c7b9563b58a77423d4c6e026ff831a69612b02fc
change-id: 20240714-fsconfig-fsparam_fd-fixes-09f2e741c28d

Best regards,
-- 
Aleksa Sarai <cyphar@cyphar.com>


^ permalink raw reply	[flat|nested] 4+ messages in thread

* [PATCH v2 1/2] autofs: fix missing fput for FSCONFIG_SET_FD
  2024-07-31 13:10 [PATCH v2 0/2] fsconfig: minor fsparam_fd fixes Aleksa Sarai
@ 2024-07-31 13:10 ` Aleksa Sarai
  2024-07-31 13:10 ` [PATCH v2 2/2] coda: use param->file " Aleksa Sarai
  2024-08-01  7:04 ` [PATCH v2 0/2] fsconfig: minor fsparam_fd fixes Christian Brauner
  2 siblings, 0 replies; 4+ messages in thread
From: Aleksa Sarai @ 2024-07-31 13:10 UTC (permalink / raw)
  To: Ian Kent, Bill O'Donnell, Christian Brauner, Jan Harkes,
	coda, Eric Sandeen, David Howells
  Cc: autofs, linux-kernel, codalist, Aleksa Sarai

If you pass an fd using FSCONFIG_SET_FD, autofs_parse_fd() "steals" the
param->file and so the fs_context infrastructure will not do fput() for
us.

Fixes: e6ec453bd0f0 ("autofs: convert autofs to use the new mount api")
Signed-off-by: Aleksa Sarai <cyphar@cyphar.com>
---
 fs/autofs/inode.c | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)

diff --git a/fs/autofs/inode.c b/fs/autofs/inode.c
index cf792d4de4f1..64faa6c51f60 100644
--- a/fs/autofs/inode.c
+++ b/fs/autofs/inode.c
@@ -172,8 +172,7 @@ static int autofs_parse_fd(struct fs_context *fc, struct autofs_sb_info *sbi,
 	ret = autofs_check_pipe(pipe);
 	if (ret < 0) {
 		errorf(fc, "Invalid/unusable pipe");
-		if (param->type != fs_value_is_file)
-			fput(pipe);
+		fput(pipe);
 		return -EBADF;
 	}
 

-- 
2.45.2


^ permalink raw reply	[flat|nested] 4+ messages in thread

* [PATCH v2 2/2] coda: use param->file for FSCONFIG_SET_FD
  2024-07-31 13:10 [PATCH v2 0/2] fsconfig: minor fsparam_fd fixes Aleksa Sarai
  2024-07-31 13:10 ` [PATCH v2 1/2] autofs: fix missing fput for FSCONFIG_SET_FD Aleksa Sarai
@ 2024-07-31 13:10 ` Aleksa Sarai
  2024-08-01  7:04 ` [PATCH v2 0/2] fsconfig: minor fsparam_fd fixes Christian Brauner
  2 siblings, 0 replies; 4+ messages in thread
From: Aleksa Sarai @ 2024-07-31 13:10 UTC (permalink / raw)
  To: Ian Kent, Bill O'Donnell, Christian Brauner, Jan Harkes,
	coda, Eric Sandeen, David Howells
  Cc: autofs, linux-kernel, codalist, Aleksa Sarai

While the old code did support FSCONFIG_SET_FD, there's no need to
re-get the file the fs_context infrastructure already grabbed for us.

Signed-off-by: Aleksa Sarai <cyphar@cyphar.com>
---
 fs/coda/inode.c | 43 ++++++++++++++++++++++++++++++-------------
 1 file changed, 30 insertions(+), 13 deletions(-)

diff --git a/fs/coda/inode.c b/fs/coda/inode.c
index 6898dc621011..6896fce122e1 100644
--- a/fs/coda/inode.c
+++ b/fs/coda/inode.c
@@ -119,31 +119,43 @@ static const struct fs_parameter_spec coda_param_specs[] = {
 	{}
 };
 
-static int coda_parse_fd(struct fs_context *fc, int fd)
+static int coda_set_idx(struct fs_context *fc, struct file *file)
 {
 	struct coda_fs_context *ctx = fc->fs_private;
-	struct fd f;
 	struct inode *inode;
 	int idx;
 
-	f = fdget(fd);
-	if (!f.file)
-		return -EBADF;
-	inode = file_inode(f.file);
+	inode = file_inode(file);
 	if (!S_ISCHR(inode->i_mode) || imajor(inode) != CODA_PSDEV_MAJOR) {
-		fdput(f);
-		return invalf(fc, "code: Not coda psdev");
+		return invalf(fc, "coda: Not coda psdev");
 	}
-
 	idx = iminor(inode);
-	fdput(f);
-
 	if (idx < 0 || idx >= MAX_CODADEVS)
 		return invalf(fc, "coda: Bad minor number");
 	ctx->idx = idx;
 	return 0;
 }
 
+static int coda_parse_fd(struct fs_context *fc, struct fs_parameter *param,
+			 struct fs_parse_result *result)
+{
+	struct file *file;
+	int err;
+
+	if (param->type == fs_value_is_file) {
+		file = param->file;
+		param->file = NULL;
+	} else {
+		file = fget(result->uint_32);
+	}
+	if (!file)
+		return -EBADF;
+
+	err = coda_set_idx(fc, file);
+	fput(file);
+	return err;
+}
+
 static int coda_parse_param(struct fs_context *fc, struct fs_parameter *param)
 {
 	struct fs_parse_result result;
@@ -155,7 +167,7 @@ static int coda_parse_param(struct fs_context *fc, struct fs_parameter *param)
 
 	switch (opt) {
 	case Opt_fd:
-		return coda_parse_fd(fc, result.uint_32);
+		return coda_parse_fd(fc, param, &result);
 	}
 
 	return 0;
@@ -167,6 +179,7 @@ static int coda_parse_param(struct fs_context *fc, struct fs_parameter *param)
  */
 static int coda_parse_monolithic(struct fs_context *fc, void *_data)
 {
+	struct file *file;
 	struct coda_mount_data *data = _data;
 
 	if (!data)
@@ -175,7 +188,11 @@ static int coda_parse_monolithic(struct fs_context *fc, void *_data)
 	if (data->version != CODA_MOUNT_VERSION)
 		return invalf(fc, "coda: Bad mount version");
 
-	coda_parse_fd(fc, data->fd);
+	file = fget(data->fd);
+	if (file) {
+		coda_set_idx(fc, file);
+		fput(file);
+	}
 	return 0;
 }
 

-- 
2.45.2


^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH v2 0/2] fsconfig: minor fsparam_fd fixes
  2024-07-31 13:10 [PATCH v2 0/2] fsconfig: minor fsparam_fd fixes Aleksa Sarai
  2024-07-31 13:10 ` [PATCH v2 1/2] autofs: fix missing fput for FSCONFIG_SET_FD Aleksa Sarai
  2024-07-31 13:10 ` [PATCH v2 2/2] coda: use param->file " Aleksa Sarai
@ 2024-08-01  7:04 ` Christian Brauner
  2 siblings, 0 replies; 4+ messages in thread
From: Christian Brauner @ 2024-08-01  7:04 UTC (permalink / raw)
  To: Aleksa Sarai
  Cc: Christian Brauner, autofs, linux-kernel, codalist, Ian Kent,
	Bill O'Donnell, Jan Harkes, coda, Eric Sandeen,
	David Howells

On Wed, 31 Jul 2024 23:10:26 +1000, Aleksa Sarai wrote:
> While working on adding an fsparam_fd() argument to cgroupfs, I noticed
> that there are only two users of fsparam_fd() and they both seemed to
> have minor issues:
> 
> * autofs has a missing fput() when using FSCONFIG_SET_FD.
> * coda uses fsparam_fd() but it ignores param->file and so ends up
>   re-getting the file. This doesn't change the behaviour but it seems
>   preferable to have all users of fsparam_fd() have the same logic.
> 
> [...]

Applied to the vfs.misc branch of the vfs/vfs.git tree.
Patches in the vfs.misc branch should appear in linux-next soon.

Please report any outstanding bugs that were missed during review in a
new review to the original patch series allowing us to drop it.

It's encouraged to provide Acked-bys and Reviewed-bys even though the
patch has now been applied. If possible patch trailers will be updated.

Note that commit hashes shown below are subject to change due to rebase,
trailer updates or similar. If in doubt, please check the listed branch.

tree:   https://git.kernel.org/pub/scm/linux/kernel/git/vfs/vfs.git
branch: vfs.misc

[1/2] autofs: fix missing fput for FSCONFIG_SET_FD
      https://git.kernel.org/vfs/vfs/c/9f6b314ecc8b
[2/2] coda: use param->file for FSCONFIG_SET_FD
      https://git.kernel.org/vfs/vfs/c/b0839e9bbc5b

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2024-08-01  7:05 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2024-07-31 13:10 [PATCH v2 0/2] fsconfig: minor fsparam_fd fixes Aleksa Sarai
2024-07-31 13:10 ` [PATCH v2 1/2] autofs: fix missing fput for FSCONFIG_SET_FD Aleksa Sarai
2024-07-31 13:10 ` [PATCH v2 2/2] coda: use param->file " Aleksa Sarai
2024-08-01  7:04 ` [PATCH v2 0/2] fsconfig: minor fsparam_fd fixes Christian Brauner

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®