WSL2-Linux-Kernel/fs/xfs
Dave Chinner e44e240d53 xfs: read only mounts with fsopen mount API are busted
commit d8d222e09dab84a17bb65dda4b94d01c565f5327 upstream.

Recently xfs/513 started failing on my test machines testing "-o
ro,norecovery" mount options. This was being emitted in dmesg:

[ 9906.932724] XFS (pmem0): no-recovery mounts must be read-only.

Turns out, readonly mounts with the fsopen()/fsconfig() mount API
have been busted since day zero. It's only taken 5 years for debian
unstable to start using this "new" mount API, and shortly after this
I noticed xfs/513 had started to fail as per above.

The syscall trace is:

fsopen("xfs", FSOPEN_CLOEXEC)           = 3
mount_setattr(-1, NULL, 0, NULL, 0)     = -1 EINVAL (Invalid argument)
.....
fsconfig(3, FSCONFIG_SET_STRING, "source", "/dev/pmem0", 0) = 0
fsconfig(3, FSCONFIG_SET_FLAG, "ro", NULL, 0) = 0
fsconfig(3, FSCONFIG_SET_FLAG, "norecovery", NULL, 0) = 0
fsconfig(3, FSCONFIG_CMD_CREATE, NULL, NULL, 0) = -1 EINVAL (Invalid argument)
close(3)                                = 0

Showing that the actual mount instantiation (FSCONFIG_CMD_CREATE) is
what threw out the error.

During mount instantiation, we call xfs_fs_validate_params() which
does:

        /* No recovery flag requires a read-only mount */
        if (xfs_has_norecovery(mp) && !xfs_is_readonly(mp)) {
                xfs_warn(mp, "no-recovery mounts must be read-only.");
                return -EINVAL;
        }

and xfs_is_readonly() checks internal mount flags for read only
state. This state is set in xfs_init_fs_context() from the
context superblock flag state:

        /*
         * Copy binary VFS mount flags we are interested in.
         */
        if (fc->sb_flags & SB_RDONLY)
                set_bit(XFS_OPSTATE_READONLY, &mp->m_opstate);

With the old mount API, all of the VFS specific superblock flags
had already been parsed and set before xfs_init_fs_context() is
called, so this all works fine.

However, in the brave new fsopen/fsconfig world,
xfs_init_fs_context() is called from fsopen() context, before any
VFS superblock have been set or parsed. Hence if we use fsopen(),
the internal XFS readonly state is *never set*. Hence anything that
depends on xfs_is_readonly() actually returning true for read only
mounts is broken if fsopen() has been used to mount the filesystem.

Fix this by moving this internal state initialisation to
xfs_fs_fill_super() before we attempt to validate the parameters
that have been set prior to the FSCONFIG_CMD_CREATE call being made.

