filesystems selftests cleanups and fanotify test
Subsystems (4)
v2 cover filesystems selftests cleanups and fanotify test
Christian,
This adds a test for fanotify mount ns notifications inside userns [1].
While working on the test I ended up making lots of cleanups to reduce build dependency on make headers_install.
These patches got rid of the dependency for my kvm setup for the affected filesystems tests.
Building with TOOLS_INCLUDES dir was recommended by John Hubbard [2].
NOTE #1: these patches are based on a merge of vfs-6.16.mount (changes wrappers.h) into v6.15-rc5 (changes mount-notify_test.c), so if this cleanup is acceptable, we should probably setup a selftests branch for 6.16, so that it can be used to test the fanotify patches.
NOTE #2: some of the defines in wrappers.h are left for overlayfs and mount_setattr tests, which were not converted to use TOOLS_INCLUDES. I did not want to mess with those tests.
Thanks,
Amir.
Changes since v1:
- Add test for fanotify mntns watch in userns
- Fix some braino in statmount_test_ns re-factoring
- Add cleanups to pidfd and mount_setattr tests
- Add syscall number defs for more archs
- Mention some more changes in commit messages
- Use ksft_print_msg() in helpers
- RVB from John Hubbard
[1] https://lore.kernel.org/linux-fsdevel/[email protected]/
[2] https://lore.kernel.org/linux-fsdevel/[email protected]/
Amir Goldstein (8):
selftests/filesystems: move wrapper.h out of overlayfs subdir selftests/fs/statmount: build with tools include dir selftests/pidfd: move syscall definitions into wrappers.h selftests/mount_settattr: remove duplicate syscall definitions selftests/fs/mount-notify: build with tools include dir selftests/filesystems: create get_unique_mnt_id() helper selftests/filesystems: create setup_userns() helper selftests/fs/mount-notify: add a test variant running inside userns
tools/include/uapi/linux/fanotify.h | 274 +++++++++
tools/include/uapi/linux/mount.h | 235 ++++++++
tools/include/uapi/linux/nsfs.h | 45 ++
.../filesystems/mount-notify/.gitignore | 1 +
.../filesystems/mount-notify/Makefile | 9 +-
.../mount-notify/mount-notify_test.c | 38 +-
.../mount-notify/mount-notify_test_ns.c | 557 ++++++++++++++++++
.../selftests/filesystems/overlayfs/Makefile | 2 +-
.../filesystems/overlayfs/dev_in_maps.c | 2 +-
.../overlayfs/set_layers_via_fds.c | 2 +-
.../selftests/filesystems/statmount/Makefile | 6 +-
.../filesystems/statmount/statmount.h | 36 ++
.../filesystems/statmount/statmount_test_ns.c | 86 +--
tools/testing/selftests/filesystems/utils.c | 88 +++
tools/testing/selftests/filesystems/utils.h | 3 +
.../filesystems/{overlayfs => }/wrappers.h | 42 +-
.../testing/selftests/mount_setattr/Makefile | 2 +
.../mount_setattr/mount_setattr_test.c | 54 +-
.../selftests/pidfd/pidfd_bind_mount.c | 74 +--
19 files changed, 1312 insertions(+), 244 deletions(-)
create mode 100644 tools/include/uapi/linux/fanotify.h
create mode 100644 tools/include/uapi/linux/mount.h
create mode 100644 tools/include/uapi/linux/nsfs.h
create mode 100644 tools/testing/selftests/filesystems/mount-notify/mount-notify_test_ns.c
rename tools/testing/selftests/filesystems/{overlayfs => }/wrappers.h (62%)Signature · 1 line
2.34.1
PATCH v2 1/8 selftests/filesystems: move wrapper.h out of overlayfs subdir
This is not an overlayfs specific header.
---
tools/testing/selftests/filesystems/overlayfs/Makefile | 2 +-
tools/testing/selftests/filesystems/overlayfs/dev_in_maps.c | 2 +-
.../selftests/filesystems/overlayfs/set_layers_via_fds.c | 2 +-
tools/testing/selftests/filesystems/{overlayfs => }/wrappers.h | 0
tools/testing/selftests/mount_setattr/Makefile | 2 ++
tools/testing/selftests/mount_setattr/mount_setattr_test.c | 2 +-
6 files changed, 6 insertions(+), 4 deletions(-)
rename tools/testing/selftests/filesystems/{overlayfs => }/wrappers.h (100%)tools/testing/selftests/filesystems/overlayfs/Makefile +1 -1
@@ -4,7 +4,7 @@ CFLAGS += -Wall CFLAGS += $(KHDR_INCLUDES) LDLIBS += -lcap -LOCAL_HDRS += wrappers.h log.h +LOCAL_HDRS += ../wrappers.h log.h TEST_GEN_PROGS := dev_in_maps TEST_GEN_PROGS += set_layers_via_fds
tools/testing/selftests/filesystems/overlayfs/dev_in_maps.c +1 -1
@@ -17,7 +17,7 @@#include "../../kselftest.h" #include "log.h" -#include "wrappers.h" +#include "../wrappers.h" static long get_file_dev_and_inode (void *addr,struct statx *stx) {
tools/testing/selftests/filesystems/overlayfs/set_layers_via_fds.c +1 -1
@@ -16,7 +16,7 @@#include "../../pidfd/pidfd.h" #include "log.h" #include "../utils.h" -#include "wrappers.h" +#include "../wrappers.h" FIXTURE (set_layers_via_fds) {int pidfd;
tools/testing/selftests/filesystems/wrappers.h renamed from tools/testing/selftests/filesystems/overlayfs/wrappers.h +0 -0
tools/testing/selftests/mount_setattr/Makefile +2 -0
@@ -2,6 +2,8 @@ # Makefile for mount selftests. CFLAGS = -g $(KHDR_INCLUDES) -Wall -O2 -pthread +LOCAL_HDRS += ../filesystems/wrappers.h + TEST_GEN_PROGS := mount_setattr_test include ../lib.mk
tools/testing/selftests/mount_setattr/mount_setattr_test.c +1 -1
@@ -20,7 +20,7 @@#include <stdarg.h> #include <linux/mount.h> -#include "../filesystems/overlayfs/wrappers.h" +#include "../filesystems/wrappers.h" #include "../kselftest_harness.h" #ifndef CLONE_NEWNS
Signature · 1 line
2.34.1
Re: [PATCH v2 1/8] selftests/filesystems: move wrapper.h out of overlayfs subdir
Quoted 5 lines · Amir Goldstein
This is not an overlayfs specific header.
Reviewed-by John Hubbard <[email protected]>Signed-off-by Amir Goldstein <[email protected]>---
Thanks for cleaning this up for me :)
PATCH v2 2/8 selftests/fs/statmount: build with tools include dir
In reply to Amir GoldsteinCopy the required headers files (mount.h, nsfs.h) to the tools include dir and define the statmount/listmount syscall numbers to decouple dependency with headers_install for the common cases.
--- tools/include/uapi/linux/mount.h | 235 ++++++++++++++++++ tools/include/uapi/linux/nsfs.h | 45 ++++ .../selftests/filesystems/statmount/Makefile | 3 +- .../filesystems/statmount/statmount.h | 36 +++ 4 files changed, 318 insertions(+), 1 deletion(-) create mode 100644 tools/include/uapi/linux/mount.h create mode 100644 tools/include/uapi/linux/nsfs.h
tools/include/uapi/linux/mount.h new file +235 -0
@@ -0,0 +1,235 @@ +#ifndef _UAPI_LINUX_MOUNT_H +#define _UAPI_LINUX_MOUNT_H + +#include <linux/types.h> + +/* +* These are the fs-independent mount-flags: up to 32 flags are supported +* +* Usage of these is restricted within the kernel to core mount(2) code and +* callers of sys_mount() only. Filesystems should be using the SB_* +* equivalent instead. +*/ +#define MS_RDONLY 1/* Mount read-only */ +#define MS_NOSUID 2/* Ignore suid and sgid bits */ +#define MS_NODEV 4/* Disallow access to device special files */ +#define MS_NOEXEC 8/* Disallow program execution */ +#define MS_SYNCHRONOUS 16/* Writes are synced at once */ +#define MS_REMOUNT 32/* Alter flags of a mounted FS */ +#define MS_MANDLOCK 64/* Allow mandatory locks on an FS */ +#define MS_DIRSYNC 128/* Directory modifications are synchronous */ +#define MS_NOSYMFOLLOW 256/* Do not follow symlinks */ +#define MS_NOATIME 1024/* Do not update access times. */ +#define MS_NODIRATIME 2048/* Do not update directory access times */ +#define MS_BIND 4096 +#define MS_MOVE 8192 +#define MS_REC 16384 +#define MS_VERBOSE 32768/* War is peace. Verbosity is silence. +MS_VERBOSE is deprecated. */ +#define MS_SILENT 32768 +#define MS_POSIXACL (1<<16)/* VFS does not apply the umask */ +#define MS_UNBINDABLE (1<<17)/* change to unbindable */ +#define MS_PRIVATE (1<<18)/* change to private */ +#define MS_SLAVE (1<<19)/* change to slave */ +#define MS_SHARED (1<<20)/* change to shared */ +#define MS_RELATIME (1<<21)/* Update atime relative to mtime/ctime. */ +#define MS_KERNMOUNT (1<<22)/* this is a kern_mount call */ +#define MS_I_VERSION (1<<23)/* Update inode I_version field */ +#define MS_STRICTATIME (1<<24)/* Always perform atime updates */ +#define MS_LAZYTIME (1<<25)/* Update the on-disk [acm]times lazily */ + +/* These sb flags are internal to the kernel */ +#define MS_SUBMOUNT (1<<26) +#define MS_NOREMOTELOCK (1<<27) +#define MS_NOSEC (1<<28) +#define MS_BORN (1<<29) +#define MS_ACTIVE (1<<30) +#define MS_NOUSER (1<<31) + +/* +* Superblock flags that can be altered by MS_REMOUNT +*/ +#define MS_RMT_MASK (MS_RDONLY|MS_SYNCHRONOUS|MS_MANDLOCK|MS_I_VERSION|\ + MS_LAZYTIME) + +/* +* Old magic mount flag and mask +*/ +#define MS_MGC_VAL 0xC0ED0000 +#define MS_MGC_MSK 0xffff0000 + +/* +* open_tree() flags. +*/ +#define OPEN_TREE_CLONE 1/* Clone the target tree and attach the clone */ +#define OPEN_TREE_CLOEXEC O_CLOEXEC/* Close the file on execve() */ + +/* +* move_mount() flags. +*/ +#define MOVE_MOUNT_F_SYMLINKS 0x00000001/* Follow symlinks on from path */ +#define MOVE_MOUNT_F_AUTOMOUNTS 0x00000002/* Follow automounts on from path */ +#define MOVE_MOUNT_F_EMPTY_PATH 0x00000004/* Empty from path permitted */ +#define MOVE_MOUNT_T_SYMLINKS 0x00000010/* Follow symlinks on to path */ +#define MOVE_MOUNT_T_AUTOMOUNTS 0x00000020/* Follow automounts on to path */ +#define MOVE_MOUNT_T_EMPTY_PATH 0x00000040/* Empty to path permitted */ +#define MOVE_MOUNT_SET_GROUP 0x00000100/* Set sharing group instead */ +#define MOVE_MOUNT_BENEATH 0x00000200/* Mount beneath top mount */ +#define MOVE_MOUNT__MASK 0x00000377 + +/* +* fsopen() flags. +*/ +#define FSOPEN_CLOEXEC 0x00000001 + +/* +* fspick() flags. +*/ +#define FSPICK_CLOEXEC 0x00000001 +#define FSPICK_SYMLINK_NOFOLLOW 0x00000002 +#define FSPICK_NO_AUTOMOUNT 0x00000004 +#define FSPICK_EMPTY_PATH 0x00000008 + +/* +* The type of fsconfig() call made. +*/ +enum fsconfig_command { +FSCONFIG_SET_FLAG =0 ,/* Set parameter, supplying no value */ +FSCONFIG_SET_STRING =1 ,/* Set parameter, supplying a string value */ +FSCONFIG_SET_BINARY =2 ,/* Set parameter, supplying a binary blob value */ +FSCONFIG_SET_PATH =3 ,/* Set parameter, supplying an object by path */ +FSCONFIG_SET_PATH_EMPTY =4 ,/* Set parameter, supplying an object by (empty) path */ +FSCONFIG_SET_FD =5 ,/* Set parameter, supplying an object by fd */ +FSCONFIG_CMD_CREATE =6 ,/* Create new or reuse existing superblock */ +FSCONFIG_CMD_RECONFIGURE =7 ,/* Invoke superblock reconfiguration */ +FSCONFIG_CMD_CREATE_EXCL =8 ,/* Create new superblock, fail if reusing existing superblock */ +}; + +/* +* fsmount() flags. +*/ +#define FSMOUNT_CLOEXEC 0x00000001 + +/* +* Mount attributes. +*/ +#define MOUNT_ATTR_RDONLY 0x00000001/* Mount read-only */ +#define MOUNT_ATTR_NOSUID 0x00000002/* Ignore suid and sgid bits */ +#define MOUNT_ATTR_NODEV 0x00000004/* Disallow access to device special files */ +#define MOUNT_ATTR_NOEXEC 0x00000008/* Disallow program execution */ +#define MOUNT_ATTR__ATIME 0x00000070/* Setting on how atime should be updated */ +#define MOUNT_ATTR_RELATIME 0x00000000/* - Update atime relative to mtime/ctime. */ +#define MOUNT_ATTR_NOATIME 0x00000010/* - Do not update access times. */ +#define MOUNT_ATTR_STRICTATIME 0x00000020/* - Always perform atime updates */ +#define MOUNT_ATTR_NODIRATIME 0x00000080/* Do not update directory access times */ +#define MOUNT_ATTR_IDMAP 0x00100000/* Idmap mount to @userns_fd in struct mount_attr. */ +#define MOUNT_ATTR_NOSYMFOLLOW 0x00200000/* Do not follow symlinks */ + +/* +* mount_setattr() +*/ +struct mount_attr { +__u64 attr_set; +__u64 attr_clr; +__u64 propagation; +__u64 userns_fd; +}; + +/* List of all mount_attr versions. */ +#define MOUNT_ATTR_SIZE_VER0 32/* sizeof first published struct */ + + +/* +* Structure for getting mount/superblock/filesystem info with statmount(2). +* +* The interface is similar to statx(2): individual fields or groups can be +* selected with the @mask argument of statmount(). Kernel will set the @mask +* field according to the supported fields. +* +* If string fields are selected, then the caller needs to pass a buffer that +* has space after the fixed part of the structure. Nul terminated strings are +* copied there and offsets relative to @str are stored in the relevant fields. +* If the buffer is too small, then EOVERFLOW is returned. The actually used +* size is returned in @size. +*/ +struct statmount { +__u32 size;/* Total size, including strings */ +__u32 mnt_opts;/* [str] Options (comma separated, escaped) */ +__u64 mask;/* What results were written */ +__u32 sb_dev_major;/* Device ID */ +__u32 sb_dev_minor; +__u64 sb_magic;/* ..._SUPER_MAGIC */ +__u32 sb_flags;/* SB_{RDONLY,SYNCHRONOUS,DIRSYNC,LAZYTIME} */ +__u32 fs_type;/* [str] Filesystem type */ +__u64 mnt_id;/* Unique ID of mount */ +__u64 mnt_parent_id;/* Unique ID of parent (for root == mnt_id) */ +__u32 mnt_id_old;/* Reused IDs used in proc/.../mountinfo */ +__u32 mnt_parent_id_old; +__u64 mnt_attr;/* MOUNT_ATTR_... */ +__u64 mnt_propagation;/* MS_{SHARED,SLAVE,PRIVATE,UNBINDABLE} */ +__u64 mnt_peer_group;/* ID of shared peer group */ +__u64 mnt_master;/* Mount receives propagation from this ID */ +__u64 propagate_from;/* Propagation from in current namespace */ +__u32 mnt_root;/* [str] Root of mount relative to root of fs */ +__u32 mnt_point;/* [str] Mountpoint relative to current root */ +__u64 mnt_ns_id;/* ID of the mount namespace */ +__u32 fs_subtype;/* [str] Subtype of fs_type (if any) */ +__u32 sb_source;/* [str] Source string of the mount */ +__u32 opt_num;/* Number of fs options */ +__u32 opt_array;/* [str] Array of nul terminated fs options */ +__u32 opt_sec_num;/* Number of security options */ +__u32 opt_sec_array;/* [str] Array of nul terminated security options */ +__u64 supported_mask;/* Mask flags that this kernel supports */ +__u32 mnt_uidmap_num;/* Number of uid mappings */ +__u32 mnt_uidmap;/* [str] Array of uid mappings (as seen from callers namespace) */ +__u32 mnt_gidmap_num;/* Number of gid mappings */ +__u32 mnt_gidmap;/* [str] Array of gid mappings (as seen from callers namespace) */ +__u64 __spare2[43 ]; +char str[];/* Variable size part containing strings */ +}; + +/* +* Structure for passing mount ID and miscellaneous parameters to statmount(2) +* and listmount(2). +* +* For statmount(2) @param represents the request mask. +* For listmount(2) @param represents the last listed mount id (or zero). +*/ +struct mnt_id_req { +__u32 size; +__u32 spare; +__u64 mnt_id; +__u64 param; +__u64 mnt_ns_id; +}; + +/* List of all mnt_id_req versions. */ +#define MNT_ID_REQ_SIZE_VER0 24/* sizeof first published struct */ +#define MNT_ID_REQ_SIZE_VER1 32/* sizeof second published struct */ + +/* +* @mask bits for statmount(2) +*/ +#define STATMOUNT_SB_BASIC 0x00000001U/* Want/got sb_... */ +#define STATMOUNT_MNT_BASIC 0x00000002U/* Want/got mnt_... */ +#define STATMOUNT_PROPAGATE_FROM 0x00000004U/* Want/got propagate_from */ +#define STATMOUNT_MNT_ROOT 0x00000008U/* Want/got mnt_root */ +#define STATMOUNT_MNT_POINT 0x00000010U/* Want/got mnt_point */ +#define STATMOUNT_FS_TYPE 0x00000020U/* Want/got fs_type */ +#define STATMOUNT_MNT_NS_ID 0x00000040U/* Want/got mnt_ns_id */ +#define STATMOUNT_MNT_OPTS 0x00000080U/* Want/got mnt_opts */ +#define STATMOUNT_FS_SUBTYPE 0x00000100U/* Want/got fs_subtype */ +#define STATMOUNT_SB_SOURCE 0x00000200U/* Want/got sb_source */ +#define STATMOUNT_OPT_ARRAY 0x00000400U/* Want/got opt_... */ +#define STATMOUNT_OPT_SEC_ARRAY 0x00000800U/* Want/got opt_sec... */ +#define STATMOUNT_SUPPORTED_MASK 0x00001000U/* Want/got supported mask flags */ +#define STATMOUNT_MNT_UIDMAP 0x00002000U/* Want/got uidmap... */ +#define STATMOUNT_MNT_GIDMAP 0x00004000U/* Want/got gidmap... */ + +/* +* Special @mnt_id values that can be passed to listmount +*/ +#define LSMT_ROOT 0xffffffffffffffff/* root mount */ +#define LISTMOUNT_REVERSE (1 << 0)/* List later mounts first */ + +#endif /* _UAPI_LINUX_MOUNT_H */
tools/include/uapi/linux/nsfs.h new file +45 -0
45 lines not on this page · raw message
tools/testing/selftests/filesystems/statmount/Makefile +2 -1
@@ -1,6 +1,7 @@ # SPDX-License-Identifier: GPL-2.0-or-later -CFLAGS += -Wall -O2 -g $(KHDR_INCLUDES) +CFLAGS += -Wall -O2 -g $(KHDR_INCLUDES) $(TOOLS_INCLUDES) + TEST_GEN_PROGS := statmount_test statmount_test_ns listmount_test include ../../lib.mk
tools/testing/selftests/filesystems/statmount/statmount.h +36 -0
@@ -7,6 +7,42 @@#include <linux/mount.h> #include <asm/unistd.h> +#ifndef __NR_statmount +#if defined __alpha__ +#define __NR_statmount 567 +#elif defined _MIPS_SIM +#if _MIPS_SIM == _MIPS_SIM_ABI32/* o32 */ +#define __NR_statmount 4457 +#endif +#if _MIPS_SIM == _MIPS_SIM_NABI32/* n32 */ +#define __NR_statmount 6457 +#endif +#if _MIPS_SIM == _MIPS_SIM_ABI64/* n64 */ +#define __NR_statmount 5457 +#endif +#else +#define __NR_statmount 457 +#endif +#endif + +#ifndef __NR_listmount +#if defined __alpha__ +#define __NR_listmount 568 +#elif defined _MIPS_SIM +#if _MIPS_SIM == _MIPS_SIM_ABI32/* o32 */ +#define __NR_listmount 4458 +#endif +#if _MIPS_SIM == _MIPS_SIM_NABI32/* n32 */ +#define __NR_listmount 6458 +#endif +#if _MIPS_SIM == _MIPS_SIM_ABI64/* n64 */ +#define __NR_listmount 5458 +#endif +#else +#define __NR_listmount 458 +#endif +#endif +static inline int statmount (uint64_t mnt_id,uint64_t mnt_ns_id,uint64_t mask,struct statmount *buf,size_t bufsize,unsigned int flags)
Signature · 1 line
2.34.1
Re: [PATCH v2 2/8] selftests/fs/statmount: build with tools include dir
Quoted 7 lines · Amir Goldstein
Copy the required headers files (
mount.h,nsfs.h) to the tools include dir and define the statmount/listmount syscall numbers to decouple dependency withheaders_installfor the common cases.Reviewed-by John Hubbard <[email protected]>Signed-off-by Amir Goldstein <[email protected]>---
PATCH v2 3/8 selftests/pidfd: move syscall definitions into wrappers.h
In reply to Amir GoldsteinThere was already duplicity in some of the defintions.
Remove syscall number defintions for __ia64__ that are both stale and incorrect.
--- .../testing/selftests/filesystems/wrappers.h | 42 ++++++++++- .../selftests/pidfd/pidfd_bind_mount.c | 74 +------------------ 2 files changed, 42 insertions(+), 74 deletions(-)
tools/testing/selftests/filesystems/wrappers.h +41 -1
@@ -40,6 +40,28 @@ static inline int sys_mount(const char *src, const char *tgt, const char *fst,#define MOVE_MOUNT_F_EMPTY_PATH 0x00000004/* Empty from path permitted */ #endif +#ifndef MOVE_MOUNT_T_EMPTY_PATH +#define MOVE_MOUNT_T_EMPTY_PATH 0x00000040/* Empty to path permitted */ +#endif + +#ifndef __NR_move_mount +#if defined __alpha__ +#define __NR_move_mount 539 +#elif defined _MIPS_SIM +#if _MIPS_SIM == _MIPS_SIM_ABI32/* o32 */ +#define __NR_move_mount 4429 +#endif +#if _MIPS_SIM == _MIPS_SIM_NABI32/* n32 */ +#define __NR_move_mount 6429 +#endif +#if _MIPS_SIM == _MIPS_SIM_ABI64/* n64 */ +#define __NR_move_mount 5429 +#endif +#else +#define __NR_move_mount 429 +#endif +#endif +static inline int sys_move_mount (int from_dfd,const char *from_pathname,int to_dfd,const char *to_pathname,unsigned int flags)
@@ -57,7 +79,25 @@ static inline int sys_move_mount(int from_dfd, const char *from_pathname,#endif #ifndef AT_RECURSIVE -#define AT_RECURSIVE 0x8000 +#define AT_RECURSIVE 0x8000/* Apply to the entire subtree */ +#endif + +#ifndef __NR_open_tree +#if defined __alpha__ +#define __NR_open_tree 538 +#elif defined _MIPS_SIM +#if _MIPS_SIM == _MIPS_SIM_ABI32/* o32 */ +#define __NR_open_tree 4428 +#endif +#if _MIPS_SIM == _MIPS_SIM_NABI32/* n32 */ +#define __NR_open_tree 6428 +#endif +#if _MIPS_SIM == _MIPS_SIM_ABI64/* n64 */ +#define __NR_open_tree 5428 +#endif +#else +#define __NR_open_tree 428 +#endif #endif static inline int sys_open_tree (int dfd,const char *filename,unsigned int flags)
tools/testing/selftests/pidfd/pidfd_bind_mount.c +1 -73
80 lines not on this page · raw message
Signature · 1 line
2.34.1
Re: [PATCH v2 3/8] selftests/pidfd: move syscall definitions into wrappers.h
Quoted 7 lines · Amir Goldstein
There was already duplicity in some of the defintions.
Remove syscall number defintions for
__ia64__that are both stale and incorrect.Signed-off-by Amir Goldstein <[email protected]>---
PATCH v2 4/8 selftests/mount_settattr: remove duplicate syscall definitions
In reply to Amir GoldsteinWhich are already defined in wrappers.h.
For now, the syscall defintions of mount_settattr() itself remain in the test, which is the only test to use them.
--- .../mount_setattr/mount_setattr_test.c | 52 ------------------- 1 file changed, 52 deletions(-)
tools/testing/selftests/mount_setattr/mount_setattr_test.c +0 -52
@@ -107,46 +107,6 @@#endif #endif -#ifndef __NR_open_tree -#if defined __alpha__ -#define __NR_open_tree 538 -#elif defined _MIPS_SIM -#if _MIPS_SIM == _MIPS_SIM_ABI32/* o32 */ -#define __NR_open_tree 4428 -#endif -#if _MIPS_SIM == _MIPS_SIM_NABI32/* n32 */ -#define __NR_open_tree 6428 -#endif -#if _MIPS_SIM == _MIPS_SIM_ABI64/* n64 */ -#define __NR_open_tree 5428 -#endif -#elif defined __ia64__ -#define __NR_open_tree (428 + 1024) -#else -#define __NR_open_tree 428 -#endif -#endif - -#ifndef __NR_move_mount -#if defined __alpha__ -#define __NR_move_mount 539 -#elif defined _MIPS_SIM -#if _MIPS_SIM == _MIPS_SIM_ABI32/* o32 */ -#define __NR_move_mount 4429 -#endif -#if _MIPS_SIM == _MIPS_SIM_NABI32/* n32 */ -#define __NR_move_mount 6429 -#endif -#if _MIPS_SIM == _MIPS_SIM_ABI64/* n64 */ -#define __NR_move_mount 5429 -#endif -#elif defined __ia64__ -#define __NR_move_mount (428 + 1024) -#else -#define __NR_move_mount 429 -#endif -#endif -#ifndef MOUNT_ATTR_IDMAP #define MOUNT_ATTR_IDMAP 0x00100000#endif
@@ -161,18 +121,6 @@ static inline int sys_mount_setattr(int dfd, const char *path, unsigned int flagreturn syscall (__NR_mount_setattr, dfd, path, flags, attr, size); } -#ifndef OPEN_TREE_CLONE -#define OPEN_TREE_CLONE 1 -#endif - -#ifndef OPEN_TREE_CLOEXEC -#define OPEN_TREE_CLOEXEC O_CLOEXEC -#endif - -#ifndef AT_RECURSIVE -#define AT_RECURSIVE 0x8000/* Apply to the entire subtree */ -#endif -static ssize_t write_nointr (int fd,const void *buf,size_t count) {ssize_t ret;
Signature · 1 line
2.34.1
Re: [PATCH v2 4/8] selftests/mount_settattr: remove duplicate syscall definitions
Quoted 7 lines · Amir Goldstein
Which are already defined in
wrappers.h.For now, the syscall defintions of
mount_settattr()itself remain in the test, which is the only test to use them.Signed-off-by Amir Goldstein <[email protected]>---
PATCH v2 5/8 selftests/fs/mount-notify: build with tools include dir
In reply to Amir GoldsteinCopy the fanotify uapi header files to the tools include dir and define __kernel_fsid_t to decouple dependency with headers_install and then remove the redundant re-definitions of fanotify macros.
--- tools/include/uapi/linux/fanotify.h | 274 ++++++++++++++++++ .../filesystems/mount-notify/Makefile | 3 +- .../mount-notify/mount-notify_test.c | 25 +- 3 files changed, 282 insertions(+), 20 deletions(-) create mode 100644 tools/include/uapi/linux/fanotify.h
tools/include/uapi/linux/fanotify.h new file +274 -0
@@ -0,0 +1,274 @@ +/* SPDX-License-Identifier: GPL-2.0 WITH Linux-syscall-note */ +#ifndef _UAPI_LINUX_FANOTIFY_H +#define _UAPI_LINUX_FANOTIFY_H + +#include <linux/types.h> + +/* the following events that user-space can register for */ +#define FAN_ACCESS 0x00000001/* File was accessed */ +#define FAN_MODIFY 0x00000002/* File was modified */ +#define FAN_ATTRIB 0x00000004/* Metadata changed */ +#define FAN_CLOSE_WRITE 0x00000008/* Writable file closed */ +#define FAN_CLOSE_NOWRITE 0x00000010/* Unwritable file closed */ +#define FAN_OPEN 0x00000020/* File was opened */ +#define FAN_MOVED_FROM 0x00000040/* File was moved from X */ +#define FAN_MOVED_TO 0x00000080/* File was moved to Y */ +#define FAN_CREATE 0x00000100/* Subfile was created */ +#define FAN_DELETE 0x00000200/* Subfile was deleted */ +#define FAN_DELETE_SELF 0x00000400/* Self was deleted */ +#define FAN_MOVE_SELF 0x00000800/* Self was moved */ +#define FAN_OPEN_EXEC 0x00001000/* File was opened for exec */ + +#define FAN_Q_OVERFLOW 0x00004000/* Event queued overflowed */ +#define FAN_FS_ERROR 0x00008000/* Filesystem error */ + +#define FAN_OPEN_PERM 0x00010000/* File open in perm check */ +#define FAN_ACCESS_PERM 0x00020000/* File accessed in perm check */ +#define FAN_OPEN_EXEC_PERM 0x00040000/* File open/exec in perm check */ +/* #define FAN_DIR_MODIFY 0x00080000 */ /* Deprecated (reserved) */ + +#define FAN_PRE_ACCESS 0x00100000/* Pre-content access hook */ +#define FAN_MNT_ATTACH 0x01000000/* Mount was attached */ +#define FAN_MNT_DETACH 0x02000000/* Mount was detached */ + +#define FAN_EVENT_ON_CHILD 0x08000000/* Interested in child events */ + +#define FAN_RENAME 0x10000000/* File was renamed */ + +#define FAN_ONDIR 0x40000000/* Event occurred against dir */ + +/* helper events */ +#define FAN_CLOSE (FAN_CLOSE_WRITE | FAN_CLOSE_NOWRITE)/* close */ +#define FAN_MOVE (FAN_MOVED_FROM | FAN_MOVED_TO)/* moves */ + +/* flags used for fanotify_init() */ +#define FAN_CLOEXEC 0x00000001 +#define FAN_NONBLOCK 0x00000002 + +/* These are NOT bitwise flags. Both bits are used together. */ +#define FAN_CLASS_NOTIF 0x00000000 +#define FAN_CLASS_CONTENT 0x00000004 +#define FAN_CLASS_PRE_CONTENT 0x00000008 + +/* Deprecated - do not use this in programs and do not add new flags here! */ +#define FAN_ALL_CLASS_BITS (FAN_CLASS_NOTIF | FAN_CLASS_CONTENT | \ + FAN_CLASS_PRE_CONTENT) + +#define FAN_UNLIMITED_QUEUE 0x00000010 +#define FAN_UNLIMITED_MARKS 0x00000020 +#define FAN_ENABLE_AUDIT 0x00000040 + +/* Flags to determine fanotify event format */ +#define FAN_REPORT_PIDFD 0x00000080/* Report pidfd for event->pid */ +#define FAN_REPORT_TID 0x00000100/* event->pid is thread id */ +#define FAN_REPORT_FID 0x00000200/* Report unique file id */ +#define FAN_REPORT_DIR_FID 0x00000400/* Report unique directory id */ +#define FAN_REPORT_NAME 0x00000800/* Report events with name */ +#define FAN_REPORT_TARGET_FID 0x00001000/* Report dirent target id */ +#define FAN_REPORT_FD_ERROR 0x00002000/* event->fd can report error */ +#define FAN_REPORT_MNT 0x00004000/* Report mount events */ + +/* Convenience macro - FAN_REPORT_NAME requires FAN_REPORT_DIR_FID */ +#define FAN_REPORT_DFID_NAME (FAN_REPORT_DIR_FID | FAN_REPORT_NAME) +/* Convenience macro - FAN_REPORT_TARGET_FID requires all other FID flags */ +#define FAN_REPORT_DFID_NAME_TARGET (FAN_REPORT_DFID_NAME | \ + FAN_REPORT_FID | FAN_REPORT_TARGET_FID) + +/* Deprecated - do not use this in programs and do not add new flags here! */ +#define FAN_ALL_INIT_FLAGS (FAN_CLOEXEC | FAN_NONBLOCK | \ + FAN_ALL_CLASS_BITS | FAN_UNLIMITED_QUEUE |\ + FAN_UNLIMITED_MARKS) + +/* flags used for fanotify_modify_mark() */ +#define FAN_MARK_ADD 0x00000001 +#define FAN_MARK_REMOVE 0x00000002 +#define FAN_MARK_DONT_FOLLOW 0x00000004 +#define FAN_MARK_ONLYDIR 0x00000008 +/* FAN_MARK_MOUNT is 0x00000010 */ +#define FAN_MARK_IGNORED_MASK 0x00000020 +#define FAN_MARK_IGNORED_SURV_MODIFY 0x00000040 +#define FAN_MARK_FLUSH 0x00000080 +/* FAN_MARK_FILESYSTEM is 0x00000100 */ +#define FAN_MARK_EVICTABLE 0x00000200 +/* This bit is mutually exclusive with FAN_MARK_IGNORED_MASK bit */ +#define FAN_MARK_IGNORE 0x00000400 + +/* These are NOT bitwise flags. Both bits can be used togther. */ +#define FAN_MARK_INODE 0x00000000 +#define FAN_MARK_MOUNT 0x00000010 +#define FAN_MARK_FILESYSTEM 0x00000100 +#define FAN_MARK_MNTNS 0x00000110 + +/* +* Convenience macro - FAN_MARK_IGNORE requires FAN_MARK_IGNORED_SURV_MODIFY +* for non-inode mark types. +*/ +#define FAN_MARK_IGNORE_SURV (FAN_MARK_IGNORE | FAN_MARK_IGNORED_SURV_MODIFY) + +/* Deprecated - do not use this in programs and do not add new flags here! */ +#define FAN_ALL_MARK_FLAGS (FAN_MARK_ADD |\ + FAN_MARK_REMOVE |\ + FAN_MARK_DONT_FOLLOW |\ + FAN_MARK_ONLYDIR |\ + FAN_MARK_MOUNT |\ + FAN_MARK_IGNORED_MASK |\ + FAN_MARK_IGNORED_SURV_MODIFY |\ + FAN_MARK_FLUSH) + +/* Deprecated - do not use this in programs and do not add new flags here! */ +#define FAN_ALL_EVENTS (FAN_ACCESS |\ + FAN_MODIFY |\ + FAN_CLOSE |\ + FAN_OPEN) + +/* +* All events which require a permission response from userspace +*/ +/* Deprecated - do not use this in programs and do not add new flags here! */ +#define FAN_ALL_PERM_EVENTS (FAN_OPEN_PERM |\ + FAN_ACCESS_PERM) + +/* Deprecated - do not use this in programs and do not add new flags here! */ +#define FAN_ALL_OUTGOING_EVENTS (FAN_ALL_EVENTS |\ + FAN_ALL_PERM_EVENTS |\ + FAN_Q_OVERFLOW) + +#define FANOTIFY_METADATA_VERSION 3 + +struct fanotify_event_metadata { +__u32 event_len; +__u8 vers; +__u8 reserved; +__u16 metadata_len; +__aligned_u64 mask; +__s32 fd; +__s32 pid; +}; + +#define FAN_EVENT_INFO_TYPE_FID 1 +#define FAN_EVENT_INFO_TYPE_DFID_NAME 2 +#define FAN_EVENT_INFO_TYPE_DFID 3 +#define FAN_EVENT_INFO_TYPE_PIDFD 4 +#define FAN_EVENT_INFO_TYPE_ERROR 5 +#define FAN_EVENT_INFO_TYPE_RANGE 6 +#define FAN_EVENT_INFO_TYPE_MNT 7 + +/* Special info types for FAN_RENAME */ +#define FAN_EVENT_INFO_TYPE_OLD_DFID_NAME 10 +/* Reserved for FAN_EVENT_INFO_TYPE_OLD_DFID 11 */ +#define FAN_EVENT_INFO_TYPE_NEW_DFID_NAME 12 +/* Reserved for FAN_EVENT_INFO_TYPE_NEW_DFID 13 */ + +/* Variable length info record following event metadata */ +struct fanotify_event_info_header { +__u8 info_type; +__u8 pad; +__u16 len; +}; + +/* +* Unique file identifier info record. +* This structure is used for records of types FAN_EVENT_INFO_TYPE_FID, +* FAN_EVENT_INFO_TYPE_DFID and FAN_EVENT_INFO_TYPE_DFID_NAME. +* For FAN_EVENT_INFO_TYPE_DFID_NAME there is additionally a null terminated +* name immediately after the file handle. +*/ +struct fanotify_event_info_fid { +struct fanotify_event_info_header hdr; +__kernel_fsid_t fsid; +/* +* Following is an opaque struct file_handle that can be passed as +* an argument to open_by_handle_at(2). +*/ +unsigned char handle[]; +}; + +/* +* This structure is used for info records of type FAN_EVENT_INFO_TYPE_PIDFD. +* It holds a pidfd for the pid that was responsible for generating an event. +*/ +struct fanotify_event_info_pidfd { +struct fanotify_event_info_header hdr; +__s32 pidfd; +}; + +struct fanotify_event_info_error { +struct fanotify_event_info_header hdr; +__s32 error; +__u32 error_count; +}; + +struct fanotify_event_info_range { +struct fanotify_event_info_header hdr; +__u32 pad; +__u64 offset; +__u64 count; +}; + +struct fanotify_event_info_mnt { +struct fanotify_event_info_header hdr; +__u64 mnt_id; +}; + +/* +* User space may need to record additional information about its decision. +* The extra information type records what kind of information is included. +* The default is none. We also define an extra information buffer whose +* size is determined by the extra information type. +* +* If the information type is Audit Rule, then the information following +* is the rule number that triggered the user space decision that +* requires auditing. +*/ + +#define FAN_RESPONSE_INFO_NONE 0 +#define FAN_RESPONSE_INFO_AUDIT_RULE 1 + +struct fanotify_response { +__s32 fd; +__u32 response; +}; + +struct fanotify_response_info_header { +__u8 type; +__u8 pad; +__u16 len; +}; + +struct fanotify_response_info_audit_rule { +struct fanotify_response_info_header hdr; +__u32 rule_number; +__u32 subj_trust; +__u32 obj_trust; +}; + +/* Legit userspace responses to a _PERM event */ +#define FAN_ALLOW 0x01 +#define FAN_DENY 0x02 +/* errno other than EPERM can specified in upper byte of deny response */ +#define FAN_ERRNO_BITS 8 +#define FAN_ERRNO_SHIFT (32 - FAN_ERRNO_BITS) +#define FAN_ERRNO_MASK ((1 << FAN_ERRNO_BITS) - 1) +#define FAN_DENY_ERRNO (err) \ + (FAN_DENY | ((((__u32)(err)) & FAN_ERRNO_MASK) << FAN_ERRNO_SHIFT)) + +#define FAN_AUDIT 0x10/* Bitmask to create audit record for result */ +#define FAN_INFO 0x20/* Bitmask to indicate additional information */ + +/* No fd set in event */ +#define FAN_NOFD -1 +#define FAN_NOPIDFD FAN_NOFD +#define FAN_EPIDFD -2 + +/* Helper functions to deal with fanotify_event_metadata buffers */ +#define FAN_EVENT_METADATA_LEN (sizeof(struct fanotify_event_metadata)) + +#define FAN_EVENT_NEXT (meta, len) ((len) -= (meta)->event_len, \ + (struct fanotify_event_metadata*)(((char *)(meta)) + \ + (meta)->event_len)) + +#define FAN_EVENT_OK (meta, len) ((long)(len) >= (long)FAN_EVENT_METADATA_LEN && \ + (long)(meta)->event_len >= (long)FAN_EVENT_METADATA_LEN && \ + (long)(meta)->event_len <= (long)(len)) + +#endif /* _UAPI_LINUX_FANOTIFY_H */
tools/testing/selftests/filesystems/mount-notify/Makefile +2 -1
@@ -1,6 +1,7 @@ # SPDX-License-Identifier: GPL-2.0-or-later -CFLAGS += -Wall -O2 -g $(KHDR_INCLUDES) +CFLAGS += -Wall -O2 -g $(KHDR_INCLUDES) $(TOOLS_INCLUDES) + TEST_GEN_PROGS := mount-notify_test include ../../lib.mk
tools/testing/selftests/filesystems/mount-notify/mount-notify_test.c +6 -19
@@ -8,33 +8,20 @@#include <string.h> #include <sys/stat.h> #include <sys/mount.h> -#include <linux/fanotify.h> #include <unistd.h> -#include <sys/fanotify.h> #include <sys/syscall.h> #include "../../kselftest_harness.h" #include "../statmount/statmount.h" -#ifndef FAN_MNT_ATTACH -struct fanotify_event_info_mnt { -struct fanotify_event_info_header hdr; -__u64 mnt_id; -}; -#define FAN_MNT_ATTACH 0x01000000/* Mount was attached */ -#endif - -#ifndef FAN_MNT_DETACH -#define FAN_MNT_DETACH 0x02000000/* Mount was detached */ +// Needed for linux/fanotify.h +#ifndef __kernel_fsid_t +typedef struct { +int val[2 ]; +}__kernel_fsid_t ;#endif -#ifndef FAN_REPORT_MNT -#define FAN_REPORT_MNT 0x00004000/* Report mount events */ -#endif - -#ifndef FAN_MARK_MNTNS -#define FAN_MARK_MNTNS 0x00000110 -#endif +#include <sys/fanotify.h> static uint64_t get_mnt_id (struct __test_metadata *const _metadata,const char *path)
Signature · 1 line
2.34.1
Re: [PATCH v2 5/8] selftests/fs/mount-notify: build with tools include dir
Quoted 7 lines · Amir Goldstein
Copy the fanotify uapi header files to the tools include dir and define
__kernel_fsid_tto decouple dependency withheaders_installand then remove the redundant re-definitions of fanotify macros.Reviewed-by John Hubbard <[email protected]>Signed-off-by Amir Goldstein <[email protected]>---
Love it.
PATCH v2 6/8 selftests/filesystems: create get_unique_mnt_id() helper
In reply to Amir GoldsteinAdd helper to utils.c and use it in mount-notify and statmount tests.
Linking with utils.c drags in a dependecy with libcap, so add it to the Makefile of the tests.
--- .../filesystems/mount-notify/Makefile | 3 ++ .../mount-notify/mount-notify_test.c | 13 ++------- .../selftests/filesystems/statmount/Makefile | 3 ++ .../filesystems/statmount/statmount_test_ns.c | 28 +++---------------- tools/testing/selftests/filesystems/utils.c | 22 +++++++++++++++ tools/testing/selftests/filesystems/utils.h | 2 ++ 6 files changed, 36 insertions(+), 35 deletions(-)
tools/testing/selftests/filesystems/mount-notify/Makefile +3 -0
@@ -1,7 +1,10 @@ # SPDX-License-Identifier: GPL-2.0-or-later CFLAGS += -Wall -O2 -g $(KHDR_INCLUDES) $(TOOLS_INCLUDES) +LDLIBS += -lcap TEST_GEN_PROGS := mount-notify_test include ../../lib.mk + +$(OUTPUT)/mount-notify_test: ../utils.c
tools/testing/selftests/filesystems/mount-notify/mount-notify_test.c +2 -11
@@ -13,6 +13,7 @@#include "../../kselftest_harness.h" #include "../statmount/statmount.h" +#include "../utils.h" // Needed for linux/fanotify.h #ifndef __kernel_fsid_t
@@ -23,16 +24,6 @@ typedef struct {#include <sys/fanotify.h> -static uint64_t get_mnt_id (struct __test_metadata *const _metadata, -const char *path) -{ -struct statx sx; - -ASSERT_EQ (statx (AT_FDCWD , path,0 ,STATX_MNT_ID_UNIQUE , &sx),0 ); -ASSERT_TRUE (!!(sx.stx_mask &STATX_MNT_ID_UNIQUE )); -return sx.stx_mnt_id; -} -static const char root_mntpoint_templ[] ="/tmp/mount-notify_test_root.XXXXXX" ;static const int mark_cmds[] = {
@@ -81,7 +72,7 @@ FIXTURE_SETUP(fanotify)ASSERT_EQ (mkdir ("b" ,0700 ),0 ); - self->root_id =get_mnt_id (_metadata,"/" ); + self->root_id =get_unique_mnt_id ("/" );ASSERT_NE (self->root_id,0 );for (i =0 ; i <NUM_FAN_FDS ; i++) {
tools/testing/selftests/filesystems/statmount/Makefile +3 -0
@@ -1,7 +1,10 @@ # SPDX-License-Identifier: GPL-2.0-or-later CFLAGS += -Wall -O2 -g $(KHDR_INCLUDES) $(TOOLS_INCLUDES) +LDLIBS += -lcap TEST_GEN_PROGS := statmount_test statmount_test_ns listmount_test include ../../lib.mk + +$(OUTPUT)/statmount_test_ns: ../utils.c
tools/testing/selftests/filesystems/statmount/statmount_test_ns.c +4 -24
@@ -14,6 +14,7 @@#include <linux/stat.h> #include "statmount.h" +#include "../utils.h" #include "../../kselftest.h" #define NSID_PASS 0
@@ -78,27 +79,6 @@ static int get_mnt_ns_id(const char *mnt_ns, uint64_t *mnt_ns_id)return NSID_PASS ; } -static int get_mnt_id (const char *path,uint64_t *mnt_id) -{ -struct statx sx; -int ret; - - ret =statx (AT_FDCWD , path,0 ,STATX_MNT_ID_UNIQUE , &sx); -if (ret ==-1 ) { -ksft_print_msg ("retrieving unique mount ID for %s: %s\n" , path, -strerror (errno)); -return NSID_ERROR ; - } - -if (!(sx.stx_mask &STATX_MNT_ID_UNIQUE )) { -ksft_print_msg ("no unique mount ID available for %s\n" , path); -return NSID_ERROR ; - } - - *mnt_id = sx.stx_mnt_id; -return NSID_PASS ; -} -static int write_file (const char *path,const char *val) {int fd =open (path,O_WRONLY );
@@ -174,9 +154,9 @@ static int _test_statmount_mnt_ns_id(void)if (ret !=NSID_PASS )return ret; - ret =get_mnt_id ("/" , &root_id); -if (ret !=NSID_PASS ) -return ret; + root_id =get_unique_mnt_id ("/" ); +if (!root_id) +return NSID_ERROR ; ret =statmount (root_id,0 ,STATMOUNT_MNT_NS_ID , &sm,sizeof (sm),0 );if (ret ==-1 ) {
tools/testing/selftests/filesystems/utils.c +22 -0
@@ -19,6 +19,8 @@#include <sys/wait.h> #include <sys/xattr.h> +#include "../kselftest.h" +#include "wrappers.h" #include "utils.h" #define MAX_USERNS_LEVEL 32
@@ -499,3 +501,23 @@ int cap_down(cap_value_t down)cap_free (caps);return fret; } + +uint64_t get_unique_mnt_id (const char *path) +{ +struct statx sx; +int ret; + + ret =statx (AT_FDCWD , path,0 ,STATX_MNT_ID_UNIQUE , &sx); +if (ret ==-1 ) { +ksft_print_msg ("retrieving unique mount ID for %s: %s\n" , path, +strerror (errno)); +return 0 ; + } + +if (!(sx.stx_mask &STATX_MNT_ID_UNIQUE )) { +ksft_print_msg ("no unique mount ID available for %s\n" , path); +return 0 ; + } + +return sx.stx_mnt_id; +}
tools/testing/selftests/filesystems/utils.h +2 -0
@@ -42,4 +42,6 @@ static inline bool switch_userns(int fd, uid_t uid, gid_t gid, bool drop_caps) return true; } +extern uint64_t get_unique_mnt_id (const char *path); +#endif /* __IDMAP_UTILS_H */
Signature · 1 line
2.34.1
Re: [PATCH v2 6/8] selftests/filesystems: create get_unique_mnt_id() helper
Quoted 8 lines · Amir Goldstein
Add helper to
utils.cand use it in mount-notify and statmount tests.Linking with
utils.cdrags in a dependecy with libcap, so add it to theMakefileof the tests.Reviewed-by John Hubbard <[email protected]>Signed-off-by Amir Goldstein <[email protected]>---
Thanks!
PATCH v2 7/8 selftests/filesystems: create setup_userns() helper
In reply to Amir GoldsteinAdd helper to utils.c and use it in statmount userns tests.
--- .../filesystems/statmount/statmount_test_ns.c | 58 +--------------- tools/testing/selftests/filesystems/utils.c | 66 +++++++++++++++++++ tools/testing/selftests/filesystems/utils.h | 1 + 3 files changed, 68 insertions(+), 57 deletions(-)
tools/testing/selftests/filesystems/statmount/statmount_test_ns.c +1 -57
@@ -79,66 +79,10 @@ static int get_mnt_ns_id(const char *mnt_ns, uint64_t *mnt_ns_id)return NSID_PASS ; } -static int write_file (const char *path,const char *val) -{ -int fd =open (path,O_WRONLY ); -size_t len =strlen (val); -int ret; - -if (fd ==-1 ) { -ksft_print_msg ("opening %s for write: %s\n" , path,strerror (errno)); -return NSID_ERROR ; - } - - ret =write (fd, val, len); -if (ret ==-1 ) { -ksft_print_msg ("writing to %s: %s\n" , path,strerror (errno)); -return NSID_ERROR ; - } -if (ret != len) { -ksft_print_msg ("short write to %s\n" , path); -return NSID_ERROR ; - } - - ret =close (fd); -if (ret ==-1 ) { -ksft_print_msg ("closing %s\n" , path); -return NSID_ERROR ; - } - -return NSID_PASS ; -} -static int setup_namespace (void ) { -int ret; -char buf[32 ]; -uid_t uid =getuid (); -gid_t gid =getgid (); - - ret =unshare (CLONE_NEWNS |CLONE_NEWUSER |CLONE_NEWPID ); -if (ret ==-1 ) -ksft_exit_fail_msg ("unsharing mountns and userns: %s\n" , -strerror (errno)); - -sprintf (buf,"0 %d 1" , uid); - ret =write_file ("/proc/self/uid_map" , buf); -if (ret !=NSID_PASS ) -return ret; - ret =write_file ("/proc/self/setgroups" ,"deny" ); -if (ret !=NSID_PASS ) -return ret; -sprintf (buf,"0 %d 1" , gid); - ret =write_file ("/proc/self/gid_map" , buf); -if (ret !=NSID_PASS ) -return ret; - - ret =mount ("" ,"/" ,NULL ,MS_REC |MS_PRIVATE ,NULL ); -if (ret ==-1 ) { -ksft_print_msg ("making mount tree private: %s\n" , -strerror (errno)); +if (setup_userns () !=0 )return NSID_ERROR ; - }return NSID_PASS ; }
tools/testing/selftests/filesystems/utils.c +66 -0
78 lines not on this page · raw message
tools/testing/selftests/filesystems/utils.h +1 -0
@@ -27,6 +27,7 @@ extern int caps_down(void);extern int cap_down (cap_value_t down);extern bool switch_ids (uid_t uid,gid_t gid); +extern int setup_userns (void );static inline bool switch_userns (int fd,uid_t uid,gid_t gid,bool drop_caps) {
Signature · 1 line
2.34.1
Re: [PATCH v2 7/8] selftests/filesystems: create setup_userns() helper
Quoted 5 lines · Amir Goldstein
Add helper to
utils.cand use it in statmount userns tests.Reviewed-by John Hubbard <[email protected]>Signed-off-by Amir Goldstein <[email protected]>---
PATCH v2 8/8 selftests/fs/mount-notify: add a test variant running inside userns
In reply to Amir Goldsteinunshare userns in addition to mntns and verify that:
1. watching tmpfs mounted inside userns is allowed with any mark type
2. watching orig root with filesystem mark type is not allowed
3. watching mntns of orig userns is not allowed
4. watching mntns in userns where fanotify_init was called is allowed
mount events are only tested with the last case of mntns mark.
--- .../filesystems/mount-notify/.gitignore | 1 + .../filesystems/mount-notify/Makefile | 3 +- .../mount-notify/mount-notify_test_ns.c | 557 ++++++++++++++++++ 3 files changed, 560 insertions(+), 1 deletion(-) create mode 100644 tools/testing/selftests/filesystems/mount-notify/mount-notify_test_ns.c
tools/testing/selftests/filesystems/mount-notify/.gitignore +1 -0
@@ -1,2 +1,3 @@ # SPDX-License-Identifier: GPL-2.0-only /*_test +/*_test_ns
tools/testing/selftests/filesystems/mount-notify/Makefile +2 -1
@@ -3,8 +3,9 @@ CFLAGS += -Wall -O2 -g $(KHDR_INCLUDES) $(TOOLS_INCLUDES) LDLIBS += -lcap -TEST_GEN_PROGS := mount-notify_test +TEST_GEN_PROGS := mount-notify_test mount-notify_test_ns include ../../lib.mk $(OUTPUT)/mount-notify_test: ../utils.c +$(OUTPUT)/mount-notify_test_ns: ../utils.c
tools/testing/selftests/filesystems/mount-notify/mount-notify_test_ns.c new file +557 -0
557 lines not on this page · raw message
Signature · 1 line
2.34.1
Re: [PATCH v2 8/8] selftests/fs/mount-notify: add a test variant running inside userns
Quoted 11 lines · Amir Goldstein
unshare userns in addition to mntns and verify that:
1. watching tmpfs mounted inside userns is allowed with any mark type
2. watching orig root with filesystem mark type is not allowed
3. watching mntns of orig userns is not allowed
4. watching mntns in userns wherefanotify_initwas called is allowedmount events are only tested with the last case of mntns mark.
Signed-off-by Amir Goldstein <[email protected]>---
Christian Brauner
maintainerQuoted 12 lines · Amir Goldstein
Christian,
This adds a test for fanotify mount ns notifications inside userns [1].
While working on the test I ended up making lots of cleanups to reduce build dependency on make
headers_install.These patches got rid of the dependency for my kvm setup for the affected filesystems tests.
Building with
TOOLS_INCLUDESdir was recommended by John Hubbard [2].
Quoted 8 lines
NOTE #1: these patches are based on a merge of vfs-6.16.mount (changes
wrappers.h) into v6.15-rc5 (changesmount-notify_test.c), so if this cleanup is acceptable, we should probably setup a selftests branch for 6.16, so that it can be used to test the fanotify patches.NOTE #2: some of the defines in
wrappers.hare left for overlayfs andmount_setattrtests, which were not converted to useTOOLS_INCLUDES. I did not want to mess with those tests.
So I added both wrappers.h and utils.{c,h} and I had always intended to make them more widely available since quite a few things use them by now and I'm probably the cuplrit here. :) So thanks for this work!
As a next step we should move all VFS/FS related tests from selftests/ into selftests/filesystems/. So if anyone has the time and energy for this I will very very happily merge this.
Christian Brauner
maintainerQuoted 8 lines · Amir Goldstein
Christian,
This adds a test for fanotify mount ns notifications inside userns [1].
While working on the test I ended up making lots of cleanups to reduce build dependency on make
headers_install.[...]
Applied to the vfs-6.16.selftests branch of the vfs/vfs.git tree. Patches in the vfs-6.16.selftests branch should appear in linux-next soon.
Please report any outstanding bugs that were missed during review in a new review to the original patch series allowing us to drop it.
It's encouraged to provide Acked-bys and Reviewed-bys even though the patch has now been applied. If possible patch trailers will be updated.
Note that commit hashes shown below are subject to change due to rebase, trailer updates or similar. If in doubt, please check the listed branch.
tree: https://git.kernel.org/pub/scm/linux/kernel/git/vfs/vfs.git branch: vfs-6.16.selftests
[1/8] selftests/filesystems: move wrapper.h out of overlayfs subdir
https://git.kernel.org/vfs/vfs/c/0bd92b9fe538 [2/8] selftests/fs/statmount: build with tools include dir https://git.kernel.org/vfs/vfs/c/b13fb4ee4647 [3/8] selftests/pidfd: move syscall definitions into wrappers.h https://git.kernel.org/vfs/vfs/c/ef058fc1e5e9 [4/8] selftests/mount_settattr: remove duplicate syscall definitions https://git.kernel.org/vfs/vfs/c/ec050f2adf37 [5/8] selftests/fs/mount-notify: build with tools include dir https://git.kernel.org/vfs/vfs/c/c6d9775c2066 [6/8] selftests/filesystems: create get_unique_mnt_id() helper https://git.kernel.org/vfs/vfs/c/e897b9b1334b [7/8] selftests/filesystems: create setup_userns() helper https://git.kernel.org/vfs/vfs/c/8199e6f7402c [8/8] selftests/fs/mount-notify: add a test variant running inside userns https://git.kernel.org/vfs/vfs/c/781091f3f594
Quoted 6 lines · Christian Brauner
Quoted 4 lines · Amir Goldstein
Christian,
This adds a test for fanotify mount ns notifications inside userns [1].
Quoted 7 lines
Quoted 4 lines
While working on the test I ended up making lots of cleanups to reduce build dependency on make
headers_install.[...]
Applied to the vfs-6.16.selftests branch of the vfs/vfs.git tree. Patches in the vfs-6.16.selftests branch should appear in linux-next soon.
Forgot to push the branch?
I do not see it in your tree nor in linux-next...
Thanks,
Amir.
Quoted 29 lines
Please report any outstanding bugs that were missed during review in a new review to the original patch series allowing us to drop it.
It's encouraged to provide Acked-bys and Reviewed-bys even though the patch has now been applied. If possible patch trailers will be updated.
Note that commit hashes shown below are subject to change due to rebase, trailer updates or similar. If in doubt, please check the listed branch.
tree: https://git.kernel.org/pub/scm/linux/kernel/git/vfs/vfs.git branch: vfs-6.16.selftests[1/8] selftests/filesystems: move
wrapper.hout of overlayfs subdirhttps://git.kernel.org/vfs/vfs/c/0bd92b9fe538 [2/8] selftests/fs/statmount: build with tools include dir https://git.kernel.org/vfs/vfs/c/b13fb4ee4647 [3/8] selftests/pidfd: move syscall definitions into wrappers.h https://git.kernel.org/vfs/vfs/c/ef058fc1e5e9 [4/8] selftests/mount_settattr: remove duplicate syscall definitions https://git.kernel.org/vfs/vfs/c/ec050f2adf37 [5/8] selftests/fs/mount-notify: build with tools include dir https://git.kernel.org/vfs/vfs/c/c6d9775c2066 [6/8] selftests/filesystems: create get_unique_mnt_id() helper https://git.kernel.org/vfs/vfs/c/e897b9b1334b [7/8] selftests/filesystems: create setup_userns() helper https://git.kernel.org/vfs/vfs/c/8199e6f7402c [8/8] selftests/fs/mount-notify: add a test variant running inside userns https://git.kernel.org/vfs/vfs/c/781091f3f594
Christian Brauner
maintainerQuoted 10 lines · Amir Goldstein
Quoted 9 lines · Christian Brauner
Quoted 7 lines · Amir Goldstein
Christian,
This adds a test for fanotify mount ns notifications inside userns [1].
While working on the test I ended up making lots of cleanups to reduce build dependency on make
headers_install.
Quoted 8 lines
Quoted 4 lines
Quoted 1 line
[...]
Applied to the vfs-6.16.selftests branch of the vfs/vfs.git tree. Patches in the vfs-6.16.selftests branch should appear in linux-next soon.
Forgot to push the branch?
I do not see it in your tree nor in linux-next...
Should all be done now.