Linux-mm Archive on lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH 0/3] fs: pre-existing fixes for the SB_RDONLY series
@ 2026-11-16  9:28 Christian Brauner
  2026-11-16  9:28 ` [PATCH 1/3] gfs2: don't BUG when remounting read-only after a withdraw during mount Christian Brauner
                   ` (2 more replies)
  0 siblings, 3 replies; 6+ messages in thread
From: Christian Brauner @ 2026-11-16  9:28 UTC (permalink / raw)
  To: linux-fsdevel
  Cc: Jan Kara, ecryptfs, linux-ext4, jfs-discussion, linux-nilfs,
	exfat, linux-mm, ntfs, ocfs2-devel, linux-btrfs, gfs2, linux-efi,
	linux-mtd, linux-xfs, Christian Brauner (Amutable), stable

Three fixes for pre-existing bugs that came up during review of the
SB_RDONLY series (cf. [1]). They don't depend on it and are all tagged
for stable. I'll put them in front of the series in vfs-7.5.super.

- gfs2 hits the BUG_ON() in gfs2_quota_cleanup() on a remount to
  read-only after a withdraw during mount. The withdraw work was never
  queued so SDF_JOURNAL_LIVE stays set.

- exfat marks the volume clean at umount or on a remount to read-only
  after a shutdown with EXFAT_GOING_DOWN_NOSYNC although it may be
  inconsistent.

- jfs takes a negative inode size from disk as is. A symlink with one
  is treated as a fast symlink and jfs_iget() writes out of bounds.

[1]: https://patch.msgid.link/20261113-work-fs-sb_rdonly-v3-0-0be92bb73709@kernel.org

Signed-off-by: Christian Brauner (Amutable) <brauner@kernel.org>
---
Christian Brauner (3):
      gfs2: don't BUG when remounting read-only after a withdraw during mount
      exfat: keep the volume marked dirty after a shutdown
      jfs: refuse inodes with a negative size

 fs/exfat/super.c     | 3 ++-
 fs/gfs2/incore.h     | 1 +
 fs/gfs2/ops_fstype.c | 5 +++++
 fs/gfs2/util.c       | 9 ++++++++-
 fs/gfs2/util.h       | 1 +
 fs/jfs/jfs_imap.c    | 4 ++++
 6 files changed, 21 insertions(+), 2 deletions(-)
---
base-commit: c339f4010dea8b0d754f84ace70cd1b089878ef8
change-id: 20261116-work-fs-sb_rdonly-fixes-d74c927f80b5



^ permalink raw reply	[flat|nested] 6+ messages in thread

* [PATCH 1/3] gfs2: don't BUG when remounting read-only after a withdraw during mount
  2026-11-16  9:28 [PATCH 0/3] fs: pre-existing fixes for the SB_RDONLY series Christian Brauner
@ 2026-11-16  9:28 ` Christian Brauner
  2026-11-17  9:51   ` sashiko-bot
  2026-11-16  9:28 ` [PATCH 2/3] exfat: keep the volume marked dirty after a shutdown Christian Brauner
  2026-11-16  9:28 ` [PATCH 3/3] jfs: refuse inodes with a negative size Christian Brauner
  2 siblings, 1 reply; 6+ messages in thread
From: Christian Brauner @ 2026-11-16  9:28 UTC (permalink / raw)
  To: linux-fsdevel
  Cc: Jan Kara, ecryptfs, linux-ext4, jfs-discussion, linux-nilfs,
	exfat, linux-mm, ntfs, ocfs2-devel, linux-btrfs, gfs2, linux-efi,
	linux-mtd, linux-xfs, Christian Brauner (Amutable), stable

gfs2_withdraw() doesn't queue the withdraw work before the superblock is
born. But gfs2_fill_super() makes the journal live before that and a
withdraw can still happen until the mount is done, e.g. from the log or
quota daemons or through the withdraw file in sysfs. The withdraw is
then never processed and SDF_JOURNAL_LIVE stays set. A later remount to
read-only, sysrq u included, goes through gfs2_make_fs_ro() whose log
flushes bail out early on the withdrawn filesystem and then
gfs2_quota_cleanup() hits its BUG_ON().

So queue the withdraw work from gfs2_reconfigure() and wait for it
before going read-only. The work can't run twice so guard the queueing
with a new SDF_WITHDRAW_QUEUED bit.

