diff mbox series

[v1] exfat: fix mount options cannot be modified via remount

Message ID PUZPR04MB6316EECFBF485365FB17D05E81C22@PUZPR04MB6316.apcprd04.prod.outlook.com (mailing list archive)
State New
Headers show
Series [v1] exfat: fix mount options cannot be modified via remount | expand

Commit Message

Yuezhang.Mo@sony.com Feb. 26, 2025, 2:56 a.m. UTC
Without this fix, the mount options cannot be modified via remount.
For example, after executing the second command below, mount option
'errors' is not modified to 'remount-ro'.

mount -o errors=panic /dev/sda1 /mnt
mount -o remount,errors=remount-ro /mnt

The reason is that a new "struct fs_context" is allocated during
remount, which when initialized in exfat_init_fs_context(), allocates
a new "struct exfat_sb_info". exfat_parse_param() applies the new
mount options to this new "struct exfat_sb_info" instead of the one
allocated during the first mount.

This commit adds a remount check in exfat_init_fs_context(), so that
if it is a remount, a new "struct exfat_sb_info" is not allocated, but
the one from the first mount is referenced.

Fixes: 719c1e182916 ("exfat: add super block operations")
Signed-off-by: Yuezhang Mo <Yuezhang.Mo@sony.com>
---
 fs/exfat/super.c | 8 +++++++-
 1 file changed, 7 insertions(+), 1 deletion(-)
diff mbox series

Patch

From 17d62fab3a2fdb80eb20aac6d7692be597b90dc6 Mon Sep 17 00:00:00 2001
From: Yuezhang Mo <Yuezhang.Mo@sony.com>
Date: Tue, 7 Jan 2025 18:12:54 +0800
Subject: [PATCH v1] exfat: fix mount options cannot be modified via remount

Without this fix, the mount options cannot be modified via remount.
For example, after executing the second command below, mount option
'errors' is not modified to 'remount-ro'.

mount -o errors=panic /dev/sda1 /mnt
mount -o remount,errors=remount-ro /mnt

The reason is that a new "struct fs_context" is allocated during
remount, which when initialized in exfat_init_fs_context(), allocates
a new "struct exfat_sb_info". exfat_parse_param() applies the new
mount options to this new "struct exfat_sb_info" instead of the one
allocated during the first mount.

This commit adds a remount check in exfat_init_fs_context(), so that
if it is a remount, a new "struct exfat_sb_info" is not allocated, but
the one from the first mount is referenced.

Fixes: 719c1e182916 ("exfat: add super block operations")
Signed-off-by: Yuezhang Mo <Yuezhang.Mo@sony.com>
---
 fs/exfat/super.c | 8 +++++++-
 1 file changed, 7 insertions(+), 1 deletion(-)

diff --git a/fs/exfat/super.c b/fs/exfat/super.c
index 8465033a6cf0..6a23523b1276 100644
--- a/fs/exfat/super.c
+++ b/fs/exfat/super.c
@@ -745,7 +745,7 @@  static void exfat_free(struct fs_context *fc)
 {
 	struct exfat_sb_info *sbi = fc->s_fs_info;
 
-	if (sbi)
+	if (sbi && fc->purpose != FS_CONTEXT_FOR_RECONFIGURE)
 		exfat_free_sbi(sbi);
 }
 
@@ -769,6 +769,11 @@  static int exfat_init_fs_context(struct fs_context *fc)
 {
 	struct exfat_sb_info *sbi;
 
+	if (fc->purpose == FS_CONTEXT_FOR_RECONFIGURE) { /* remount */
+		sbi = EXFAT_SB(fc->root->d_sb);
+		goto out;
+	}
+
 	sbi = kzalloc(sizeof(struct exfat_sb_info), GFP_KERNEL);
 	if (!sbi)
 		return -ENOMEM;
@@ -786,6 +791,7 @@  static int exfat_init_fs_context(struct fs_context *fc)
 	sbi->options.iocharset = exfat_default_iocharset;
 	sbi->options.errors = EXFAT_ERRORS_RO;
 
+out:
 	fc->s_fs_info = sbi;
 	fc->ops = &exfat_context_ops;
 	return 0;
-- 
2.43.0