Skip to content

Commit c4a1682

Browse files
committed
fs: add open_tree_attr()
Add open_tree_attr() which allow to atomically create a detached mount tree and set mount options on it. If OPEN_TREE_CLONE is used this will allow the creation of a detached mount with a new set of mount options without it ever being exposed to userspace without that set of mount options applied. Link: https://lore.kernel.org/r/[email protected] Reviewed-by: "Seth Forshee (DigitalOcean)" <[email protected]> Signed-off-by: Christian Brauner <[email protected]>
1 parent 474f782 commit c4a1682

File tree

20 files changed

+63
-1
lines changed

20 files changed

+63
-1
lines changed

arch/alpha/kernel/syscalls/syscall.tbl

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -506,3 +506,4 @@
506506
574 common getxattrat sys_getxattrat
507507
575 common listxattrat sys_listxattrat
508508
576 common removexattrat sys_removexattrat
509+
577 common open_tree_attr sys_open_tree_attr

arch/arm/tools/syscall.tbl

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -481,3 +481,4 @@
481481
464 common getxattrat sys_getxattrat
482482
465 common listxattrat sys_listxattrat
483483
466 common removexattrat sys_removexattrat
484+
467 common open_tree_attr sys_open_tree_attr

arch/arm64/tools/syscall_32.tbl

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -478,3 +478,4 @@
478478
464 common getxattrat sys_getxattrat
479479
465 common listxattrat sys_listxattrat
480480
466 common removexattrat sys_removexattrat
481+
467 common open_tree_attr sys_open_tree_attr

arch/m68k/kernel/syscalls/syscall.tbl

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -466,3 +466,4 @@
466466
464 common getxattrat sys_getxattrat
467467
465 common listxattrat sys_listxattrat
468468
466 common removexattrat sys_removexattrat
469+
467 common open_tree_attr sys_open_tree_attr

arch/microblaze/kernel/syscalls/syscall.tbl

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -472,3 +472,4 @@
472472
464 common getxattrat sys_getxattrat
473473
465 common listxattrat sys_listxattrat
474474
466 common removexattrat sys_removexattrat
475+
467 common open_tree_attr sys_open_tree_attr

arch/mips/kernel/syscalls/syscall_n32.tbl

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -405,3 +405,4 @@
405405
464 n32 getxattrat sys_getxattrat
406406
465 n32 listxattrat sys_listxattrat
407407
466 n32 removexattrat sys_removexattrat
408+
467 n32 open_tree_attr sys_open_tree_attr

arch/mips/kernel/syscalls/syscall_n64.tbl

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -381,3 +381,4 @@
381381
464 n64 getxattrat sys_getxattrat
382382
465 n64 listxattrat sys_listxattrat
383383
466 n64 removexattrat sys_removexattrat
384+
467 n64 open_tree_attr sys_open_tree_attr

arch/mips/kernel/syscalls/syscall_o32.tbl

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -454,3 +454,4 @@
454454
464 o32 getxattrat sys_getxattrat
455455
465 o32 listxattrat sys_listxattrat
456456
466 o32 removexattrat sys_removexattrat
457+
467 o32 open_tree_attr sys_open_tree_attr

arch/parisc/kernel/syscalls/syscall.tbl

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -465,3 +465,4 @@
465465
464 common getxattrat sys_getxattrat
466466
465 common listxattrat sys_listxattrat
467467
466 common removexattrat sys_removexattrat
468+
467 common open_tree_attr sys_open_tree_attr

arch/powerpc/kernel/syscalls/syscall.tbl

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -557,3 +557,4 @@
557557
464 common getxattrat sys_getxattrat
558558
465 common listxattrat sys_listxattrat
559559
466 common removexattrat sys_removexattrat
560+
467 common open_tree_attr sys_open_tree_attr

arch/s390/kernel/syscalls/syscall.tbl

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -469,3 +469,4 @@
469469
464 common getxattrat sys_getxattrat sys_getxattrat
470470
465 common listxattrat sys_listxattrat sys_listxattrat
471471
466 common removexattrat sys_removexattrat sys_removexattrat
472+
467 common open_tree_attr sys_open_tree_attr sys_open_tree_attr

arch/sh/kernel/syscalls/syscall.tbl

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -470,3 +470,4 @@
470470
464 common getxattrat sys_getxattrat
471471
465 common listxattrat sys_listxattrat
472472
466 common removexattrat sys_removexattrat
473+
467 common open_tree_attr sys_open_tree_attr

