Skip to contentSkip to conversation

NFS: Ensure the fs_context has the correct fs_type before mounting

PATCH New Scott Mayhew 1 participant 1 message Feb 21, 2020

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

PATCH 1/1 NFS: Ensure the fs_context has the correct fs_type before mounting

This is necessary because unless userspace explicitly requests fstype "nfs4" (either via "mount -t nfs4" or by calling the "mount.nfs4" helper directly), the fstype will default to "nfs".

This was fine on older kernels because the super_block->s_type was set via mount_info->nfs_mod->nfs_fs, which was set when parsing the mount options and subsequently passed in the "type" argument of sget().

After commit f2aedb713c28 ("NFS: Add fs_context support."), sget_fc(), which has no "type" argument, is called instead. In sget_fc(), the super_block->s_type is set via fs_context->fs_type, which was set when the filesystem context was initially created.

Fixes f2aedb713c28 ("NFS: Add fs_context support.")
---
 fs/nfs/fs_context.c | 7 +++++++
 1 file changed, 7 insertions(+)
fs/nfs/fs_context.c +7 -0
index e1b938457ab9..b616263b0eb6 100644
@@ -1240,6 +1240,13 @@ static int nfs_fs_context_validate(struct fs_context *fc)
 		}
 		ctx->nfs_mod = nfs_mod;
 	}
+
+	/* Ensure the filesystem context has the correct fs_type */
+	if (fc->fs_type != ctx->nfs_mod->nfs_fs) {
+		module_put(fc->fs_type->owner);
+		__module_get(ctx->nfs_mod->nfs_fs->owner);
+		fc->fs_type = ctx->nfs_mod->nfs_fs;
+	}
 	return 0;
 
 out_no_device_name:
Signature · 1 line
2.24.1