Christian Brauner 344bac8f0d
fs: kill MNT_ONRB
Move mnt->mnt_node into the union with mnt->mnt_rcu and mnt->mnt_llist
instead of keeping it with mnt->mnt_list. This allows us to use
RB_CLEAR_NODE(&mnt->mnt_node) in umount_tree() as well as
list_empty(&mnt->mnt_node). That in turn allows us to remove MNT_ONRB.

This also fixes the bug reported in [1] where seemingly MNT_ONRB wasn't
set in @mnt->mnt_flags even though the mount was present in the mount
rbtree of the mount namespace.

The root cause is the following race. When a btrfs subvolume is mounted
a temporary mount is created:

btrfs_get_tree_subvol()
{
        mnt = fc_mount()
        // Register the newly allocated mount with sb->mounts:
        lock_mount_hash();
        list_add_tail(&mnt->mnt_instance, &mnt->mnt.mnt_sb->s_mounts);
        unlock_mount_hash();
}

and registered on sb->s_mounts. Later it is added to an anonymous mount
namespace via mount_subvol():

-> mount_subvol()
   -> mount_subtree()
      -> alloc_mnt_ns()
         mnt_add_to_ns()
         vfs_path_lookup()
         put_mnt_ns()

The mnt_add_to_ns() call raises MNT_ONRB in @mnt->mnt_flags. If someone
concurrently does a ro remount:

reconfigure_super()
-> sb_prepare_remount_readonly()
   {
           list_for_each_entry(mnt, &sb->s_mounts, mnt_instance) {
   }

all mounts registered in sb->s_mounts are visited and first
MNT_WRITE_HOLD is raised, then MNT_READONLY is raised, and finally
MNT_WRITE_HOLD is removed again.

The flag modification for MNT_WRITE_HOLD/MNT_READONLY and MNT_ONRB race
so MNT_ONRB might be lost.

Fixes: 2eea9ce4310d ("mounts: keep list of mounts in an rbtree")
Cc: <stable@kernel.org> # v6.8+
Link: https://lore.kernel.org/r/20241215-vfs-6-14-mount-work-v1-1-fd55922c4af8@kernel.org
Link: https://lore.kernel.org/r/ec6784ed-8722-4695-980a-4400d4e7bd1a@gmx.com [1]
Signed-off-by: Christian Brauner <brauner@kernel.org>
2025-01-09 16:58:50 +01:00
..
2024-11-01 07:37:10 -10:00
2024-11-22 12:33:52 -08:00
2024-07-15 11:14:59 -07:00
2024-11-26 13:39:02 -08:00
2024-11-25 17:08:27 +09:00
2024-09-16 09:14:02 +02:00
2024-11-26 12:50:58 -08:00
2024-10-17 00:28:06 -07:00
2024-11-27 13:11:58 -08:00
2024-11-26 12:34:50 -08:00
2024-11-18 09:35:30 -08:00
2024-11-26 18:15:06 +01:00
2024-11-26 12:59:30 -08:00
2024-11-30 10:17:53 -08:00
2024-11-26 12:59:30 -08:00
\n
2024-11-21 09:55:45 -08:00
2024-11-22 20:55:42 -08:00
2024-11-27 08:11:46 -08:00
2024-09-19 10:18:15 +02:00
2024-05-28 11:52:53 +02:00
\n
2024-11-21 09:50:18 -08:00
2024-08-21 22:32:58 +02:00
2024-11-30 10:14:42 -08:00
2024-11-22 20:50:55 -08:00
2024-10-02 12:02:15 -07:00
2024-11-03 01:28:06 -05:00
2024-11-21 08:28:08 -08:00
2024-11-26 13:26:15 -08:00
2024-11-18 10:30:29 -08:00
2024-11-18 10:45:06 -08:00
2024-11-03 01:28:06 -05:00
2024-11-03 01:28:06 -05:00
2024-10-21 16:29:38 +02:00
2024-11-03 01:28:06 -05:00
2024-10-21 16:29:38 +02:00
2024-09-24 15:29:42 -07:00
2025-01-09 16:58:50 +01:00
2025-01-09 16:58:50 +01:00
2024-09-27 08:18:43 -07:00
\n
2024-11-21 09:55:45 -08:00
2024-10-24 13:54:51 +02:00
2024-09-27 08:18:43 -07:00
2024-11-03 01:28:07 -05:00
2024-11-03 01:28:07 -05:00
2024-11-03 01:28:06 -05:00
2024-11-03 01:28:06 -05:00
2024-11-03 01:28:06 -05:00
2024-11-03 01:28:06 -05:00