Skip to contentSkip to conversation

fuse: use ->reconfigure() instead of ->remount_fs()

PATCH In review Miklos Szeredi 3 participants 5 messages Jul 10, 2020 – Jul 20, 2020

Subsystems (3)
lore
Share & tools
lore
#0 lore raw

PATCH 1/3 fuse: use ->reconfigure() instead of ->remount_fs()

s_op->remount_fs() is only called from legacy_reconfigure(), which is not used after being converted to the new API.

Convert to using ->reconfigure(). This restores the previous behavior of syncing the filesystem and rejecting MS_MANDLOCK on remount.

Fixes c30da2e981a7 ("fuse: convert to use the new mount API")
Cc <[email protected]> # v5.4
---
 fs/fuse/inode.c | 8 +++++---
 1 file changed, 5 insertions(+), 3 deletions(-)
fs/fuse/inode.c +5 -3
index 5b4aebf5821f..be39dff57c28 100644
@@ -121,10 +121,12 @@ static void fuse_evict_inode(struct inode *inode)
 	}
 }
 
-static int fuse_remount_fs(struct super_block *sb, int *flags, char *data)
+static int fuse_reconfigure(struct fs_context *fc)
 {
+	struct super_block *sb = fc->root->d_sb;
+
 	sync_filesystem(sb);
-	if (*flags & SB_MANDLOCK)
+	if (fc->sb_flags & SB_MANDLOCK)
 		return -EINVAL;
 
 	return 0;
@@ -817,7 +819,6 @@ static const struct super_operations fuse_super_operations = {
 	.evict_inode	= fuse_evict_inode,
 	.write_inode	= fuse_write_inode,
 	.drop_inode	= generic_delete_inode,
-	.remount_fs	= fuse_remount_fs,
 	.put_super	= fuse_put_super,
 	.umount_begin	= fuse_umount_begin,
 	.statfs		= fuse_statfs,
@@ -1296,6 +1297,7 @@ static int fuse_get_tree(struct fs_context *fc)
 static const struct fs_context_operations fuse_context_ops = {
 	.free		= fuse_free_fc,
 	.parse_param	= fuse_parse_param,
+	.reconfigure	= fuse_reconfigure,
 	.get_tree	= fuse_get_tree,
 };
 
Signature · 1 line
2.21.1
#1 lore raw

PATCH 2/3 fuse: ignore 'data' argument of mount(..., MS_REMOUNT)

The command

mount -o remount -o unknownoption /mnt/fuse

succeeds on kernel versions prior to v5.4 and fails on kernel version at or after. This is because fuse_parse_param() rejects any unrecognised options in case of FS_CONTEXT_FOR_RECONFIGURE, just as for FS_CONTEXT_FOR_MOUNT.

This causes a regression in case the fuse filesystem is in fstab, since remount sends all options found there to the kernel; even ones that are meant for the initial mount and are consumed by the userspace fuse server.

Fix this by ignoring mount options, just as fuse_remount_fs() did prior to the conversion to the new API.

Fixes c30da2e981a7 ("fuse: convert to use the new mount API")
Cc <[email protected]> # v5.4
---
 fs/fuse/inode.c | 7 +++++++
 1 file changed, 7 insertions(+)
fs/fuse/inode.c +7 -0
index be39dff57c28..ba201bf5ffad 100644
@@ -477,6 +477,13 @@ static int fuse_parse_param(struct fs_context *fc, struct fs_parameter *param)
 	struct fuse_fs_context *ctx = fc->fs_private;
 	int opt;
 
+	/*
+	 * Ignore options coming from mount(MS_REMOUNT) for backward
+	 * compatibility.
+	 */
+	if (fc->purpose == FS_CONTEXT_FOR_RECONFIGURE)
+		return 0;
+
 	opt = fs_parse(fc, fuse_fs_parameters, param, &result);
 	if (opt < 0)
 		return opt;
Signature · 1 line
2.21.1
maintainer
#2 lore raw

Re: [PATCH 2/3] fuse: ignore 'data' argument of mount(..., MS_REMOUNT)

Hi

[This is an automated email]

This commit has been processed because it contains a "Fixes:" tag fixing commit: c30da2e981a7 ("fuse: convert to use the new mount API").

The bot has tested the following trees: v5.7.8, v5.4.51.

v5.7.8: Build OK!
v5.4.51: Failed to apply! Possible dependencies:

    7f5d38141e309 ("new primitive: __fs_parse()")
    82995cc6c5ae4 ("libceph, rbd, ceph: convert to use the new mount API")
    d7167b149943e ("fs_parse: fold fs_parameter_desc/fs_parameter_spec")

NOTE: The patch will not be queued to stable trees until it is upstream.

How should we proceed with this patch?

Signature · 2 lines
Thanks
Sasha
maintainer
#3 lore raw

Re: [PATCH 2/3] fuse: ignore 'data' argument of mount(..., MS_REMOUNT)

Quoted 12 lines · Sasha Levin

Hi

[This is an automated email]

This commit has been processed because it contains a "Fixes:" tag fixing commit: c30da2e981a7 ("fuse: convert to use the new mount API").

The bot has tested the following trees: v5.7.8, v5.4.51.

v5.7.8: Build OK!
v5.4.51: Failed to apply! Possible dependencies:

Quoted 8 lines
    7f5d38141e309 ("new primitive: __fs_parse()")
    82995cc6c5ae4 ("libceph, rbd, ceph: convert to use the new mount API")
    d7167b149943e ("fs_parse: fold fs_parameter_desc/fs_parameter_spec")

NOTE: The patch will not be queued to stable trees until it is upstream.

How should we proceed with this patch?

Conflict resolution is trivial.

Thanks,
Miklos

fs/fuse/inode.c +0 -0
diff --cc fs/fuse/inode.c
index 16aec32f7f3d,ba201bf5ffad..000000000000
@@@ -473,7 -477,14 +473,14 @@@ static int fuse_parse_param(struct fs_c
  	struct fuse_fs_context *ctx = fc->fs_private;
  	int opt;
  
+ 	/*
+ 	 * Ignore options coming from mount(MS_REMOUNT) for backward
+ 	 * compatibility.
+ 	 */
+ 	if (fc->purpose == FS_CONTEXT_FOR_RECONFIGURE)
+ 		return 0;
+ 
 -	opt = fs_parse(fc, fuse_fs_parameters, param, &result);
 +	opt = fs_parse(fc, &fuse_fs_parameters, param, &result);
  	if (opt < 0)
  		return opt;
  
#4 lore raw

PATCH 3/3 fuse: reject options on reconfigure via fsconfig(2)

In reply to Miklos Szeredi

Previous patch changed handling of remount/reconfigure to ignore all options, including those that are unknown to the fuse kernel fs. This was done for backward compatibility, but this likely only affects the old mount(2) API.

The new fsconfig(2) based reconfiguration could possibly be improved. This would make the new API less of a drop in replacement for the old, OTOH this is a good chance to get rid of some weirdnesses in the old API.

Several other behaviors might make sense:

1) unknown options are rejected, known options are ignored

2) unknown options are rejected, known options are rejected if the value is changed, allowed otherwise

3) all options are rejected

