linux-stable/arch/microblaze/kernel
Christian Brauner 2a1867219c
fs: add mount_setattr()
This implements the missing mount_setattr() syscall. While the new mount
api allows to change the properties of a superblock there is currently
no way to change the properties of a mount or a mount tree using file
descriptors which the new mount api is based on. In addition the old
mount api has the restriction that mount options cannot be applied
recursively. This hasn't changed since changing mount options on a
per-mount basis was implemented in [1] and has been a frequent request
not just for convenience but also for security reasons. The legacy
mount syscall is unable to accommodate this behavior without introducing
a whole new set of flags because MS_REC | MS_REMOUNT | MS_BIND |
MS_RDONLY | MS_NOEXEC | [...] only apply the mount option to the topmost
mount. Changing MS_REC to apply to the whole mount tree would mean
introducing a significant uapi change and would likely cause significant
regressions.

The new mount_setattr() syscall allows to recursively clear and set
mount options in one shot. Multiple calls to change mount options
requesting the same changes are idempotent:

int mount_setattr(int dfd, const char *path, unsigned flags,
                  struct mount_attr *uattr, size_t usize);

Flags to modify path resolution behavior are specified in the @flags
argument. Currently, AT_EMPTY_PATH, AT_RECURSIVE, AT_SYMLINK_NOFOLLOW,
and AT_NO_AUTOMOUNT are supported. If useful, additional lookup flags to
restrict path resolution as introduced with openat2() might be supported
in the future.

The mount_setattr() syscall can be expected to grow over time and is
designed with extensibility in mind. It follows the extensible syscall
pattern we have used with other syscalls such as openat2(), clone3(),
sched_{set,get}attr(), and others.
The set of mount options is passed in the uapi struct mount_attr which
currently has the following layout:

struct mount_attr {
	__u64 attr_set;
	__u64 attr_clr;
	__u64 propagation;
	__u64 userns_fd;
};

The @attr_set and @attr_clr members are used to clear and set mount
options. This way a user can e.g. request that a set of flags is to be
raised such as turning mounts readonly by raising MOUNT_ATTR_RDONLY in
@attr_set while at the same time requesting that another set of flags is
to be lowered such as removing noexec from a mount tree by specifying
MOUNT_ATTR_NOEXEC in @attr_clr.

Note, since the MOUNT_ATTR_<atime> values are an enum starting from 0,
not a bitmap, users wanting to transition to a different atime setting
cannot simply specify the atime setting in @attr_set, but must also
specify MOUNT_ATTR__ATIME in the @attr_clr field. So we ensure that
MOUNT_ATTR__ATIME can't be partially set in @attr_clr and that @attr_set
can't have any atime bits set if MOUNT_ATTR__ATIME isn't set in
@attr_clr.

The @propagation field lets callers specify the propagation type of a
mount tree. Propagation is a single property that has four different
settings and as such is not really a flag argument but an enum.
Specifically, it would be unclear what setting and clearing propagation
settings in combination would amount to. The legacy mount() syscall thus
forbids the combination of multiple propagation settings too. The goal
is to keep the semantics of mount propagation somewhat simple as they
are overly complex as it is.

The @userns_fd field lets user specify a user namespace whose idmapping
becomes the idmapping of the mount. This is implemented and explained in
detail in the next patch.

[1]: commit 2e4b7fcd92 ("[PATCH] r/o bind mounts: honor mount writer counts at remount")

Link: https://lore.kernel.org/r/20210121131959.646623-35-christian.brauner@ubuntu.com
Cc: David Howells <dhowells@redhat.com>
Cc: Aleksa Sarai <cyphar@cyphar.com>
Cc: Al Viro <viro@zeniv.linux.org.uk>
Cc: linux-fsdevel@vger.kernel.org
Cc: linux-api@vger.kernel.org
Reviewed-by: Christoph Hellwig <hch@lst.de>
Signed-off-by: Christian Brauner <christian.brauner@ubuntu.com>
2021-01-24 14:42:45 +01:00
..
cpu microblaze: Add missing irqflags.h header 2020-02-25 12:33:19 +01:00
syscalls fs: add mount_setattr() 2021-01-24 14:42:45 +01:00
.gitignore .gitignore: add SPDX License Identifier 2020-03-25 11:50:48 +01:00
asm-offsets.c microblaze: Remove noMMU code 2020-11-26 16:39:35 +01:00
dma.c dma-mapping: merge <linux/dma-noncoherent.h> into <linux/dma-map-ops.h> 2020-10-06 07:07:06 +02:00
entry.S microblaze: Fix _reset() function 2020-02-25 12:26:18 +01:00
exceptions.c microblaze: Remove noMMU code 2020-11-26 16:39:35 +01:00
ftrace.c microblaze: function_graph: Simplify with function_graph_enter() 2018-11-27 20:30:18 -05:00
head.S microblaze: Remove noMMU code 2020-11-26 16:39:35 +01:00
hw_exception_handler.S microblaze: Remove noMMU code 2020-11-26 16:39:35 +01:00
irq.c Revert "irqchip/xilinx: Enable generic irq multi handler" 2020-04-01 09:12:24 +01:00
kgdb.c kgdb/treewide: constify struct kgdb_arch arch_kgdb_ops 2018-12-30 08:33:06 +00:00
Makefile microblaze: Remove noMMU code 2020-11-26 16:39:35 +01:00
mcount.S
microblaze_ksyms.c microblaze: Remove noMMU code 2020-11-26 16:39:35 +01:00
misc.S microblaze: Add sync to tlb operations 2020-02-25 12:33:19 +01:00
module.c mm: reorder includes after introduction of linux/pgtable.h 2020-06-09 09:39:13 -07:00
process.c Microblaze patches for 5.11-rc1 2020-12-16 12:04:39 -08:00
prom.c treewide: Replace GPLv2 boilerplate/reference with SPDX - rule 152 2019-05-30 11:26:32 -07:00
ptrace.c sched/headers: Prepare for new header dependencies before moving code to <linux/sched/task_stack.h> 2017-03-02 08:42:36 +01:00
reset.c microblaze: Switch to standard restart handler 2019-09-19 10:43:32 +02:00
setup.c microblaze: Remove noMMU code 2020-11-26 16:39:35 +01:00
signal.c microblaze: Remove noMMU code 2020-11-26 16:39:35 +01:00
stacktrace.c microblaze: add loglvl to microblaze_unwind() 2020-06-09 09:39:11 -07:00
sys_microblaze.c mm: add ksys_mmap_pgoff() helper; remove in-kernel calls to sys_mmap_pgoff() 2018-04-02 20:16:11 +02:00
syscall_table.S microblaze: generate uapi header and system call table files 2018-11-16 08:24:34 +01:00
timer.c microblaze: Replace setup_irq() by request_irq() 2020-03-09 14:36:23 +01:00
traps.c kernel: rename show_stack_loglvl() => show_stack() 2020-06-09 09:39:13 -07:00
unwind.c microblaze: Remove noMMU code 2020-11-26 16:39:35 +01:00
vmlinux.lds.S microblaze: Define percpu sestion in linker file 2020-02-25 12:33:19 +01:00