vfs_clean_context() prepares a context for the next reconfiguration after fsmount() and after every successful FSCONFIG_CMD_RECONFIGURE. It resets fc->sb_flags but leaves fc->sb_flags_mask alone. So the next FSCONFIG_CMD_RECONFIGURE on that file descriptor applies the old mask to empty flags. That makes a read-only superblock read-write without anyone asking for it: fsfd = fsopen("ext4", 0); fsconfig(fsfd, FSCONFIG_SET_STRING, "source", "/dev/vda", 0); fsconfig(fsfd, FSCONFIG_SET_FLAG, "ro", NULL, 0); fsconfig(fsfd, FSCONFIG_CMD_CREATE, NULL, NULL, 0); mntfd = fsmount(fsfd, 0, 0); move_mount(mntfd, "", AT_FDCWD, "/mnt", MOVE_MOUNT_F_EMPTY_PATH); fsconfig(fsfd, FSCONFIG_CMD_RECONFIGURE, NULL, NULL, 0); EXT4-fs (vda): re-mounted 68db7463-95cb-47f9-ab87-d1fd35252958 r/w. The same happens for a second FSCONFIG_CMD_RECONFIGURE on a context from fspick() after the first one set "ro". The stale mask also drops SB_SYNCHRONOUS, SB_LAZYTIME and SB_MANDLOCK set in an earlier round. And btrfs_reconfigure() adds SB_POSIXACL to the mask when "acl" or "noacl" changes the ACL state so every later reconfiguration on that file descriptor fails with -EINVAL as reconfigure_super() refuses anything outside of MS_RMT_MASK. Reset the mask as well so a cleaned context looks like a new one from fspick() just as the comment in sys_fsmount() promises. Fixes: ecdab150fddb ("vfs: syscall: Add fsconfig() for configuring and managing a context") Cc: stable@vger.kernel.org Signed-off-by: Christian Brauner (Amutable) --- fs/fs_context.c | 1 + 1 file changed, 1 insertion(+) diff --git a/fs/fs_context.c b/fs/fs_context.c index a50584df97be..ba99e673458a 100644 --- a/fs/fs_context.c +++ b/fs/fs_context.c @@ -544,6 +544,7 @@ void vfs_clean_context(struct fs_context *fc) fc->fs_private = NULL; fc->s_fs_info = NULL; fc->sb_flags = 0; + fc->sb_flags_mask = 0; security_free_mnt_opts(&fc->security); kfree(fc->source); fc->source = NULL; -- 2.53.0