Signed-off-by: Dave Chinner <dchinner@redhat.com>
Fixes: 73e5fff98b ("xfs: switch to use the new mount-api")
cc: stable@vger.kernel.org
Reviewed-by: Christoph Hellwig <hch@lst.de>
Signed-off-by: Chandan Babu R <chandanbabu@kernel.org>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
2024-02-23 08:54:32 +01:00
..
libxfs xfs: fix exception caused by unexpected illegal bestcount in leaf dir 2023-11-28 16:56:26 +00:00
scrub xfs: disable reaping in fscounters scrub 2023-10-06 13:18:10 +02:00
Kconfig
Makefile
kmem.c
kmem.h
mrlock.h
xfs.h
xfs_acl.c
xfs_acl.h
xfs_aops.c
xfs_aops.h
xfs_attr_inactive.c xfs: fix use-after-free in xattr node block inactivation 2023-11-28 16:56:25 +00:00
xfs_attr_list.c
xfs_bio_io.c
xfs_bmap_item.c xfs: fix potential log item leak 2023-02-22 12:57:03 +01:00
xfs_bmap_item.h
xfs_bmap_util.c xfs: set prealloc flag in xfs_alloc_file_space() 2023-03-17 08:49:00 +01:00
xfs_bmap_util.h
xfs_buf.c
xfs_buf.h
xfs_buf_item.c
xfs_buf_item.h
xfs_buf_item_recover.c xfs: convert buf_cancel_table allocation to kmalloc_array 2023-11-28 16:56:25 +00:00
xfs_dir2_readdir.c
xfs_discard.c
xfs_discard.h
xfs_dquot.c
xfs_dquot.h
xfs_dquot_item.c
xfs_dquot_item.h
xfs_dquot_item_recover.c
xfs_error.c xfs: fix memory leak in xfs_errortag_init 2023-11-28 16:56:26 +00:00
xfs_error.h
xfs_export.c
xfs_export.h
xfs_extent_busy.c
xfs_extent_busy.h
xfs_extfree_item.c
xfs_extfree_item.h
xfs_file.c xfs: set prealloc flag in xfs_alloc_file_space() 2023-03-17 08:49:00 +01:00
xfs_filestream.c xfs: fix soft lockup via spinning in filestream ag selection loop 2022-08-25 11:40:48 +02:00
xfs_filestream.h
xfs_fsmap.c
xfs_fsmap.h
xfs_fsops.c xfs: fix overfilling of reserve pool 2022-08-25 11:40:48 +02:00
xfs_fsops.h
xfs_globals.c
xfs_health.c
xfs_icache.c xfs: fix xfs_inodegc_stop racing with mod_delayed_work 2023-10-06 13:18:10 +02:00
xfs_icache.h xfs: introduce xfs_inodegc_push() 2023-10-06 13:18:09 +02:00
xfs_icreate_item.c xfs: fix potential log item leak 2023-02-22 12:57:03 +01:00
xfs_icreate_item.h
xfs_inode.c xfs: use invalidate_lock to check the state of mmap_lock 2023-11-28 16:56:25 +00:00
xfs_inode.h
xfs_inode_item.c
xfs_inode_item.h
xfs_inode_item_recover.c
xfs_ioctl.c xfs: reject crazy array sizes being fed to XFS_IOC_GETBMAP* 2022-08-25 11:40:48 +02:00
xfs_ioctl.h
xfs_ioctl32.c
xfs_ioctl32.h
xfs_iomap.c
xfs_iomap.h
xfs_iops.c xfs: don't expose internal symlink metadata buffers to the vfs 2023-10-25 11:58:54 +02:00
xfs_iops.h xfs: remove xfs_setattr_time() declaration 2023-03-17 08:49:04 +01:00
xfs_itable.c
xfs_itable.h
xfs_iwalk.c
xfs_iwalk.h
xfs_linux.h
xfs_log.c xfs: prevent a UAF when log IO errors race with unmount 2023-11-28 16:56:25 +00:00
xfs_log.h
xfs_log_cil.c
xfs_log_priv.h xfs: refactor buffer cancellation table allocation 2023-11-28 16:56:25 +00:00
xfs_log_recover.c xfs: avoid a UAF when log intent item recovery fails 2023-11-28 16:56:26 +00:00
xfs_message.c
xfs_message.h
xfs_mount.c
xfs_mount.h xfs: check that per-cpu inodegc workers actually run on that cpu 2023-10-06 13:18:10 +02:00
xfs_mru_cache.c
xfs_mru_cache.h
xfs_ondisk.h
xfs_pnfs.c xfs: remove XFS_PREALLOC_SYNC 2023-03-17 08:48:59 +01:00
xfs_pnfs.h
xfs_pwork.c
xfs_pwork.h
xfs_qm.c xfs: fix intermittent hang during quotacheck 2023-11-28 16:56:26 +00:00
xfs_qm.h
xfs_qm_bhv.c
xfs_qm_syscalls.c xfs: introduce xfs_inodegc_push() 2023-10-06 13:18:09 +02:00
xfs_quota.h
xfs_quotaops.c
xfs_refcount_item.c xfs: fix potential log item leak 2023-02-22 12:57:03 +01:00
xfs_refcount_item.h
xfs_reflink.c xfs: Fix false ENOSPC when performing direct write on a delalloc extent in cow fork 2023-11-28 16:56:26 +00:00
xfs_reflink.h
xfs_rmap_item.c xfs: fix potential log item leak 2023-02-22 12:57:03 +01:00
xfs_rmap_item.h
xfs_rtalloc.c
xfs_rtalloc.h
xfs_stats.c
xfs_stats.h
xfs_super.c xfs: read only mounts with fsopen mount API are busted 2024-02-23 08:54:32 +01:00
xfs_super.h
xfs_symlink.c xfs: don't expose internal symlink metadata buffers to the vfs 2023-10-25 11:58:54 +02:00
xfs_symlink.h
xfs_sysctl.c
xfs_sysctl.h
xfs_sysfs.c
xfs_sysfs.h xfs: Fix unreferenced object reported by kmemleak in xfs_sysfs_init() 2023-11-28 16:56:26 +00:00
xfs_trace.c
xfs_trace.h xfs: introduce xfs_inodegc_push() 2023-10-06 13:18:09 +02:00
xfs_trans.c
xfs_trans.h
xfs_trans_ail.c
xfs_trans_buf.c
xfs_trans_dquot.c xfs: revert "xfs: actually bump warning counts when we send warnings" 2022-08-25 11:40:48 +02:00
xfs_trans_priv.h
xfs_xattr.c