Prior to the backward compatibility fix to ignore all options all known options were accepted (1), even if they change the value of a mount parameter; fuse_reconfigure() does not look at the config values set by fuse_parse_param().

To fix that we'd need to verify that the value provided is the same as set in the initial configuration (2). The major drawback is that this is much more complex than just rejecting all attempts at changing options (3); i.e. all options signify initial configuration values and don't make sense on reconfigure.

This patch opts for (3) with the rationale that no mount options are reconfigurable in fuse.

---
 fs/fuse/inode.c            | 16 ++++++++++------
 fs/namespace.c             |  1 +
 include/linux/fs_context.h |  1 +
 3 files changed, 12 insertions(+), 6 deletions(-)
fs/fuse/inode.c +10 -6
index ba201bf5ffad..bba747520e9b 100644
@@ -477,12 +477,16 @@ static int fuse_parse_param(struct fs_context *fc, struct fs_parameter *param)
 	struct fuse_fs_context *ctx = fc->fs_private;
 	int opt;
 
-	/*
-	 * Ignore options coming from mount(MS_REMOUNT) for backward
-	 * compatibility.
-	 */
-	if (fc->purpose == FS_CONTEXT_FOR_RECONFIGURE)
-		return 0;
+	if (fc->purpose == FS_CONTEXT_FOR_RECONFIGURE) {
+		/*
+		 * Ignore options coming from mount(MS_REMOUNT) for backward
+		 * compatibility.
+		 */
+		if (fc->oldapi)
+			return 0;
+
+		return invalfc(fc, "No changes allowed in reconfigure");
+	}
 
 	opt = fs_parse(fc, fuse_fs_parameters, param, &result);
 	if (opt < 0)
fs/namespace.c +1 -0
index f30ed401cc6d..4a0f600a3328 100644
@@ -2603,6 +2603,7 @@ static int do_remount(struct path *path, int ms_flags, int sb_flags,
 	if (IS_ERR(fc))
 		return PTR_ERR(fc);
 
+	fc->oldapi = true;
 	err = parse_monolithic_mount_data(fc, data);
 	if (!err) {
 		down_write(&sb->s_umount);
include/linux/fs_context.h +1 -0
index 5f24fcbfbfb4..37e1e8f7f08d 100644
@@ -109,6 +109,7 @@ struct fs_context {
 	enum fs_context_phase	phase:8;	/* The phase the context is in */
 	bool			need_free:1;	/* Need to call ops->free() */
 	bool			global:1;	/* Goes into &init_user_ns */
+	bool			oldapi:1;	/* Coming from mount(2) */
 };
 
 struct fs_context_operations {
Signature · 1 line
2.21.1