arch/sparc/kernel/syscalls/syscall.tbl

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -512,3 +512,4 @@
512512
464 common getxattrat sys_getxattrat
513513
465 common listxattrat sys_listxattrat
514514
466 common removexattrat sys_removexattrat
515+
467 common open_tree_attr sys_open_tree_attr

arch/x86/entry/syscalls/syscall_32.tbl

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -472,3 +472,4 @@
472472
464 i386 getxattrat sys_getxattrat
473473
465 i386 listxattrat sys_listxattrat
474474
466 i386 removexattrat sys_removexattrat
475+
467 i386 open_tree_attr sys_open_tree_attr

arch/x86/entry/syscalls/syscall_64.tbl

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -390,6 +390,7 @@
390390
464 common getxattrat sys_getxattrat
391391
465 common listxattrat sys_listxattrat
392392
466 common removexattrat sys_removexattrat
393+
467 common open_tree_attr sys_open_tree_attr
393394

394395
#
395396
# Due to a historical design error, certain syscalls are numbered differently

arch/xtensa/kernel/syscalls/syscall.tbl

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -437,3 +437,4 @@
437437
464 common getxattrat sys_getxattrat
438438
465 common listxattrat sys_listxattrat
439439
466 common removexattrat sys_removexattrat
440+
467 common open_tree_attr sys_open_tree_attr

fs/namespace.c

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4995,6 +4995,45 @@ SYSCALL_DEFINE5(mount_setattr, int, dfd, const char __user *, path,
49954995
return err;
49964996
}
49974997

4998+
SYSCALL_DEFINE5(open_tree_attr, int, dfd, const char __user *, filename,
4999+
unsigned, flags, struct mount_attr __user *, uattr,
5000+
size_t, usize)
5001+
{
5002+
struct file __free(fput) *file = NULL;
5003+
int fd;
5004+
5005+
if (!uattr && usize)
5006+
return -EINVAL;
5007+
5008+
file = vfs_open_tree(dfd, filename, flags);
5009+
if (IS_ERR(file))
5010+
return PTR_ERR(file);
5011+
5012+
if (uattr) {
5013+
int ret;
5014+
struct mount_kattr kattr = {
5015+
.recurse = !!(flags & AT_RECURSIVE),
5016+
};
5017+
5018+
ret = copy_mount_setattr(uattr, usize, &kattr);
5019+
if (ret)
5020+
return ret;
5021+
5022+
ret = do_mount_setattr(&file->f_path, &kattr);
5023+
if (ret)
5024+
return ret;
5025+
5026+
finish_mount_kattr(&kattr);
5027+
}
5028+
5029+
fd = get_unused_fd_flags(flags & O_CLOEXEC);
5030+
if (fd < 0)
5031+
return fd;
5032+
5033+
fd_install(fd, no_free_ptr(file));
5034+
return fd;
5035+
}
5036+
49985037
int show_path(struct seq_file *m, struct dentry *root)
49995038
{
50005039
if (root->d_sb->s_op->show_path)

include/linux/syscalls.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -951,6 +951,10 @@ asmlinkage long sys_statx(int dfd, const char __user *path, unsigned flags,
951951
asmlinkage long sys_rseq(struct rseq __user *rseq, uint32_t rseq_len,
952952
int flags, uint32_t sig);
953953
asmlinkage long sys_open_tree(int dfd, const char __user *path, unsigned flags);
954+
asmlinkage long sys_open_tree_attr(int dfd, const char __user *path,
955+
unsigned flags,
956+
struct mount_attr __user *uattr,
957+
size_t usize);
954958
asmlinkage long sys_move_mount(int from_dfd, const char __user *from_path,
955959
int to_dfd, const char __user *to_path,
956960
unsigned int ms_flags);

include/uapi/asm-generic/unistd.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -849,9 +849,11 @@ __SYSCALL(__NR_getxattrat, sys_getxattrat)
849849
__SYSCALL(__NR_listxattrat, sys_listxattrat)
850850
#define __NR_removexattrat 466
851851
__SYSCALL(__NR_removexattrat, sys_removexattrat)
852+
#define __NR_open_tree_attr 467
853+
__SYSCALL(__NR_open_tree_attr, sys_open_tree_attr)
852854

853855
#undef __NR_syscalls
854-
#define __NR_syscalls 467
856+
#define __NR_syscalls 468
855857

856858
/*
857859
* 32 bit systems traditionally used different

scripts/syscall.tbl

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -407,3 +407,4 @@
407407
464 common getxattrat sys_getxattrat
408408
465 common listxattrat sys_listxattrat
409409
466 common removexattrat sys_removexattrat
410+
467 common open_tree_attr sys_open_tree_attr

0 commit comments

Comments
 (0)