Commit a41dbf5
committed
mount: hold namespace_sem across copy in create_new_namespace()
Fix an oversight when creating a new mount namespace. If someone had the
bright idea to make the real rootfs a shared or dependent mount and it
is later copied the copy will become a peer of the old real rootfs mount
or a dependent mount of it. The namespace semaphore is dropped and we
use mount lock exact to lock the new real root mount. If that fails or
the subsequent do_loopback() fails we rely on the copy of the real root
mount to be cleaned up by path_put(). The problem is that this doesn't
deal with mount propagation and will leave the mounts linked in the
propagation lists.
When creating a new mount namespace create_new_namespace() first
acquires namespace_sem to clone the nullfs root, drops it, then
reacquires it via LOCK_MOUNT_EXACT which takes inode_lock first to
respect the inode_lock -> namespace_sem lock ordering. This
drop-and-reacquire pattern is fragile and was the source of the
propagation cleanup bug fixed in the preceding commit.
Extend lock_mount_exact() with a copy_mount mode that clones the mount
under the locks atomically. When copy_mount is true, path_overmounted()
is skipped since we're copying the mount, not mounting on top of it -
the nullfs root always has rootfs mounted on top so the check would
always fail. If clone_mnt() fails after get_mountpoint() has pinned the
mountpoint, __unlock_mount() is used to properly unpin the mountpoint
and release both locks.
This allows create_new_namespace() to use LOCK_MOUNT_EXACT_COPY which
takes inode_lock and namespace_sem once and holds them throughout the
clone and subsequent mount operations, eliminating the
drop-and-reacquire pattern entirely.
Reported-by: syzbot+a89f9434fb5a001ccd58@syzkaller.appspotmail.com
Fixes: 9b8a0ba ("mount: add OPEN_TREE_NAMESPACE") # mainline only
Link: https://lore.kernel.org/699047f6.050a0220.2757fb.0024.GAE@google.com
Signed-off-by: Christian Brauner <brauner@kernel.org>1 parent ac83896 commit a41dbf5
1 file changed
+57
-54
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
2791 | 2791 | | |
2792 | 2792 | | |
2793 | 2793 | | |
2794 | | - | |
| 2794 | + | |
| 2795 | + | |
2795 | 2796 | | |
2796 | 2797 | | |
2797 | 2798 | | |
2798 | 2799 | | |
2799 | 2800 | | |
2800 | 2801 | | |
2801 | 2802 | | |
2802 | | - | |
| 2803 | + | |
| 2804 | + | |
| 2805 | + | |
| 2806 | + | |
2803 | 2807 | | |
2804 | 2808 | | |
2805 | 2809 | | |
| |||
3073 | 3077 | | |
3074 | 3078 | | |
3075 | 3079 | | |
3076 | | - | |
3077 | | - | |
3078 | | - | |
3079 | 3080 | | |
3080 | 3081 | | |
3081 | | - | |
3082 | | - | |
3083 | 3082 | | |
3084 | 3083 | | |
3085 | | - | |
| 3084 | + | |
| 3085 | + | |
| 3086 | + | |
3086 | 3087 | | |
3087 | 3088 | | |
3088 | 3089 | | |
| |||
3094 | 3095 | | |
3095 | 3096 | | |
3096 | 3097 | | |
3097 | | - | |
3098 | | - | |
3099 | | - | |
3100 | | - | |
| 3098 | + | |
| 3099 | + | |
| 3100 | + | |
3101 | 3101 | | |
3102 | | - | |
3103 | | - | |
3104 | | - | |
3105 | | - | |
3106 | | - | |
3107 | | - | |
3108 | | - | |
3109 | | - | |
3110 | | - | |
3111 | | - | |
3112 | | - | |
| 3102 | + | |
| 3103 | + | |
| 3104 | + | |
| 3105 | + | |
| 3106 | + | |
| 3107 | + | |
3113 | 3108 | | |
| 3109 | + | |
3114 | 3110 | | |
3115 | 3111 | | |
3116 | | - | |
3117 | | - | |
3118 | | - | |
3119 | | - | |
3120 | | - | |
| 3112 | + | |
| 3113 | + | |
| 3114 | + | |
3121 | 3115 | | |
3122 | | - | |
3123 | | - | |
3124 | | - | |
3125 | | - | |
3126 | | - | |
3127 | | - | |
3128 | | - | |
3129 | | - | |
3130 | | - | |
| 3116 | + | |
| 3117 | + | |
| 3118 | + | |
| 3119 | + | |
| 3120 | + | |
| 3121 | + | |
3131 | 3122 | | |
3132 | 3123 | | |
3133 | | - | |
3134 | | - | |
3135 | | - | |
| 3124 | + | |
| 3125 | + | |
| 3126 | + | |
3136 | 3127 | | |
3137 | 3128 | | |
3138 | | - | |
3139 | | - | |
3140 | | - | |
3141 | 3129 | | |
| 3130 | + | |
| 3131 | + | |
| 3132 | + | |
| 3133 | + | |
| 3134 | + | |
| 3135 | + | |
3142 | 3136 | | |
3143 | 3137 | | |
3144 | 3138 | | |
3145 | | - | |
3146 | | - | |
| 3139 | + | |
| 3140 | + | |
3147 | 3141 | | |
3148 | 3142 | | |
3149 | 3143 | | |
3150 | 3144 | | |
3151 | 3145 | | |
3152 | 3146 | | |
3153 | | - | |
3154 | | - | |
3155 | | - | |
| 3147 | + | |
| 3148 | + | |
3156 | 3149 | | |
3157 | 3150 | | |
3158 | 3151 | | |
3159 | | - | |
| 3152 | + | |
3160 | 3153 | | |
3161 | | - | |
| 3154 | + | |
3162 | 3155 | | |
3163 | 3156 | | |
3164 | 3157 | | |
| |||
3840 | 3833 | | |
3841 | 3834 | | |
3842 | 3835 | | |
3843 | | - | |
| 3836 | + | |
| 3837 | + | |
3844 | 3838 | | |
3845 | 3839 | | |
3846 | 3840 | | |
3847 | 3841 | | |
| 3842 | + | |
| 3843 | + | |
| 3844 | + | |
3848 | 3845 | | |
3849 | 3846 | | |
3850 | 3847 | | |
3851 | 3848 | | |
3852 | | - | |
| 3849 | + | |
3853 | 3850 | | |
3854 | 3851 | | |
3855 | 3852 | | |
3856 | 3853 | | |
3857 | 3854 | | |
3858 | 3855 | | |
3859 | 3856 | | |
3860 | | - | |
3861 | | - | |
| 3857 | + | |
3862 | 3858 | | |
| 3859 | + | |
| 3860 | + | |
| 3861 | + | |
| 3862 | + | |
| 3863 | + | |
| 3864 | + | |
| 3865 | + | |
3863 | 3866 | | |
3864 | 3867 | | |
3865 | 3868 | | |
| |||
0 commit comments