Skip to contentSkip to conversation

nfs: fix regression in handling of fsc= option in NFSv4

PATCH Superseded Chen Hanxiao 2 participants 3 messages Jan 30, 2024 – Jan 31, 2024

Subsystems (2)

v2 of 3 Superseded Latest is v3 →

lore
Share & tools
lore
#0 lore raw

PATCH v2 1/1 nfs: fix regression in handling of fsc= option in NFSv4

Setting the uniquifier for fscache via the fsc= mount option is currently broken in NFSv4.

Fix this by passing fscache_uniq to root_fc if possible.

---
v2:
use kmemdup_nul instead of snprintf

 fs/nfs/nfs4super.c | 24 ++++++++++++++++++++++++
 1 file changed, 24 insertions(+)
fs/nfs/nfs4super.c +24 -0
index d09bcfd7db89..4a23d9143d5a 100644
@@ -145,6 +145,7 @@ static int do_nfs4_mount(struct nfs_server *server,
 			 const char *export_path)
 {
 	struct nfs_fs_context *root_ctx;
+	struct nfs_fs_context *ctx;
 	struct fs_context *root_fc;
 	struct vfsmount *root_mnt;
 	struct dentry *dentry;
@@ -157,6 +158,12 @@ static int do_nfs4_mount(struct nfs_server *server,
 		.dirfd	= -1,
 	};
 
+	struct fs_parameter param_fsc = {
+		.key	= "fsc",
+		.type	= fs_value_is_string,
+		.dirfd	= -1,
+	};
+
 	if (IS_ERR(server))
 		return PTR_ERR(server);
 
@@ -168,9 +175,26 @@ static int do_nfs4_mount(struct nfs_server *server,
 	kfree(root_fc->source);
 	root_fc->source = NULL;
 
+	ctx = nfs_fc2context(fc);
 	root_ctx = nfs_fc2context(root_fc);
 	root_ctx->internal = true;
 	root_ctx->server = server;
+
+	if (ctx->fscache_uniq) {
+		len = strlen(ctx->fscache_uniq) + 1;
+		param_fsc.size = len;
+		param_fsc.string = kmemdup_nul(ctx->fscache_uniq, len, GFP_KERNEL);
+		if (param_fsc.string == NULL) {
+			put_fs_context(root_fc);
+			return -ENOMEM;
+		}
+		ret = vfs_parse_fs_param(root_fc, &param_fsc);
+		kfree(param_fsc.string);
+		if (ret < 0) {
+			put_fs_context(root_fc);
+			return ret;
+		}
+	}
 	/* We leave export_path unset as it's not used to find the root. */
 
 	len = strlen(hostname) + 5;
Signature · 1 line
2.39.1
maintainer
#1 lore raw
Quoted 40 lines · Chen Hanxiao

Setting the uniquifier for fscache via the fsc= mount option is currently broken in NFSv4.

Fix this by passing fscache_uniq to root_fc if possible.

---
v2:
use kmemdup_nul instead of snprintf

 fs/nfs/nfs4super.c | 24 ++++++++++++++++++++++++
 1 file changed, 24 insertions(+)
fs/nfs/nfs4super.c +7 -0
index d09bcfd7db89..4a23d9143d5a 100644
@@ -145,6 +145,7 @@ static int do_nfs4_mount(struct nfs_server *server,
 			 const char *export_path)
 {
 	struct nfs_fs_context *root_ctx;
+	struct nfs_fs_context *ctx;
 	struct fs_context *root_fc;
 	struct vfsmount *root_mnt;
 	struct dentry *dentry;
@@ -157,6 +158,12 @@ static int do_nfs4_mount(struct nfs_server *server,
 		.dirfd	= -1,
 	};
 
+	struct fs_parameter param_fsc = {
+		.key	= "fsc",
+		.type	= fs_value_is_string,
+		.dirfd	= -1,
+	};
+
 	if (IS_ERR(server))
 		return PTR_ERR(server);
 
@@ -168,9 +175,26 @@ static int do_nfs4_mount(struct nfs_server *server,
 	kfree(root_fc->source);

fs/nfs/nfs4super.c static int do_nfs4_mount(struct nfs_server *server, · line 185

Quoted 10 lines
fs/nfs/nfs4super.c +5 -0
 	root_fc->source = NULL;
 
+	ctx = nfs_fc2context(fc);
 	root_ctx = nfs_fc2context(root_fc);
 	root_ctx->internal = true;
 	root_ctx->server = server;
+
+	if (ctx->fscache_uniq) {
+		len = strlen(ctx->fscache_uniq) + 1;
+		param_fsc.size = len;

In the other patch you were setting .size to the return value from snprintf. That does not include the NUL byte. You're including it here though. Which way is correct?

Quoted 15 lines
fs/nfs/nfs4super.c +12 -0
+		param_fsc.string = kmemdup_nul(ctx->fscache_uniq, len, GFP_KERNEL);
+		if (param_fsc.string == NULL) {
+			put_fs_context(root_fc);
+			return -ENOMEM;
+		}
+		ret = vfs_parse_fs_param(root_fc, &param_fsc);
+		kfree(param_fsc.string);
+		if (ret < 0) {
+			put_fs_context(root_fc);
+			return ret;
+		}
+	}
 	/* We leave export_path unset as it's not used to find the root. */
 
 	len = strlen(hostname) + 5;
Signature · 1 line
Jeff Layton <[email protected]>
#2 lore raw
Quoted 54 lines

-----邮件原件-----
发件人: Jeff Layton <[email protected]>
发送时间: 2024年1月30日 23:50
收件人: Chen, Hanxiao/陈 晗霄 <[email protected]>; Trond Myklebust <[email protected]>; Anna Schumaker <[email protected]> 抄送: [email protected]; Dave Wysochanski <[email protected]>; David Howells <[email protected]>
主题: Re: [PATCH v2] nfs: fix regression in handling of fsc= option in NFSv4

Quoted 42 lines · Chen Hanxiao

Setting the uniquifier for fscache via the fsc= mount option is currently broken in NFSv4.

Fix this by passing fscache_uniq to root_fc if possible.

---
v2:
use kmemdup_nul instead of snprintf

 fs/nfs/nfs4super.c | 24 ++++++++++++++++++++++++
 1 file changed, 24 insertions(+)
fs/nfs/nfs4super.c +7 -0
index d09bcfd7db89..4a23d9143d5a 100644
@@ -145,6 +145,7 @@ static int do_nfs4_mount(struct nfs_server *server,
 			 const char *export_path)
 {
 	struct nfs_fs_context *root_ctx;
+	struct nfs_fs_context *ctx;
 	struct fs_context *root_fc;
 	struct vfsmount *root_mnt;
 	struct dentry *dentry;
@@ -157,6 +158,12 @@ static int do_nfs4_mount(struct nfs_server *server,
 		.dirfd	= -1,
 	};
 
+	struct fs_parameter param_fsc = {
+		.key	= "fsc",
+		.type	= fs_value_is_string,
+		.dirfd	= -1,
+	};
+
 	if (IS_ERR(server))
 		return PTR_ERR(server);
 
@@ -168,9 +175,26 @@ static int do_nfs4_mount(struct nfs_server *server,
 	kfree(root_fc->source);
 	root_fc->source = NULL;
 
Quoted 13 lines

fs/nfs/nfs4super.c static int do_nfs4_mount(struct nfs_server *server, · line 185

Quoted 8 lines
fs/nfs/nfs4super.c +5 -0
+	ctx = nfs_fc2context(fc);
 	root_ctx = nfs_fc2context(root_fc);
 	root_ctx->internal = true;
 	root_ctx->server = server;
+
+	if (ctx->fscache_uniq) {
+		len = strlen(ctx->fscache_uniq) + 1;
+		param_fsc.size = len;

In the other patch you were setting .size to the return value from snprintf. That does not include the NUL byte. You're including it here though. Which way is correct?

It should be:
len = strlen(ctx->fscache_uniq).
param_fsc.size = len;

for kmemdup_nul case.

Will be fixed in v3.
Sorry for the noise.

Regards
- Chen

Quoted 19 lines

fs/nfs/nfs4super.c static int do_nfs4_mount(struct nfs_server *server, · line 186

Quoted 1 line
fs/nfs/nfs4super.c +1 -0
+		param_fsc.string = kmemdup_nul(ctx->fscache_uniq, len,

GFP_KERNEL);

Quoted 4 lines
fs/nfs/nfs4super.c +4 -0
+		if (param_fsc.string == NULL) {
+			put_fs_context(root_fc);
+			return -ENOMEM;
+		}

fs/nfs/nfs4super.c static int do_nfs4_mount(struct nfs_server *server, · line 200

Quoted 10 lines
fs/nfs/nfs4super.c +7 -0
+		ret = vfs_parse_fs_param(root_fc, &param_fsc);
+		kfree(param_fsc.string);
+		if (ret < 0) {
+			put_fs_context(root_fc);
+			return ret;
+		}
+	}
 	/* We leave export_path unset as it's not used to find the root. */
 
 	len = strlen(hostname) + 5;

--
Jeff Layton <[email protected]>