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

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



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@xxxxxxxx>
---
 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
From 17d62fab3a2fdb80eb20aac6d7692be597b90dc6 Mon Sep 17 00:00:00 2001
From: Yuezhang Mo <Yuezhang.Mo@xxxxxxxx>
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@xxxxxxxx>
---
 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


[Index of Archives]     [Linux Ext4 Filesystem]     [Union Filesystem]     [Filesystem Testing]     [Ceph Users]     [Ecryptfs]     [NTFS 3]     [AutoFS]     [Kernel Newbies]     [Share Photos]     [Security]     [Netfilter]     [Bugtraq]     [Yosemite News]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Linux Cachefs]     [Reiser Filesystem]     [Linux RAID]     [NTFS 3]     [Samba]     [Device Mapper]     [CEPH Development]

  Powered by Linux