Fixes: 9c4a3de6cd5b ("gfs2: Asynchronous withdraw")
Cc: stable@vger.kernel.org
Signed-off-by: Christian Brauner (Amutable) <brauner@kernel.org>
---
 fs/gfs2/incore.h     | 1 +
 fs/gfs2/ops_fstype.c | 5 +++++
 fs/gfs2/util.c       | 9 ++++++++-
 fs/gfs2/util.h       | 1 +
 4 files changed, 15 insertions(+), 1 deletion(-)

diff --git a/fs/gfs2/incore.h b/fs/gfs2/incore.h
index 49cc232942a29..151458e90480b 100644
--- a/fs/gfs2/incore.h
+++ b/fs/gfs2/incore.h
@@ -605,6 +605,7 @@ enum {
 	SDF_KILL		= 15,
 	SDF_EVICTING		= 16,
 	SDF_FROZEN		= 17,
+	SDF_WITHDRAW_QUEUED	= 18,
 };
 
 #define GFS2_FSNAME_LEN		256
diff --git a/fs/gfs2/ops_fstype.c b/fs/gfs2/ops_fstype.c
index 6ec47376aecf2..3bd5702535dfe 100644
--- a/fs/gfs2/ops_fstype.c
+++ b/fs/gfs2/ops_fstype.c
@@ -1590,6 +1590,11 @@ static int gfs2_reconfigure(struct fs_context *fc)
 
 	if ((sb->s_flags ^ fc->sb_flags) & SB_RDONLY) {
 		if (fc->sb_flags & SB_RDONLY) {
+			/* gfs2_withdraw() doesn't queue the work during mount. */
+			if (gfs2_withdrawn(sdp)) {
+				gfs2_queue_withdraw(sdp);
+				flush_work(&sdp->sd_withdraw_work);
+			}
 			gfs2_make_fs_ro(sdp);
 		} else {
 			error = gfs2_make_fs_rw(sdp);
diff --git a/fs/gfs2/util.c b/fs/gfs2/util.c
index 529c3ec37a18a..5558af374994a 100644
--- a/fs/gfs2/util.c
+++ b/fs/gfs2/util.c
@@ -238,6 +238,13 @@ void gfs2_withdraw_func(struct work_struct *work)
 	fs_err(sdp, "file system withdrawn\n");
 }
 
+/* The withdraw work must only run once. */
+void gfs2_queue_withdraw(struct gfs2_sbd *sdp)
+{
+	if (!test_and_set_bit(SDF_WITHDRAW_QUEUED, &sdp->sd_flags))
+		schedule_work(&sdp->sd_withdraw_work);
+}
+
 void gfs2_withdraw(struct gfs2_sbd *sdp)
 {
 	if (sdp->sd_args.ar_errors == GFS2_ERRORS_WITHDRAW ||
@@ -253,7 +260,7 @@ void gfs2_withdraw(struct gfs2_sbd *sdp)
 		if (!(sdp->sd_vfs->s_flags & SB_BORN))
 			return;
 		fs_err(sdp, "about to withdraw this file system\n");
-		schedule_work(&sdp->sd_withdraw_work);
+		gfs2_queue_withdraw(sdp);
 		return;
 	}
 
diff --git a/fs/gfs2/util.h b/fs/gfs2/util.h
index ffcc47d6b0b4b..78690fe76cfeb 100644
--- a/fs/gfs2/util.h
+++ b/fs/gfs2/util.h
@@ -195,5 +195,6 @@ void gfs2_lm(struct gfs2_sbd *sdp, const char *fmt, ...);
 
 void gfs2_withdraw_func(struct work_struct *work);
 void gfs2_withdraw(struct gfs2_sbd *sdp);
+void gfs2_queue_withdraw(struct gfs2_sbd *sdp);
 
 #endif /* __UTIL_DOT_H__ */

-- 
2.53.0



^ permalink raw reply related	[flat|nested] 6+ messages in thread

* [PATCH 2/3] exfat: keep the volume marked dirty after a shutdown
  2026-11-16  9:28 [PATCH 0/3] fs: pre-existing fixes for the SB_RDONLY series Christian Brauner
  2026-11-16  9:28 ` [PATCH 1/3] gfs2: don't BUG when remounting read-only after a withdraw during mount Christian Brauner
@ 2026-11-16  9:28 ` Christian Brauner
  2026-11-17  9:51   ` sashiko-bot
  2026-11-16  9:28 ` [PATCH 3/3] jfs: refuse inodes with a negative size Christian Brauner
  2 siblings, 1 reply; 6+ messages in thread
From: Christian Brauner @ 2026-11-16  9:28 UTC (permalink / raw)
  To: linux-fsdevel
  Cc: Jan Kara, ecryptfs, linux-ext4, jfs-discussion, linux-nilfs,
	exfat, linux-mm, ntfs, ocfs2-devel, linux-btrfs, gfs2, linux-efi,
	linux-mtd, linux-xfs, Christian Brauner (Amutable), stable

After a shutdown exfat_write_inode() and exfat_writepages() drop
whatever is still dirty. But exfat_put_super() and a remount to
read-only still clear VOLUME_DIRTY through exfat_set_vol_flags() which
only leaves the boot sector alone on a read-only superblock. So after a
shutdown with EXFAT_GOING_DOWN_NOSYNC the volume ends up marked clean
although it may be inconsistent. Leave the boot sector alone after a
shutdown too.

Fixes: f761fcdd289d ("exfat: Implement sops->shutdown and ioctl")
Cc: stable@vger.kernel.org
Signed-off-by: Christian Brauner (Amutable) <brauner@kernel.org>
---
 fs/exfat/super.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/fs/exfat/super.c b/fs/exfat/super.c
index 4943cef977418..eef7c159d32f4 100644
--- a/fs/exfat/super.c
+++ b/fs/exfat/super.c
@@ -98,8 +98,9 @@ static int exfat_set_vol_flags(struct super_block *sb, unsigned short new_flags)
 
 	/* skip updating volume dirty flag,
 	 * if this volume has been mounted with read-only
+	 * or was shut down (it stays dirty then)
 	 */
-	if (sb_rdonly(sb))
+	if (sb_rdonly(sb) || exfat_forced_shutdown(sb))
 		return 0;
 
 	p_boot->vol_flags = cpu_to_le16(new_flags);

-- 
2.53.0



^ permalink raw reply related	[flat|nested] 6+ messages in thread

* [PATCH 3/3] jfs: refuse inodes with a negative size
  2026-11-16  9:28 [PATCH 0/3] fs: pre-existing fixes for the SB_RDONLY series Christian Brauner
  2026-11-16  9:28 ` [PATCH 1/3] gfs2: don't BUG when remounting read-only after a withdraw during mount Christian Brauner
  2026-11-16  9:28 ` [PATCH 2/3] exfat: keep the volume marked dirty after a shutdown Christian Brauner
@ 2026-11-16  9:28 ` Christian Brauner
  2 siblings, 0 replies; 6+ messages in thread
From: Christian Brauner @ 2026-11-16  9:28 UTC (permalink / raw)
  To: linux-fsdevel
  Cc: Jan Kara, ecryptfs, linux-ext4, jfs-discussion, linux-nilfs,
	exfat, linux-mm, ntfs, ocfs2-devel, linux-btrfs, gfs2, linux-efi,
	linux-mtd, linux-xfs, Christian Brauner (Amutable), stable

copy_from_dinode() takes di_size as is and a crafted image can store a
size that is negative as a loff_t. For a symlink that passes the signed
i_size >= IDATASIZE test in jfs_iget(), so it's treated as a fast
symlink and i_link[i_size] = '\0' writes out of bounds. Refuse a
negative size when reading the inode like a corrupt dtroot.

Fixes: d69e83d99cf8 ("jfs: ensure symlinks are NUL-terminated")
Cc: stable@vger.kernel.org
Signed-off-by: Christian Brauner (Amutable) <brauner@kernel.org>
---
 fs/jfs/jfs_imap.c | 4 ++++
 1 file changed, 4 insertions(+)

diff --git a/fs/jfs/jfs_imap.c b/fs/jfs/jfs_imap.c
index b84ba4d7dfb44..f88e228d12620 100644
--- a/fs/jfs/jfs_imap.c
+++ b/fs/jfs/jfs_imap.c
@@ -3079,6 +3079,10 @@ static int copy_from_dinode(struct dinode * dip, struct inode *ip)
 	}
 
 	ip->i_size = le64_to_cpu(dip->di_size);
+	if (ip->i_size < 0) {
+		jfs_error(ip->i_sb, "Negative inode size\n");
+		return -EIO;
+	}
 	inode_set_atime(ip, le32_to_cpu(dip->di_atime.tv_sec),
 			le32_to_cpu(dip->di_atime.tv_nsec));
 	inode_set_mtime(ip, le32_to_cpu(dip->di_mtime.tv_sec),

-- 
2.53.0



^ permalink raw reply related	[flat|nested] 6+ messages in thread

* Re: [PATCH 1/3] gfs2: don't BUG when remounting read-only after a withdraw during mount
  2026-11-16  9:28 ` [PATCH 1/3] gfs2: don't BUG when remounting read-only after a withdraw during mount Christian Brauner
@ 2026-11-17  9:51   ` sashiko-bot
  0 siblings, 0 replies; 6+ messages in thread
From: sashiko-bot @ 2026-11-17  9:51 UTC (permalink / raw)
  To: Christian Brauner
  Cc: Jan Kara, linux-ext4, linux-mm, linux-efi, linux-mtd, dsterba,
	tytso, Mark Fasheh, Joel Becker, Joseph Qi

Thank you for your contribution! Sashiko AI review found 1 potential
issue to consider:
- [Medium] gfs2: race in gfs2_queue_withdraw() lets flush_work() return
  before queue
--

commit 3d2897f8b51331dc6f7b51a37f13ef421ac6739b
Author: Christian Brauner <brauner@kernel.org>

gfs2: don't BUG when remounting read-only after a withdraw during mount

This commit introduces gfs2_queue_withdraw() guarded by SDF_WITHDRAW_QUEUED
and flushes sd_withdraw_work in gfs2_reconfigure() before remounting a
withdrawn filesystem read-only.

> diff --git a/fs/gfs2/ops_fstype.c b/fs/gfs2/ops_fstype.c
> index 6ec47376aecf2..3bd5702535dfe 100644
> --- a/fs/gfs2/ops_fstype.c
> +++ b/fs/gfs2/ops_fstype.c
> @@ -1590,6 +1590,11 @@ static int gfs2_reconfigure(struct fs_context *fc)
>  
>  	if ((sb->s_flags ^ fc->sb_flags) & SB_RDONLY) {
>  		if (fc->sb_flags & SB_RDONLY) {
> +			/* gfs2_withdraw() doesn't queue the work during mount. */
> +			if (gfs2_withdrawn(sdp)) {
> +				gfs2_queue_withdraw(sdp);
> +				flush_work(&sdp->sd_withdraw_work);
> +			}
>  			gfs2_make_fs_ro(sdp);
>  		} else {
>  			error = gfs2_make_fs_rw(sdp);
> diff --git a/fs/gfs2/util.c b/fs/gfs2/util.c
> index 529c3ec37a18a..5558af374994a 100644
> --- a/fs/gfs2/util.c
> +++ b/fs/gfs2/util.c
> @@ -238,6 +238,13 @@ void gfs2_withdraw_func(struct work_struct *work)
>  	fs_err(sdp, "file system withdrawn\n");
>  }
>  
> +/* The withdraw work must only run once. */
> +void gfs2_queue_withdraw(struct gfs2_sbd *sdp)
> +{
> +	if (!test_and_set_bit(SDF_WITHDRAW_QUEUED, &sdp->sd_flags))
> +		schedule_work(&sdp->sd_withdraw_work);
> +}
> +
>  void gfs2_withdraw(struct gfs2_sbd *sdp)
>  {
>  	if (sdp->sd_args.ar_errors == GFS2_ERRORS_WITHDRAW ||
> @@ -253,7 +260,7 @@ void gfs2_withdraw(struct gfs2_sbd *sdp)
>  		if (!(sdp->sd_vfs->s_flags & SB_BORN))
>  			return;
>  		fs_err(sdp, "about to withdraw this file system\n");
> -		schedule_work(&sdp->sd_withdraw_work);
> +		gfs2_queue_withdraw(sdp);
>  		return;
>  	}

[Severity: Medium]
Can flush_work(&sdp->sd_withdraw_work) in gfs2_reconfigure() return before
a concurrent gfs2_withdraw() has queued sd_withdraw_work?

CPU0                                  CPU1
gfs2_withdraw()
  test_and_set_bit(SDF_WITHDRAWN, ...)
  gfs2_queue_withdraw()
    test_and_set_bit(SDF_WITHDRAW_QUEUED, ...)
                                      gfs2_reconfigure()
                                        if (gfs2_withdrawn(sdp))
                                          gfs2_queue_withdraw()
                                            test_and_set_bit(SDF_WITHDRAW_QUEUED, ...)
                                              --> already set, skips schedule_work()
                                          flush_work(&sdp->sd_withdraw_work)
                                            --> not pending yet, returns false
                                        gfs2_make_fs_ro()
                                          ...
                                          gfs2_quota_cleanup()
                                            --> hits BUG_ON()
    schedule_work(&sdp->sd_withdraw_work)

Because test_and_set_bit(SDF_WITHDRAW_QUEUED, &sdp->sd_flags) runs before
schedule_work() marks sd_withdraw_work pending, CPU1's gfs2_queue_withdraw()
can observe SDF_WITHDRAW_QUEUED already set and return without queuing the
work.  flush_work() then sees an idle work item and returns immediately,
allowing gfs2_make_fs_ro() -> gfs2_quota_cleanup() to proceed with
SDF_JOURNAL_LIVE still set and hit its BUG_ON().

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20261116-work-fs-sb_rdonly-fixes-v1-0-95a25ce917ad@kernel.org?part=1


^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [PATCH 2/3] exfat: keep the volume marked dirty after a shutdown
  2026-11-16  9:28 ` [PATCH 2/3] exfat: keep the volume marked dirty after a shutdown Christian Brauner
@ 2026-11-17  9:51   ` sashiko-bot
  0 siblings, 0 replies; 6+ messages in thread
From: sashiko-bot @ 2026-11-17  9:51 UTC (permalink / raw)
  To: Christian Brauner
  Cc: Jan Kara, linux-ext4, linux-mm, linux-efi, linux-mtd, dsterba,
	tytso, Mark Fasheh, Joel Becker, Joseph Qi

Thank you for your contribution! Sashiko AI review found 1 potential
issue to consider:
- [Low] exfat: Fixes trailer cites f761fcdd289d instead of 46a557694b46
--

commit a1d3dffdfc2b9385cf2e9ba0e7b99bd916f22ffa
Author: Christian Brauner <brauner@kernel.org>

> exfat: keep the volume marked dirty after a shutdown
>
> After a shutdown exfat_write_inode() and exfat_writepages() drop
> whatever is still dirty. But exfat_put_super() and a remount to
> read-only still clear VOLUME_DIRTY through exfat_set_vol_flags() which
> only leaves the boot sector alone on a read-only superblock. So after a
> shutdown with EXFAT_GOING_DOWN_NOSYNC the volume ends up marked clean
> although it may be inconsistent. Leave the boot sector alone after a
> shutdown too.
>
> Fixes: f761fcdd289d ("exfat: Implement sops->shutdown and ioctl")
> Cc: stable@vger.kernel.org
> Signed-off-by: Christian Brauner (Amutable) <brauner@kernel.org>

[Severity: Low]
Should the Fixes tag reference 46a557694b46 ("exfat: do not clear volume
dirty flag during sync") instead?

In f761fcdd289d ("exfat: Implement sops->shutdown and ioctl"),
exfat_clear_volume_dirty() was only called from exfat_sync_fs(), which
returned early on exfat_forced_shutdown(sb).  It was 46a557694b46
("exfat: do not clear volume dirty flag during sync") that removed
exfat_sync_fs() along with its shutdown check and moved the
exfat_clear_volume_dirty() calls into exfat_put_super() and
exfat_reconfigure().

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20261116-work-fs-sb_rdonly-fixes-v1-0-95a25ce917ad@kernel.org?part=2


^ permalink raw reply	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2026-11-17  9:51 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-11-16  9:28 [PATCH 0/3] fs: pre-existing fixes for the SB_RDONLY series Christian Brauner
2026-11-16  9:28 ` [PATCH 1/3] gfs2: don't BUG when remounting read-only after a withdraw during mount Christian Brauner
2026-11-17  9:51   ` sashiko-bot
2026-11-16  9:28 ` [PATCH 2/3] exfat: keep the volume marked dirty after a shutdown Christian Brauner
2026-11-17  9:51   ` sashiko-bot
2026-11-16  9:28 ` [PATCH 3/3] jfs: refuse inodes with a negative size Christian Brauner

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox