Skip to content

Commit 474f782

Browse files
committed
fs: add copy_mount_setattr() helper
Split out copy_mount_setattr() from mount_setattr() so we can use it in later patches. Link: https://lore.kernel.org/r/[email protected] Reviewed-by: "Seth Forshee (DigitalOcean)" <[email protected]> Signed-off-by: Christian Brauner <[email protected]>
1 parent 901766d commit 474f782

File tree

1 file changed

+40
-33
lines changed

1 file changed

+40
-33
lines changed

fs/namespace.c

Lines changed: 40 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -4814,7 +4814,7 @@ static int do_mount_setattr(struct path *path, struct mount_kattr *kattr)
48144814
}
48154815

48164816
static int build_mount_idmapped(const struct mount_attr *attr, size_t usize,
4817-
struct mount_kattr *kattr, unsigned int flags)
4817+
struct mount_kattr *kattr)
48184818
{
48194819
struct ns_common *ns;
48204820
struct user_namespace *mnt_userns;
@@ -4865,22 +4865,8 @@ static int build_mount_idmapped(const struct mount_attr *attr, size_t usize,
48654865
}
48664866

48674867
static int build_mount_kattr(const struct mount_attr *attr, size_t usize,
4868-
struct mount_kattr *kattr, unsigned int flags)
4868+
struct mount_kattr *kattr)
48694869
{
4870-
unsigned int lookup_flags = LOOKUP_AUTOMOUNT | LOOKUP_FOLLOW;
4871-
4872-
if (flags & AT_NO_AUTOMOUNT)
4873-
lookup_flags &= ~LOOKUP_AUTOMOUNT;
4874-
if (flags & AT_SYMLINK_NOFOLLOW)
4875-
lookup_flags &= ~LOOKUP_FOLLOW;
4876-
if (flags & AT_EMPTY_PATH)
4877-
lookup_flags |= LOOKUP_EMPTY;
4878-
4879-
*kattr = (struct mount_kattr) {
4880-
.lookup_flags = lookup_flags,
4881-
.recurse = !!(flags & AT_RECURSIVE),
4882-
};
4883-
48844870
if (attr->propagation & ~MOUNT_SETATTR_PROPAGATION_FLAGS)
48854871
return -EINVAL;
48864872
if (hweight32(attr->propagation & MOUNT_SETATTR_PROPAGATION_FLAGS) > 1)
@@ -4928,7 +4914,7 @@ static int build_mount_kattr(const struct mount_attr *attr, size_t usize,
49284914
return -EINVAL;
49294915
}
49304916

4931-
return build_mount_idmapped(attr, usize, kattr, flags);
4917+
return build_mount_idmapped(attr, usize, kattr);
49324918
}
49334919

49344920
static void finish_mount_kattr(struct mount_kattr *kattr)
@@ -4940,23 +4926,14 @@ static void finish_mount_kattr(struct mount_kattr *kattr)
49404926
mnt_idmap_put(kattr->mnt_idmap);
49414927
}
49424928

4943-
SYSCALL_DEFINE5(mount_setattr, int, dfd, const char __user *, path,
4944-
unsigned int, flags, struct mount_attr __user *, uattr,
4945-
size_t, usize)
4929+
static int copy_mount_setattr(struct mount_attr __user *uattr, size_t usize,
4930+
struct mount_kattr *kattr)
49464931
{
4947-
int err;
4948-
struct path target;
4932+
int ret;
49494933
struct mount_attr attr;
4950-
struct mount_kattr kattr;
49514934

49524935
BUILD_BUG_ON(sizeof(struct mount_attr) != MOUNT_ATTR_SIZE_VER0);
49534936

4954-
if (flags & ~(AT_EMPTY_PATH |
4955-
AT_RECURSIVE |
4956-
AT_SYMLINK_NOFOLLOW |
4957-
AT_NO_AUTOMOUNT))
4958-
return -EINVAL;
4959-
49604937
if (unlikely(usize > PAGE_SIZE))
49614938
return -E2BIG;
49624939
if (unlikely(usize < MOUNT_ATTR_SIZE_VER0))
@@ -4965,17 +4942,47 @@ SYSCALL_DEFINE5(mount_setattr, int, dfd, const char __user *, path,
49654942
if (!may_mount())
49664943
return -EPERM;
49674944

4968-
err = copy_struct_from_user(&attr, sizeof(attr), uattr, usize);
4969-
if (err)
4970-
return err;
4945+
ret = copy_struct_from_user(&attr, sizeof(attr), uattr, usize);
4946+
if (ret)
4947+
return ret;
49714948

49724949
/* Don't bother walking through the mounts if this is a nop. */
49734950
if (attr.attr_set == 0 &&
49744951
attr.attr_clr == 0 &&
49754952
attr.propagation == 0)
49764953
return 0;
49774954

4978-
err = build_mount_kattr(&attr, usize, &kattr, flags);
4955+
return build_mount_kattr(&attr, usize, kattr);
4956+
}
4957+
4958+
SYSCALL_DEFINE5(mount_setattr, int, dfd, const char __user *, path,
4959+
unsigned int, flags, struct mount_attr __user *, uattr,
4960+
size_t, usize)
4961+
{
4962+
int err;
4963+
struct path target;
4964+
struct mount_kattr kattr;
4965+
unsigned int lookup_flags = LOOKUP_AUTOMOUNT | LOOKUP_FOLLOW;
4966+
4967+
if (flags & ~(AT_EMPTY_PATH |
4968+
AT_RECURSIVE |
4969+
AT_SYMLINK_NOFOLLOW |
4970+
AT_NO_AUTOMOUNT))
4971+
return -EINVAL;
4972+
4973+
if (flags & AT_NO_AUTOMOUNT)
4974+
lookup_flags &= ~LOOKUP_AUTOMOUNT;
4975+
if (flags & AT_SYMLINK_NOFOLLOW)
4976+
lookup_flags &= ~LOOKUP_FOLLOW;
4977+
if (flags & AT_EMPTY_PATH)
4978+
lookup_flags |= LOOKUP_EMPTY;
4979+
4980+
kattr = (struct mount_kattr) {
4981+
.lookup_flags = lookup_flags,
4982+
.recurse = !!(flags & AT_RECURSIVE),
4983+
};
4984+
4985+
err = copy_mount_setattr(uattr, usize, &kattr);
49794986
if (err)
49804987
return err;
49814988

0 commit comments

Comments
 (0)