From: sashiko-bot@kernel.org
To: "Christian Brauner" <brauner@kernel.org>
Cc: "Mark Fasheh" <mark@fasheh.com>,
"Joel Becker" <jlbec@evilplan.org>,
"Joseph Qi" <joseph.qi@linux.alibaba.com>,
dsterba@suse.cz, tytso@mit.edu, linux-ext4@vger.kernel.org
Subject: Re: [PATCH RFC 11/28] affs: don't set SB_RDONLY after filesystem errors
Date: Mon, 12 Oct 2026 10:41:56 +0000 [thread overview]
Message-ID: <sashiko-outbox-167976@kernel.org> (raw)
In-Reply-To: <20261012-work-fs-sb_rdonly-v1-11-60743a3dc326@kernel.org>
Thank you for your contribution! Sashiko AI review found 2 potential issue(s) to consider:
- [High] affs: affs_error() logic short-circuit prevents setting emergency RO if already SB_RDONLY
- [High] affs: mmap writes and writeback bypass AFFS_STATE_EMERGENCY_RO and corrupt filesystem
--
commit 1ab95d009ae4a762fda73d7b1a5276c439494d6a
Author: Christian Brauner <brauner@kernel.org>
Subject: affs: don't set SB_RDONLY after filesystem errors
This commit stops setting SB_RDONLY directly in affs_error() without
holding sb->s_umount, which previously caused deadlocks during freezing.
Instead, it introduces an AFFS_STATE_EMERGENCY_RO bit to gracefully
refuse modifications with -EROFS.
> diff --git a/fs/affs/amigaffs.c b/fs/affs/amigaffs.c
> --- a/fs/affs/amigaffs.c
> +++ b/fs/affs/amigaffs.c
> @@ -479,9 +479,15 @@ affs_error(struct super_block *sb, const char *function, const char *fmt, ...)
> vaf.fmt = fmt;
> vaf.va = &args;
> pr_crit("error (device %s): %s(): %pV\n", sb->s_id, function, &vaf);
> - if (!sb_rdonly(sb))
> + /*
> + * Don't set SB_RDONLY: that requires sb->s_umount and a proper
> + * remount. Set while the superblock is frozen it makes thaw_super()
> + * skip releasing s_writers and every later writer hangs. Refuse
> + * modifications until umount instead.
> + */
> + if (!sb_rdonly(sb) &&
> + !test_and_set_bit(AFFS_STATE_EMERGENCY_RO, &AFFS_SB(sb)->s_state))
[Severity: High]
Does this short-circuit logic prevent the emergency RO bit from being set
if the filesystem is already read-only?
If a user mounts the filesystem RO, hits a read or checksum error (triggering
affs_error()), the AFFS_STATE_EMERGENCY_RO bit is completely skipped because
sb_rdonly(sb) is true.
When the user later remounts RW, affs_reconfigure() finds
affs_emergency_ro(sb) to be false and permits the RW remount. Could this
allow a corrupted filesystem to become writable, violating the intent to
refuse modifications after an error?
> pr_warn("Remounting filesystem read-only\n");
> - sb->s_flags |= SB_RDONLY;
> va_end(args);
> }
> diff --git a/fs/affs/file.c b/fs/affs/file.c
> --- a/fs/affs/file.c
> +++ b/fs/affs/file.c
[ ... ]
> @@ -1000,10 +1006,18 @@ int affs_file_fsync(struct file *filp, loff_t start, loff_t end, int datasync)
> inode_unlock(inode);
> return ret;
> }
> +
> +static ssize_t affs_file_write_iter(struct kiocb *iocb, struct iov_iter *from)
> +{
> + if (affs_emergency_ro(file_inode(iocb->ki_filp)->i_sb))
> + return -EROFS;
> + return generic_file_write_iter(iocb, from);
> +}
[Severity: High]
Since this patch removes SB_RDONLY from the error path, do we now need
checks in the mmap and writeback paths to prevent arbitrary data and
metadata modifications?
By no longer setting SB_RDONLY, the VFS filemap_page_mkwrite (used by
generic_file_mmap_prepare) permits dirtying pages without resistance.
During writeback, affs_writepages() calls affs_get_block():
fs/affs/file.c:affs_writepages() {
return mpage_writepages(mapping, wbc, affs_get_block);
}
fs/affs/file.c:affs_get_block() {
...
if (create) {
u32 blocknr = affs_alloc_block(inode, ext_bh->b_blocknr);
...
}
If the write targets a hole, affs_alloc_block() allocates blocks on the
physical disk and dirties metadata buffers. Because neither affs_writepages()
nor affs_get_block() check affs_emergency_ro(), could a user memory map an
opened file, write to it after an error, and have background writeback flush
the pages to disk, thereby corrupting the filesystem?
> +
> const struct file_operations affs_file_operations = {
> .llseek = generic_file_llseek,
> .read_iter = generic_file_read_iter,
> - .write_iter = generic_file_write_iter,
> + .write_iter = affs_file_write_iter,
> .mmap_prepare = generic_file_mmap_prepare,
> .open = affs_file_open,
> .release = affs_file_release,
--
Sashiko AI review · https://sashiko.dev/#/patchset/20261012-work-fs-sb_rdonly-v1-0-60743a3dc326@kernel.org?part=11
next prev parent reply other threads:[~2026-10-12 10:41 UTC|newest]
Thread overview: 64+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-10-12 10:20 [PATCH RFC 00/28] fs: don't set SB_RDONLY after filesystem errors Christian Brauner
2026-10-12 10:20 ` [PATCH RFC 01/28] ecryptfs: don't leak the inode when a lookup can't open the lower file Christian Brauner
2026-10-12 10:34 ` sashiko-bot
2026-10-12 10:20 ` [PATCH RFC 02/28] ecryptfs: fall back to a read-only " Christian Brauner
2026-10-12 10:32 ` sashiko-bot
2026-10-12 10:20 ` [PATCH RFC 03/28] ext2: don't set SB_RDONLY after filesystem errors Christian Brauner
2026-10-12 10:44 ` sashiko-bot
2026-10-12 10:20 ` [PATCH RFC 04/28] jfs: " Christian Brauner
2026-10-12 10:41 ` sashiko-bot
2026-10-12 10:20 ` [PATCH RFC 05/28] nilfs2: " Christian Brauner
2026-10-12 10:34 ` sashiko-bot
2026-10-13 16:01 ` Ryusuke Konishi
2026-10-12 10:20 ` [PATCH RFC 06/28] fat: " Christian Brauner
2026-10-12 10:37 ` sashiko-bot
2026-10-12 10:20 ` [PATCH RFC 07/28] exfat: keep the current mount options on remount Christian Brauner
2026-10-12 10:36 ` sashiko-bot
2026-10-12 10:20 ` [PATCH RFC 08/28] exfat: don't set SB_RDONLY after filesystem errors Christian Brauner
2026-10-12 10:35 ` sashiko-bot
2026-10-12 10:20 ` [PATCH RFC 09/28] hfs: don't set SB_RDONLY after MDB write errors Christian Brauner
2026-10-12 10:41 ` sashiko-bot
2026-10-12 22:57 ` [Jfs-discussion] " Viacheslav Dubeyko
2026-10-12 10:20 ` [PATCH RFC 10/28] hfsplus: don't set SB_RDONLY when creating the attributes tree Christian Brauner
2026-10-12 10:36 ` sashiko-bot
2026-10-12 22:34 ` [Jfs-discussion] " Viacheslav Dubeyko
2026-10-12 10:20 ` [PATCH RFC 11/28] affs: don't set SB_RDONLY after filesystem errors Christian Brauner
2026-10-12 10:41 ` sashiko-bot [this message]
2026-10-12 10:20 ` [PATCH RFC 12/28] ufs: " Christian Brauner
2026-10-12 10:39 ` sashiko-bot
2026-10-12 10:20 ` [PATCH RFC 13/28] hpfs: " Christian Brauner
2026-10-12 10:35 ` sashiko-bot
2026-10-12 10:20 ` [PATCH RFC 14/28] ntfs: " Christian Brauner
2026-10-12 10:45 ` sashiko-bot
2026-10-12 10:21 ` [PATCH RFC 15/28] ocfs2: keep options that can't change on remount Christian Brauner
2026-10-12 10:45 ` sashiko-bot
2026-10-12 10:21 ` [PATCH RFC 16/28] ocfs2: don't set SB_RDONLY after filesystem errors Christian Brauner
2026-10-12 10:59 ` sashiko-bot
2026-10-12 10:21 ` [PATCH RFC 17/28] zonefs: don't set SB_RDONLY after I/O errors Christian Brauner
2026-10-12 10:42 ` sashiko-bot
2026-10-12 10:21 ` [PATCH RFC 18/28] btrfs: check BTRFS_FS_STATE_RO instead of SB_RDONLY at runtime Christian Brauner
2026-10-12 10:53 ` sashiko-bot
2026-10-12 10:21 ` [PATCH RFC 19/28] btrfs: don't set SB_RDONLY after filesystem errors Christian Brauner
2026-10-12 11:05 ` sashiko-bot
2026-10-12 10:21 ` [PATCH RFC 20/28] gfs2: wait for a pending withdraw before remounting read-only Christian Brauner
2026-10-12 10:44 ` sashiko-bot
2026-10-12 10:21 ` [PATCH RFC 21/28] gfs2: don't set SB_RDONLY on withdraw Christian Brauner
2026-10-12 10:48 ` sashiko-bot
2026-10-12 10:21 ` [PATCH RFC 22/28] efivarfs: stop using SB_RDONLY for read-only efivar ops Christian Brauner
2026-10-12 10:52 ` sashiko-bot
2026-10-12 10:21 ` [PATCH RFC 23/28] ubifs: don't set SB_RDONLY after errors Christian Brauner
2026-10-12 11:05 ` sashiko-bot
2026-10-12 10:21 ` [PATCH RFC 24/28] selftests/filesystems: test filesystem errors while frozen Christian Brauner
2026-10-12 10:47 ` sashiko-bot
2026-10-12 10:21 ` [PATCH RFC 25/28] ext4: allow remounting read-only in the emergency state Christian Brauner
2026-10-12 10:49 ` sashiko-bot
2026-10-12 16:38 ` Jan Kara
2026-10-12 10:21 ` [PATCH RFC 26/28] selftests/filesystems: test ext4 remounts " Christian Brauner
2026-10-12 10:52 ` sashiko-bot
2026-10-12 10:21 ` [PATCH RFC 27/28] xfs: allow remounting read-only after a shutdown Christian Brauner
2026-10-12 10:55 ` sashiko-bot
2026-10-13 7:38 ` Christoph Hellwig
2026-10-12 10:21 ` [PATCH RFC 28/28] selftests/filesystems: test xfs remounts " Christian Brauner
2026-10-12 10:51 ` sashiko-bot
2026-10-13 7:40 ` Christoph Hellwig
2026-10-12 16:53 ` [PATCH RFC 00/28] fs: don't set SB_RDONLY after filesystem errors Jan Kara
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=sashiko-outbox-167976@kernel.org \
--to=sashiko-bot@kernel.org \
--cc=brauner@kernel.org \
--cc=dsterba@suse.cz \
--cc=jlbec@evilplan.org \
--cc=joseph.qi@linux.alibaba.com \
--cc=linux-ext4@vger.kernel.org \
--cc=mark@fasheh.com \
--cc=sashiko-reviews@lists.linux.dev \
--cc=tytso@mit.edu \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox