fspick() creates a reconfiguration context with an empty flag mask. Only setting "ro" or "rw" adds SB_RDONLY to it. reconfigure_super() honours the mask and leaves SB_RDONLY alone otherwise. But a lot of filesystems decide in their ->reconfigure() whether to go read-write by comparing fc->sb_flags & SB_RDONLY with the current state of the superblock and ignore the mask: affs, befs, btrfs, efivarfs, ext4, fat, gfs2, hfs, hfsplus, hpfs, isofs, jffs2, jfs, minix, nilfs2, ntfs, ntfs3, ocfs2, overlayfs, ubifs, udf, ufs and xfs. mount(2) always puts SB_RDONLY into the mask so that never mattered for it. So reconfiguring a read-only superblock through fspick() without "rw", e.g., to change an unrelated option or with no option at all, makes these filesystems go through their read-only to read-write transition. For ext4 and btrfs that ends with a read-write superblock that writes to the device and can be written to through any read-write bind mount: EXT4-fs (vda): re-mounted 68db7463-95cb-47f9-ab87-d1fd35252958 r/w. Fill in the current read-only state when the mask doesn't cover it. reconfigure_super() is called with s_umount held so that can't race with another reconfiguration. Doing it when the context is created would. Fixes: cf3cba4a429b ("vfs: syscall: Add fspick() to select a superblock for reconfiguration") Cc: stable@vger.kernel.org Signed-off-by: Christian Brauner (Amutable) --- fs/super.c | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/fs/super.c b/fs/super.c index ac4c4d067509..edd5648d1720 100644 --- a/fs/super.c +++ b/fs/super.c @@ -1077,6 +1077,14 @@ int reconfigure_super(struct fs_context *fc) if (sb->s_writers.frozen != SB_UNFROZEN) return -EBUSY; + /* + * Filesystems take fc->sb_flags & SB_RDONLY as the read-only state the + * superblock ends up in. If that isn't being changed, e.g., fspick() + * without "ro" or "rw", it's the current one. + */ + if (!(fc->sb_flags_mask & SB_RDONLY)) + fc->sb_flags = (fc->sb_flags & ~SB_RDONLY) | (sb->s_flags & SB_RDONLY); + retval = security_sb_remount(sb, fc->security); if (retval) return retval; -- 2.53.0