@@ -1767,6 +1767,19 @@ bool may_mount(void)
1767
1767
return ns_capable (current -> nsproxy -> mnt_ns -> user_ns , CAP_SYS_ADMIN );
1768
1768
}
1769
1769
1770
+ /**
1771
+ * path_mounted - check whether path is mounted
1772
+ * @path: path to check
1773
+ *
1774
+ * Determine whether @path refers to the root of a mount.
1775
+ *
1776
+ * Return: true if @path is the root of a mount, false if not.
1777
+ */
1778
+ static inline bool path_mounted (const struct path * path )
1779
+ {
1780
+ return path -> mnt -> mnt_root == path -> dentry ;
1781
+ }
1782
+
1770
1783
static void warn_mandlock (void )
1771
1784
{
1772
1785
pr_warn_once ("=======================================================\n"
@@ -1782,7 +1795,7 @@ static int can_umount(const struct path *path, int flags)
1782
1795
1783
1796
if (!may_mount ())
1784
1797
return - EPERM ;
1785
- if (path -> dentry != path -> mnt -> mnt_root )
1798
+ if (! path_mounted ( path ) )
1786
1799
return - EINVAL ;
1787
1800
if (!check_mnt (mnt ))
1788
1801
return - EINVAL ;
@@ -2367,7 +2380,7 @@ static int do_change_type(struct path *path, int ms_flags)
2367
2380
int type ;
2368
2381
int err = 0 ;
2369
2382
2370
- if (path -> dentry != path -> mnt -> mnt_root )
2383
+ if (! path_mounted ( path ) )
2371
2384
return - EINVAL ;
2372
2385
2373
2386
type = flags_to_propagation_type (ms_flags );
@@ -2643,7 +2656,7 @@ static int do_reconfigure_mnt(struct path *path, unsigned int mnt_flags)
2643
2656
if (!check_mnt (mnt ))
2644
2657
return - EINVAL ;
2645
2658
2646
- if (path -> dentry != mnt -> mnt . mnt_root )
2659
+ if (! path_mounted ( path ) )
2647
2660
return - EINVAL ;
2648
2661
2649
2662
if (!can_change_locked_flags (mnt , mnt_flags ))
@@ -2682,7 +2695,7 @@ static int do_remount(struct path *path, int ms_flags, int sb_flags,
2682
2695
if (!check_mnt (mnt ))
2683
2696
return - EINVAL ;
2684
2697
2685
- if (path -> dentry != path -> mnt -> mnt_root )
2698
+ if (! path_mounted ( path ) )
2686
2699
return - EINVAL ;
2687
2700
2688
2701
if (!can_change_locked_flags (mnt , mnt_flags ))
@@ -2772,9 +2785,9 @@ static int do_set_group(struct path *from_path, struct path *to_path)
2772
2785
2773
2786
err = - EINVAL ;
2774
2787
/* To and From paths should be mount roots */
2775
- if (from_path -> dentry != from_path -> mnt -> mnt_root )
2788
+ if (! path_mounted ( from_path ) )
2776
2789
goto out ;
2777
- if (to_path -> dentry != to_path -> mnt -> mnt_root )
2790
+ if (! path_mounted ( to_path ) )
2778
2791
goto out ;
2779
2792
2780
2793
/* Setting sharing groups is only allowed across same superblock */
@@ -2855,7 +2868,7 @@ static int do_move_mount(struct path *old_path, struct path *new_path)
2855
2868
if (old -> mnt .mnt_flags & MNT_LOCKED )
2856
2869
goto out ;
2857
2870
2858
- if (old_path -> dentry != old_path -> mnt -> mnt_root )
2871
+ if (! path_mounted ( old_path ) )
2859
2872
goto out ;
2860
2873
2861
2874
if (d_is_dir (new_path -> dentry ) !=
@@ -2937,8 +2950,7 @@ static int do_add_mount(struct mount *newmnt, struct mountpoint *mp,
2937
2950
}
2938
2951
2939
2952
/* Refuse the same filesystem on the same mount point */
2940
- if (path -> mnt -> mnt_sb == newmnt -> mnt .mnt_sb &&
2941
- path -> mnt -> mnt_root == path -> dentry )
2953
+ if (path -> mnt -> mnt_sb == newmnt -> mnt .mnt_sb && path_mounted (path ))
2942
2954
return - EBUSY ;
2943
2955
2944
2956
if (d_is_symlink (newmnt -> mnt .mnt_root ))
@@ -3917,11 +3929,11 @@ SYSCALL_DEFINE2(pivot_root, const char __user *, new_root,
3917
3929
if (new_mnt == root_mnt || old_mnt == root_mnt )
3918
3930
goto out4 ; /* loop, on the same file system */
3919
3931
error = - EINVAL ;
3920
- if (root . mnt -> mnt_root != root . dentry )
3932
+ if (! path_mounted ( & root ) )
3921
3933
goto out4 ; /* not a mountpoint */
3922
3934
if (!mnt_has_parent (root_mnt ))
3923
3935
goto out4 ; /* not attached */
3924
- if (new . mnt -> mnt_root != new . dentry )
3936
+ if (! path_mounted ( & new ) )
3925
3937
goto out4 ; /* not a mountpoint */
3926
3938
if (!mnt_has_parent (new_mnt ))
3927
3939
goto out4 ; /* not attached */
@@ -4124,7 +4136,7 @@ static int do_mount_setattr(struct path *path, struct mount_kattr *kattr)
4124
4136
struct mount * mnt = real_mount (path -> mnt );
4125
4137
int err = 0 ;
4126
4138
4127
- if (path -> dentry != mnt -> mnt . mnt_root )
4139
+ if (! path_mounted ( path ) )
4128
4140
return - EINVAL ;
4129
4141
4130
4142
if (kattr -> mnt_userns ) {
0 commit comments