statmount/listmount testing suites
v4 cover statmount/listmount testing suites
This patch-set is adding new testing suites for statmount() and listmount() syscalls, which have been recently added in kernel v6.8.
To find out more information, please read the following documentation since there's no man pages yet:
https://lwn.net/Articles/950569/
https://lore.kernel.org/lkml/[email protected]/T/
Along with kernel source code:
https://github.com/torvalds/linux/blob/1b294a1f35616977caddaddf3e9d28e576a1adbc/include/uapi/linux/mount.h#L155
https://github.com/torvalds/linux/blob/1b294a1f35616977caddaddf3e9d28e576a1adbc/tools/testing/selftests/filesystems/statmount/statmount_test.c
---
Changes in v4:
- listmount01: remove all filesystems run
- listmount02: better descriptions and proper unmount()
- statmount01: check all fields are zeroed
- statmount02: check also readonly flag
- statmount03: now it checks for all mount flags
- statmount04: moved read_peer_group inside statmount.h
- statmount07: add test for invalid values
- generic style fixes
- fix statx import
- Link to v3: https://lore.kernel.org/r/[email protected]
---
Andrea Cervesato (13):
Add SAFE_STATX macro
Add listmount/statmount syscalls
Add listmount/statmount fallback declarations Add listmount01 test
Add listmount02 test
Add statmount01 test
Add statmount02 test
Add statmount03 test
Add statmount04 test
Add statmount05 test
Add TST_EXP_EQ_STR macro
Add statmount06 test
Add statmount07 test
compile_flags.txt | 1 + configure.ac | 4 + include/lapi/mount.h | 70 +++++++++++ include/lapi/stat.h | 111 ++++++++++++----- include/lapi/syscalls/aarch64.in | 2 + include/lapi/syscalls/arc.in | 2 + include/lapi/syscalls/arm.in | 2 + include/lapi/syscalls/hppa.in | 2 + include/lapi/syscalls/i386.in | 2 + include/lapi/syscalls/ia64.in | 2 + include/lapi/syscalls/loongarch.in | 2 + include/lapi/syscalls/mips_n32.in | 2 + include/lapi/syscalls/mips_n64.in | 2 + include/lapi/syscalls/mips_o32.in | 2 + include/lapi/syscalls/powerpc.in | 2 + include/lapi/syscalls/powerpc64.in | 2 + include/lapi/syscalls/s390.in | 2 + include/lapi/syscalls/s390x.in | 2 + include/lapi/syscalls/sh.in | 2 + include/lapi/syscalls/sparc.in | 2 + include/lapi/syscalls/sparc64.in | 2 + include/lapi/syscalls/x86_64.in | 2 + include/tst_test_macros.h | 14 +++ runtest/syscalls | 11 ++ testcases/kernel/syscalls/fchmodat2/fchmodat2_01.c | 2 + testcases/kernel/syscalls/listmount/.gitignore | 2 + testcases/kernel/syscalls/listmount/Makefile | 7 ++ testcases/kernel/syscalls/listmount/listmount.h | 26 ++++ testcases/kernel/syscalls/listmount/listmount01.c | 63 ++++++++++ testcases/kernel/syscalls/listmount/listmount02.c | 105 ++++++++++++++++ testcases/kernel/syscalls/statmount/.gitignore | 7 ++ testcases/kernel/syscalls/statmount/Makefile | 7 ++ testcases/kernel/syscalls/statmount/statmount.h | 50 ++++++++ testcases/kernel/syscalls/statmount/statmount01.c | 82 ++++++++++++ testcases/kernel/syscalls/statmount/statmount02.c | 84 +++++++++++++ testcases/kernel/syscalls/statmount/statmount03.c | 137 +++++++++++++++++++++ testcases/kernel/syscalls/statmount/statmount04.c | 105 ++++++++++++++++ testcases/kernel/syscalls/statmount/statmount05.c | 128 +++++++++++++++++++ testcases/kernel/syscalls/statmount/statmount06.c | 68 ++++++++++ testcases/kernel/syscalls/statmount/statmount07.c | 75 +++++++++++ 40 files changed, 1163 insertions(+), 32 deletions(-)
---
base-commit: 6df425bb7040e1c849cb84a83f5e8808967efc0e
change-id: 20240516-listmount_statmount-080965e2f80e
Best regards,
Signature · 5 lines
Andrea Cervesato <[email protected]> -- Mailing list info: https://lists.linux.it/listinfo/ltp
PATCH v4 1/13 Add SAFE_STATX macro
From: Andrea Cervesato <[email protected]>
--- compile_flags.txt | 1 + include/lapi/stat.h | 111 +++++++++++++++------ testcases/kernel/syscalls/fchmodat2/fchmodat2_01.c | 2 + 3 files changed, 82 insertions(+), 32 deletions(-)
compile_flags.txt new file +1 -0
@@ -0,0 +1 @@ +-Iinclude/
include/lapi/stat.h +79 -32
143 lines not on this page · raw message
testcases/kernel/syscalls/fchmodat2/fchmodat2_01.c +2 -0
@@ -12,6 +12,8 @@* usage on symlinks will raise EOPNOTSUPP. */ +#define _GNU_SOURCE +#include "tst_test.h" #include "tst_safe_file_at.h" #include "lapi/fcntl.h"
Signature · 5 lines
2.43.0 -- Mailing list info: https://lists.linux.it/listinfo/ltp
Re: [LTP] [PATCH v4 01/13] Add SAFE_STATX macro
Hi!
read below...
compile_flags.txt
Quoted 15 lines · Andrea Cervesato
From: Andrea Cervesato <[email protected]>
Reviewed-by Avinesh Kumar <[email protected]>Signed-off-by Andrea Cervesato <[email protected]>--- compile_flags.txt | 1 + include/lapi/stat.h | 111 +++++++++++++++------ testcases/kernel/syscalls/fchmodat2/fchmodat2_01.c | 2 + 3 files changed, 82 insertions(+), 32 deletions(-)compile_flags.txt new file +0
-0
This is a file for configuring clangd. I guess I had a "git add ." in the folder. Please ignore this part of the patch.
Andrea
Quoted 168 lines
compile_flags.txt new file +1
-0@@ -0,0 +1 @@ +-Iinclude/include/lapi/stat.h +79
-32@@ -30,6 +30,7 @@ struct statx_timestamp { int32_t __reserved; };#endif +/* * Structures for the extended file attribute retrieval system call * (statx()). @@ -67,39 +68,57 @@ struct statx_timestamp {* will have values installed for compatibility purposes so that stat() and * co. can be emulated in userspace. */ -#ifndef HAVE_STRUCT_STATX -struct statx { -/* 0x00 */ -uint32_t stx_mask; -uint32_t stx_blksize; -uint64_t stx_attributes; -/* 0x10 */ -uint32_t stx_nlink; -uint32_t stx_uid; -uint32_t stx_gid; -uint16_t stx_mode; -uint16_t __spare0[1 ]; -/* 0x20 */ -uint64_t stx_ino; -uint64_t stx_size; -uint64_t stx_blocks; -uint64_t stx_attributes_mask; -/* 0x40 */ -const struct statx_timestamp stx_atime; -const struct statx_timestamp stx_btime; -const struct statx_timestamp stx_ctime; -const struct statx_timestamp stx_mtime; -/* 0x80 */ -uint32_t stx_rdev_major; -uint32_t stx_rdev_minor; -uint32_t stx_dev_major; -uint32_t stx_dev_minor; -/* 0x90 */ -uint64_t __spare2[14 ]; -/* 0x100 */ +#define LTP_DEFINE_STATX_STRUCT (x) \ + struct x { \ + uint32_t stx_mask; \ + uint32_t stx_blksize; \ + uint64_t stx_attributes; \ + uint32_t stx_nlink; \ + uint32_t stx_uid; \ + uint32_t stx_gid; \ + uint16_t stx_mode; \ + uint16_t __spare0[1]; \ + uint64_t stx_ino; \ + uint64_t stx_size; \ + uint64_t stx_blocks; \ + uint64_t stx_attributes_mask; \ + const struct statx_timestamp stx_atime; \ + const struct statx_timestamp stx_btime; \ + const struct statx_timestamp stx_ctime; \ + const struct statx_timestamp stx_mtime; \ + uint32_t stx_rdev_major; \ + uint32_t stx_rdev_minor; \ + uint32_t stx_dev_major; \ + uint32_t stx_dev_minor; \ + uint64_t stx_mnt_id; \ + uint32_t stx_dio_mem_align; \ + uint32_t stx_dio_offset_align; \ + uint64_t __spare3[12]; \ }; + +LTP_DEFINE_STATX_STRUCT (statx_fallback); + +#ifdef HAVE_STRUCT_STATX +typedef struct statx ltp_statx_ ; +#else +LTP_DEFINE_STATX_STRUCT (statx); + +typedef struct statx_fallback ltp_statx_ ;#endif +/* +* This is the fallback statx that we pass to the safe_statx() syscall. +* The reason why we need it, is that statx struct is constantly changing +* inside the kernel and we need to extend its definition when structure +* changes in order to compile the tests. +*/ +struct ltp_statx { +union { +ltp_statx_ buff; +struct statx_fallback data; + }; +}; +#ifndef HAVE_STATX /* @@ -108,9 +127,9 @@ struct statx {* Returns: It returns status of statx syscall */ static inline int statx (int dirfd,const char *pathname,unsigned int flags, -unsigned int mask,struct statx *statxbuf) +unsigned int mask,struct statx *st) { -return tst_syscall (__NR_statx, dirfd, pathname, flags, mask, statxbuf); +return tst_syscall (__NR_statx, dirfd, pathname, flags, mask, st); }#endif @@ -229,6 +248,10 @@ static inline int statx(int dirfd, const char *pathname, unsigned int flags,# define STATX_ATTR_VERITY 0x00100000#endif +#ifndef STATX_MNT_ID_UNIQUE +# define STATX_MNT_ID_UNIQUE 0x00004000U +#endif +#define SAFE_FCHMODAT2 (dfd, filename, mode, flags) \ safe_fchmodat2(__FILE__, __LINE__, (dfd), (filename), (mode), (flags))@@ -251,4 +274,28 @@ static inline int safe_fchmodat2(const char *file, const int lineno, return ret; } +#define SAFE_STATX (dirfd, pathname, flags, mask, buf) \ + safe_statx(__FILE__, __LINE__, (dirfd), (pathname), (flags), (mask), (buf)) + +static inline int safe_statx (const char *file,const int lineno, +int dirfd,const char *pathname,int flags,unsigned int mask, +struct ltp_statx *buf) +{ +int rval; + + rval =statx (dirfd, pathname, flags, mask, &buf->buff); + +if (rval ==-1 ) { +tst_brk_ (file, lineno,TBROK |TERRNO , +"statx(%d,%s,%d,%u,%p) failed" , dirfd, pathname, flags, mask, buf); + }else if (rval) { +tst_brk_ (file, lineno,TBROK |TERRNO , +"Invalid statx(%d,%s,%d,%u,%p) return value %d" , + dirfd, pathname, flags, mask, buf, + rval); + } + +return rval; +} +#endif /* LAPI_STAT_H__ */ testcases/kernel/syscalls/fchmodat2/fchmodat2_01.c +2
-0@@ -12,6 +12,8 @@* usage on symlinks will raise EOPNOTSUPP. */ +#define _GNU_SOURCE +#include "tst_test.h" #include "tst_safe_file_at.h" #include "lapi/fcntl.h"
Signature · 1 line
Mailing list info: https://lists.linux.it/listinfo/ltp
Re: [LTP] [PATCH v4 01/13] Add SAFE_STATX macro
In reply to Andrea CervesatoHi!
testcases/kernel/syscalls/fchmodat2/fchmodat2_01.c line 19
Quoted 11 lines
testcases/kernel/syscalls/fchmodat2/fchmodat2_01.c +2
-0@@ -12,6 +12,8 @@* usage on symlinks will raise EOPNOTSUPP. */ +#define _GNU_SOURCE +#include "tst_test.h" #include "tst_safe_file_at.h" #include "lapi/fcntl.h"
This looks like it should be in a separate patch as well. At least there is no description why this is needed in the patch either.
Signature · 5 lines
Cyril Hrubis [email protected] -- Mailing list info: https://lists.linux.it/listinfo/ltp
Re: [LTP] [PATCH v4 01/13] Add SAFE_STATX macro
Hi!
Quoted 7 lines · Cyril Hrubis
Hi!
Quoted 6 lines
testcases/kernel/syscalls/fchmodat2/fchmodat2_01.c +0
-0@@ -12,6 +12,8 @@* usage on symlinks will raise EOPNOTSUPP. */
Quoted 8 lines
testcases/kernel/syscalls/fchmodat2/fchmodat2_01.c line 19
Quoted 5 lines
testcases/kernel/syscalls/fchmodat2/fchmodat2_01.c +2
-0+#define _GNU_SOURCE +#include "tst_test.h" #include "tst_safe_file_at.h" #include "lapi/fcntl.h" This looks like it should be in a separate patch as well. At least there is no description why this is needed in the patch either.
This is clearly an error. Probably git added a wrong file.
Andrea
Signature · 1 line
Mailing list info: https://lists.linux.it/listinfo/ltp
PATCH v4 2/13 Add listmount/statmount syscalls
In reply to Andrea CervesatoFrom: Andrea Cervesato <[email protected]>
--- include/lapi/syscalls/aarch64.in | 2 ++ include/lapi/syscalls/arc.in | 2 ++ include/lapi/syscalls/arm.in | 2 ++ include/lapi/syscalls/hppa.in | 2 ++ include/lapi/syscalls/i386.in | 2 ++ include/lapi/syscalls/ia64.in | 2 ++ include/lapi/syscalls/loongarch.in | 2 ++ include/lapi/syscalls/mips_n32.in | 2 ++ include/lapi/syscalls/mips_n64.in | 2 ++ include/lapi/syscalls/mips_o32.in | 2 ++ include/lapi/syscalls/powerpc.in | 2 ++ include/lapi/syscalls/powerpc64.in | 2 ++ include/lapi/syscalls/s390.in | 2 ++ include/lapi/syscalls/s390x.in | 2 ++ include/lapi/syscalls/sh.in | 2 ++ include/lapi/syscalls/sparc.in | 2 ++ include/lapi/syscalls/sparc64.in | 2 ++ include/lapi/syscalls/x86_64.in | 2 ++ 18 files changed, 36 insertions(+)
include/lapi/syscalls/aarch64.in +2 -0
@@ -303,4 +303,6 @@ futex_waitv 449 cachestat 451 fchmodat2 452 mseal 462 +statmount 457 +listmount 458 _sysctl 1078
include/lapi/syscalls/arc.in +2 -0
@@ -323,3 +323,5 @@ futex_waitv 449 cachestat 451 fchmodat2 452 mseal 462 +statmount 457 +listmount 458
include/lapi/syscalls/arm.in +2 -0
@@ -402,3 +402,5 @@ futex_waitv (__NR_SYSCALL_BASE+449) cachestat (__NR_SYSCALL_BASE+451) fchmodat2 (__NR_SYSCALL_BASE+452) mseal (__NR_SYSCALL_BASE+462) +statmount (__NR_SYSCALL_BASE+457) +listmount (__NR_SYSCALL_BASE+458)
include/lapi/syscalls/hppa.in +2 -0
@@ -50,3 +50,5 @@ futex_waitv 449 cachestat 451 fchmodat2 452 mseal 462 +statmount 457 +listmount 458
include/lapi/syscalls/i386.in +2 -0
@@ -437,3 +437,5 @@ futex_waitv 449 cachestat 451 fchmodat2 452 mseal 462 +statmount 457 +listmount 458
include/lapi/syscalls/ia64.in +2 -0
@@ -350,3 +350,5 @@ futex_waitv 1473 cachestat 1475 fchmodat2 1476 mseal 1486 +statmount 1481 +listmount 1482
include/lapi/syscalls/loongarch.in +2 -0
@@ -308,3 +308,5 @@ set_mempolicy_home_node 450 cachestat 451 fchmodat2 452 mseal 462 +statmount 457 +listmount 458
include/lapi/syscalls/mips_n32.in +2 -0
@@ -377,3 +377,5 @@ futex_waitv 6449 cachestat 6451 fchmodat2 6452 mseal 6462 +statmount 6457 +listmount 6458
include/lapi/syscalls/mips_n64.in +2 -0
@@ -353,3 +353,5 @@ futex_waitv 5449 cachestat 5451 fchmodat2 5452 mseal 5462 +statmount 5457 +listmount 5458
include/lapi/syscalls/mips_o32.in +2 -0
@@ -423,3 +423,5 @@ futex_waitv 4449 cachestat 4451 fchmodat2 4452 mseal 4462 +statmount 4457 +listmount 4458
include/lapi/syscalls/powerpc.in +2 -0
@@ -430,3 +430,5 @@ futex_waitv 449 cachestat 451 fchmodat2 452 mseal 462 +statmount 457 +listmount 458
include/lapi/syscalls/powerpc64.in +2 -0
@@ -430,3 +430,5 @@ futex_waitv 449 cachestat 451 fchmodat2 452 mseal 462 +statmount 457 +listmount 458
include/lapi/syscalls/s390.in +2 -0
@@ -417,3 +417,5 @@ futex_waitv 449 cachestat 451 fchmodat2 452 mseal 462 +statmount 457 +listmount 458
include/lapi/syscalls/s390x.in +2 -0
@@ -365,3 +365,5 @@ futex_waitv 449 cachestat 451 fchmodat2 452 mseal 462 +statmount 457 +listmount 458
include/lapi/syscalls/sh.in +2 -0
@@ -411,3 +411,5 @@ futex_waitv 449 cachestat 451 fchmodat2 452 mseal 462 +statmount 457 +listmount 458
include/lapi/syscalls/sparc.in +2 -0
@@ -416,3 +416,5 @@ futex_waitv 449 cachestat 451 fchmodat2 452 mseal 462 +statmount 457 +listmount 458
include/lapi/syscalls/sparc64.in +2 -0
@@ -381,3 +381,5 @@ futex_waitv 449 cachestat 451 fchmodat2 452 mseal 462 +statmount 457 +listmount 458
include/lapi/syscalls/x86_64.in +2 -0
@@ -358,6 +358,8 @@ futex_waitv 449 cachestat 451 fchmodat2 452 mseal 462 +statmount 457 +listmount 458 rt_sigaction 512 rt_sigreturn 513 ioctl 514
Signature · 5 lines
2.43.0 -- Mailing list info: https://lists.linux.it/listinfo/ltp
Re: [LTP] [PATCH v4 02/13] Add listmount/statmount syscalls
Hi!
Signature · 5 lines
Cyril Hrubis [email protected] -- Mailing list info: https://lists.linux.it/listinfo/ltp
PATCH v4 3/13 Add listmount/statmount fallback declarations
In reply to Andrea CervesatoFrom: Andrea Cervesato <[email protected]>
--- configure.ac | 4 +++ include/lapi/mount.h | 70 ++++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 74 insertions(+)
configure.ac +4 -0
@@ -114,6 +114,7 @@ AC_CHECK_FUNCS_ONCE([ \ io_uring_register \ io_uring_enter \ kcmp \ + listmount \ mallinfo \ mallinfo2 \ mallopt \
@@ -143,6 +144,7 @@ AC_CHECK_FUNCS_ONCE([ \ setns \ sigpending \ splice \ + statmount \ statx \ stime \ sync_file_range \
@@ -246,6 +248,8 @@ AC_CHECK_TYPES([struct mount_attr],,,[ AC_CHECK_TYPES([struct cachestat_range],,,[#include <sys/mman.h>]) AC_CHECK_TYPES([struct cachestat],,,[#include <sys/mman.h>]) +AC_CHECK_TYPES([struct mnt_id_req],,,[#include <linux/mount.h>]) +AC_CHECK_TYPES([struct statmount],,,[#include <linux/mount.h>]) # Tools knobs
include/lapi/mount.h +70 -0
86 lines not on this page · raw message
Signature · 5 lines
2.43.0 -- Mailing list info: https://lists.linux.it/listinfo/ltp
Re: [LTP] [PATCH v4 03/13] Add listmount/statmount fallback declarations
Hi!
Quoted 13 lines
configure.ac +1
-0@@ -114,6 +114,7 @@ AC_CHECK_FUNCS_ONCE([ \ io_uring_register \ io_uring_enter \ kcmp \ + listmount \ mallinfo \ mallinfo2 \ mallopt \
configure.ac AC_CHECK_FUNCS_ONCE([ \ · line 150
Quoted 7 lines
configure.ac +1
-0@@ -143,6 +144,7 @@ AC_CHECK_FUNCS_ONCE([ \ setns \ sigpending \ splice \ + statmount \ statx \ stime \ sync_file_range \
These two checks shouldn't be here because we do not use them at all and just define cunstom wrappers later on.
Quoted 91 lines
configure.ac +2
-0@@ -246,6 +248,8 @@ AC_CHECK_TYPES([struct mount_attr],,,[ AC_CHECK_TYPES([struct cachestat_range],,,[#include <sys/mman.h>]) AC_CHECK_TYPES([struct cachestat],,,[#include <sys/mman.h>]) +AC_CHECK_TYPES([struct mnt_id_req],,,[#include <linux/mount.h>]) +AC_CHECK_TYPES([struct statmount],,,[#include <linux/mount.h>]) # Tools knobsinclude/lapi/mount.h +61
-0@@ -2,12 +2,15 @@/* * Copyright (c) Linux Test Project, 2015-2022 * Copyright (c) 2015 Cui Bixuan <[email protected]> +* Copyright (C) 2024 SUSE LLC Andrea Cervesato <[email protected]> */ #ifndef LAPI_MOUNT_H__ #define LAPI_MOUNT_H__ +#include <stdint.h> #include <sys/mount.h> +#include "config.h" #ifndef MS_REC # define MS_REC 16384@@ -37,4 +40,71 @@# define MS_NOSYMFOLLOW 256#endif +#ifndef HAVE_STRUCT_MNT_ID_REQ +struct mnt_id_req { +uint32_t size; +uint32_t spare; +uint64_t mnt_id; +uint64_t param; +}; +#endif + +#ifndef HAVE_STRUCT_STATMOUNT +struct statmount { +uint32_t size; +uint32_t __spare1; +uint64_t mask; +uint32_t sb_dev_major; +uint32_t sb_dev_minor; +uint64_t sb_magic; +uint32_t sb_flags; +uint32_t fs_type; +uint64_t mnt_id; +uint64_t mnt_parent_id; +uint32_t mnt_id_old; +uint32_t mnt_parent_id_old; +uint64_t mnt_attr; +uint64_t mnt_propagation; +uint64_t mnt_peer_group; +uint64_t mnt_master; +uint64_t propagate_from; +uint32_t mnt_root; +uint32_t mnt_point; +uint64_t __spare2[50 ]; +char str[]; +}; +#endif + +#ifndef MNT_ID_REQ_SIZE_VER0 +# define MNT_ID_REQ_SIZE_VER0 24 +#endif + +#ifndef STATMOUNT_SB_BASIC +# define STATMOUNT_SB_BASIC 0x00000001U +#endif + +#ifndef STATMOUNT_MNT_BASIC +# define STATMOUNT_MNT_BASIC 0x00000002U +#endif + +#ifndef STATMOUNT_PROPAGATE_FROM +# define STATMOUNT_PROPAGATE_FROM 0x00000004U +#endif + +#ifndef STATMOUNT_MNT_ROOT +# define STATMOUNT_MNT_ROOT 0x00000008U +#endif + +#ifndef STATMOUNT_MNT_POINT +# define STATMOUNT_MNT_POINT 0x00000010U +#endif
include/lapi/mount.h line 110
Quoted 10 lines
include/lapi/mount.h +9
-0+ +#ifndef STATMOUNT_FS_TYPE +# define STATMOUNT_FS_TYPE 0x00000020U +#endif + +#ifndef LSMT_ROOT +# define LSMT_ROOT 0xffffffffffffffff +#endif +#endif /* LAPI_MOUNT_H__ */
The rest looks fine:
Signature · 5 lines
Cyril Hrubis [email protected] -- Mailing list info: https://lists.linux.it/listinfo/ltp
PATCH v4 4/13 Add listmount01 test
In reply to Andrea CervesatoFrom: Andrea Cervesato <[email protected]>
This test verifies that listmount() is properly recognizing a mounted root directory using LSMT_ROOT flag.
--- runtest/syscalls | 2 + testcases/kernel/syscalls/listmount/.gitignore | 1 + testcases/kernel/syscalls/listmount/Makefile | 7 +++ testcases/kernel/syscalls/listmount/listmount.h | 26 ++++++++++ testcases/kernel/syscalls/listmount/listmount01.c | 63 +++++++++++++++++++++++ 5 files changed, 99 insertions(+)
runtest/syscalls +2 -0
@@ -730,6 +730,8 @@ linkat02 linkat02 listen01 listen01 +listmount01 listmount01 + listxattr01 listxattr01 listxattr02 listxattr02 listxattr03 listxattr03
testcases/kernel/syscalls/listmount/.gitignore new file +1 -0
@@ -0,0 +1 @@ +listmount01
testcases/kernel/syscalls/listmount/Makefile new file +7 -0
@@ -0,0 +1,7 @@ +# SPDX-License-Identifier: GPL-2.0-or-later +# Copyright (C) 2024 SUSE LLC Andrea Cervesato <[email protected]> + +top_srcdir ?= ../../../.. + +include $(top_srcdir)/include/mk/testcases.mk +include $(top_srcdir)/include/mk/generic_leaf_target.mk
testcases/kernel/syscalls/listmount/listmount.h new file +26 -0
@@ -0,0 +1,26 @@ +/* SPDX-License-Identifier: GPL-2.0-or-later */ +/* +* Copyright (C) 2024 SUSE LLC Andrea Cervesato <[email protected]> +*/ + +#ifndef LISTMOUNT_H + +#define _GNU_SOURCE + +#include "tst_test.h" +#include "lapi/mount.h" +#include "lapi/syscalls.h" + +static inline ssize_t listmount (uint64_t mnt_id,uint64_t last_mnt_id, +uint64_t list[],size_t num,unsigned int flags) +{ +struct mnt_id_req req = { + .size =MNT_ID_REQ_SIZE_VER0 , + .mnt_id = mnt_id, + .param = last_mnt_id, + }; + +return tst_syscall (__NR_listmount, &req, list, num, flags); +} + +#endif
testcases/kernel/syscalls/listmount/listmount01.c new file +63 -0
63 lines not on this page · raw message
Signature · 5 lines
2.43.0 -- Mailing list info: https://lists.linux.it/listinfo/ltp
Re: [LTP] [PATCH v4 04/13] Add listmount01 test
Hi!
Quoted 110 lines
This test verifies that
listmount()is properly recognizing a mounted root directory usingLSMT_ROOTflag.Signed-off-by Andrea Cervesato <[email protected]>--- runtest/syscalls | 2 + testcases/kernel/syscalls/listmount/.gitignore | 1 + testcases/kernel/syscalls/listmount/Makefile | 7 +++ testcases/kernel/syscalls/listmount/listmount.h | 26 ++++++++++ testcases/kernel/syscalls/listmount/listmount01.c | 63 +++++++++++++++++++++++ 5 files changed, 99 insertions(+)runtest/syscalls +2
-0@@ -730,6 +730,8 @@ linkat02 linkat02 listen01 listen01 +listmount01 listmount01 + listxattr01 listxattr01 listxattr02 listxattr02 listxattr03 listxattr03testcases/kernel/syscalls/listmount/.gitignore new file +1
-0@@ -0,0 +1 @@ +listmount01testcases/kernel/syscalls/listmount/Makefile new file +7
-0@@ -0,0 +1,7 @@ +# SPDX-License-Identifier: GPL-2.0-or-later +# Copyright (C) 2024 SUSE LLC Andrea Cervesato <[email protected]> + +top_srcdir ?= ../../../.. + +include $(top_srcdir)/include/mk/testcases.mk +include $(top_srcdir)/include/mk/generic_leaf_target.mktestcases/kernel/syscalls/listmount/listmount.h new file +26
-0@@ -0,0 +1,26 @@ +/* SPDX-License-Identifier: GPL-2.0-or-later */ +/* +* Copyright (C) 2024 SUSE LLC Andrea Cervesato <[email protected]> +*/ + +#ifndef LISTMOUNT_H + +#define _GNU_SOURCE + +#include "tst_test.h" +#include "lapi/mount.h" +#include "lapi/syscalls.h" + +static inline ssize_t listmount (uint64_t mnt_id,uint64_t last_mnt_id, +uint64_t list[],size_t num,unsigned int flags) +{ +struct mnt_id_req req = { + .size =MNT_ID_REQ_SIZE_VER0 , + .mnt_id = mnt_id, + .param = last_mnt_id, + }; + +return tst_syscall (__NR_listmount, &req, list, num, flags); +} + +#endif testcases/kernel/syscalls/listmount/listmount01.c new file +27
-0@@ -0,0 +1,63 @@ +// SPDX-License-Identifier: GPL-2.0-or-later +/* +* Copyright (C) 2024 SUSE LLC Andrea Cervesato <[email protected]> +*/ + +/*\ +* [Description] +* +* This test verifies that listmount() is properly recognizing a mounted +* root directory using LSMT_ROOT flag. +* +* [Algorithm] +* +* - move into a new unshared namespace +* - mount() a root inside temporary folder and get its mount ID +* - get list of mounted IDs using listmount(LSMT_ROOT, ..) +* - verify that the root mount ID is the only mount ID present inside the list +*/ + +#define _GNU_SOURCE + +#include "listmount.h" +#include "lapi/stat.h" +#include "lapi/sched.h" + +#define MNTPOINT "mntpoint" +#define LISTSIZE 32
testcases/kernel/syscalls/listmount/listmount01.c line 37
Quoted 10 lines
testcases/kernel/syscalls/listmount/listmount01.c new file +10
-0+ +static uint64_t root_id; + +static void run (void ) +{ +uint64_t list[LISTSIZE ]; + +TST_EXP_POSITIVE (listmount (LSMT_ROOT ,0 , list,LISTSIZE ,0 )); +if (TST_RET ==-1 ) +return ;
This is purely cosmetic but this should be if (!TST_PASS).
The rest looks good:
Signature · 5 lines
Cyril Hrubis [email protected] -- Mailing list info: https://lists.linux.it/listinfo/ltp
Re: [LTP] [PATCH v4 04/13] Add listmount01 test
In reply to Andrea CervesatoHi!
testcases/kernel/syscalls/listmount/listmount.h line 6
Quoted 6 lines
testcases/kernel/syscalls/listmount/listmount.h new file +6
-0+/* SPDX-License-Identifier: GPL-2.0-or-later */ +/* +* Copyright (C) 2024 SUSE LLC Andrea Cervesato <[email protected]> +*/ + +#ifndef LISTMOUNT_H
Ah, and #define LISTMOUNT_H is missing here, otherwise the header guards does not work at all.
Quoted 19 lines
testcases/kernel/syscalls/listmount/listmount.h new file +19
-0+#define _GNU_SOURCE + +#include "tst_test.h" +#include "lapi/mount.h" +#include "lapi/syscalls.h" + +static inline ssize_t listmount (uint64_t mnt_id,uint64_t last_mnt_id, +uint64_t list[],size_t num,unsigned int flags) +{ +struct mnt_id_req req = { + .size =MNT_ID_REQ_SIZE_VER0 , + .mnt_id = mnt_id, + .param = last_mnt_id, + }; + +return tst_syscall (__NR_listmount, &req, list, num, flags); +} + +#endif
Signature · 5 lines
Cyril Hrubis [email protected] -- Mailing list info: https://lists.linux.it/listinfo/ltp
PATCH v4 5/13 Add listmount02 test
In reply to Andrea CervesatoFrom: Andrea Cervesato <[email protected]>
This test verifies that listmount() is properly reading groups of mount IDs.
--- runtest/syscalls | 1 + testcases/kernel/syscalls/listmount/.gitignore | 1 + testcases/kernel/syscalls/listmount/listmount02.c | 105 ++++++++++++++++++++++ 3 files changed, 107 insertions(+)
runtest/syscalls +1 -0
@@ -731,6 +731,7 @@ linkat02 linkat02 listen01 listen01 listmount01 listmount01 +listmount02 listmount02 listxattr01 listxattr01 listxattr02 listxattr02
testcases/kernel/syscalls/listmount/.gitignore +1 -0
@@ -1 +1,2 @@ listmount01 +listmount02
testcases/kernel/syscalls/listmount/listmount02.c new file +105 -0
105 lines not on this page · raw message
Signature · 5 lines
2.43.0 -- Mailing list info: https://lists.linux.it/listinfo/ltp
Re: [LTP] [PATCH v4 05/13] Add listmount02 test
Hi!
Quoted 5 lines
testcases/kernel/syscalls/listmount/listmount02.c new file +5
-0+static void run (void ) +{ +ssize_t ret; +size_t id, tot_ids, count =0 ; +uint64_t mount_ids[LISTSIZE ];
testcases/kernel/syscalls/listmount/listmount02.c line 46
Quoted 10 lines
testcases/kernel/syscalls/listmount/listmount02.c new file +10
-0+uint64_t list[LISTSIZE ]; + +for (int i =0 ; i <BIND_MOUNTS ; i++) +SAFE_MOUNT ("/" ,"/" ,NULL ,MS_BIND ,NULL ); + +tst_res (TINFO ,"Reading all %d mount IDs in once" ,LISTSIZE ); + +TST_EXP_POSITIVE (listmount (LSMT_ROOT ,0 , mount_ids,LISTSIZE ,0 )); +if (TST_RET ==-1 ) + goto end;
Again this should be if (!TST_PASS)
Otherwise:
Signature · 5 lines
Cyril Hrubis [email protected] -- Mailing list info: https://lists.linux.it/listinfo/ltp
PATCH v4 6/13 Add statmount01 test
In reply to Andrea CervesatoFrom: Andrea Cervesato <[email protected]>
This test verifies that statmount() is working with no mask flags.
--- runtest/syscalls | 2 + testcases/kernel/syscalls/statmount/.gitignore | 1 + testcases/kernel/syscalls/statmount/Makefile | 7 ++ testcases/kernel/syscalls/statmount/statmount.h | 26 +++++++ testcases/kernel/syscalls/statmount/statmount01.c | 82 +++++++++++++++++++++++ 5 files changed, 118 insertions(+)
runtest/syscalls +2 -0
@@ -1568,6 +1568,8 @@ stat03_64 stat03_64 stat04 stat04 stat04_64 stat04_64 +statmount01 statmount01 + statfs01 statfs01 statfs01_64 statfs01_64 statfs02 statfs02
testcases/kernel/syscalls/statmount/.gitignore new file +1 -0
@@ -0,0 +1 @@ +statmount01
testcases/kernel/syscalls/statmount/Makefile new file +7 -0
@@ -0,0 +1,7 @@ +# SPDX-License-Identifier: GPL-2.0-or-later +# Copyright (C) 2024 SUSE LLC Andrea Cervesato <[email protected]> + +top_srcdir ?= ../../../.. + +include $(top_srcdir)/include/mk/testcases.mk +include $(top_srcdir)/include/mk/generic_leaf_target.mk
testcases/kernel/syscalls/statmount/statmount.h new file +26 -0
@@ -0,0 +1,26 @@ +/* SPDX-License-Identifier: GPL-2.0-or-later */ +/* +* Copyright (C) 2024 SUSE LLC Andrea Cervesato <[email protected]> +*/ + +#ifndef STATMOUNT_H + +#define _GNU_SOURCE + +#include "tst_test.h" +#include "lapi/mount.h" +#include "lapi/syscalls.h" + +static inline int statmount (uint64_t mnt_id,uint64_t mask,struct statmount *buf, +size_t bufsize,unsigned int flags) +{ +struct mnt_id_req req = { + .size =MNT_ID_REQ_SIZE_VER0 , + .mnt_id = mnt_id, + .param = mask, + }; + +return tst_syscall (__NR_statmount, &req, buf, bufsize, flags); +} + +#endif
testcases/kernel/syscalls/statmount/statmount01.c new file +82 -0
82 lines not on this page · raw message
Signature · 5 lines
2.43.0 -- Mailing list info: https://lists.linux.it/listinfo/ltp
Re: [LTP] [PATCH v4 06/13] Add statmount01 test
Hi!
testcases/kernel/syscalls/statmount/statmount.h line 6
Quoted 6 lines
testcases/kernel/syscalls/statmount/statmount.h new file +6
-0+/* SPDX-License-Identifier: GPL-2.0-or-later */ +/* +* Copyright (C) 2024 SUSE LLC Andrea Cervesato <[email protected]> +*/ + +#ifndef STATMOUNT_H
Here as well, missing #define STATMOUNT_H
Quoted 51 lines
testcases/kernel/syscalls/statmount/statmount.h new file +19
-0+#define _GNU_SOURCE + +#include "tst_test.h" +#include "lapi/mount.h" +#include "lapi/syscalls.h" + +static inline int statmount (uint64_t mnt_id,uint64_t mask,struct statmount *buf, +size_t bufsize,unsigned int flags) +{ +struct mnt_id_req req = { + .size =MNT_ID_REQ_SIZE_VER0 , + .mnt_id = mnt_id, + .param = mask, + }; + +return tst_syscall (__NR_statmount, &req, buf, bufsize, flags); +} + +#endif testcases/kernel/syscalls/statmount/statmount01.c new file +26
-0@@ -0,0 +1,82 @@ +// SPDX-License-Identifier: GPL-2.0-or-later +/* +* Copyright (C) 2024 SUSE LLC Andrea Cervesato <[email protected]> +*/ + +/*\ +* [Description] +* +* This test verifies that statmount() is working with no mask flags. +* +* [Algorithm] +* +* - create a mount point +* - run statmount() on the mount point without giving any mask +* - read results and check that mask and size are correct +*/ + +#define _GNU_SOURCE + +#include "statmount.h" +#include "lapi/stat.h" +#include "lapi/sched.h" + +#define MNTPOINT "mntpoint" + +static uint64_t root_id;
testcases/kernel/syscalls/statmount/statmount01.c line 36
Quoted 10 lines
testcases/kernel/syscalls/statmount/statmount01.c new file +10
-0+static struct statmount *st_mount; + +static void run (void ) +{ +memset (st_mount,0 ,sizeof (struct statmount )); + +TST_EXP_PASS (statmount (root_id,0 , st_mount,sizeof (struct statmount ),0 )); + +if (TST_RET ==-1 ) +return ;
Here if (!TST_PASS) as well.
Quoted 17 lines
testcases/kernel/syscalls/statmount/statmount01.c new file +17
-0+TST_EXP_EQ_LI (st_mount->size,sizeof (struct statmount )); +TST_EXP_EQ_LI (st_mount->mask,0 ); +TST_EXP_EQ_LI (st_mount->sb_dev_major,0 ); +TST_EXP_EQ_LI (st_mount->sb_dev_minor,0 ); +TST_EXP_EQ_LI (st_mount->sb_magic,0 ); +TST_EXP_EQ_LI (st_mount->sb_flags,0 ); +TST_EXP_EQ_LI (st_mount->fs_type,0 ); +TST_EXP_EQ_LI (st_mount->mnt_id,0 ); +TST_EXP_EQ_LI (st_mount->mnt_parent_id,0 ); +TST_EXP_EQ_LI (st_mount->mnt_id_old,0 ); +TST_EXP_EQ_LI (st_mount->mnt_parent_id_old,0 ); +TST_EXP_EQ_LI (st_mount->mnt_attr,0 ); +TST_EXP_EQ_LI (st_mount->mnt_propagation,0 ); +TST_EXP_EQ_LI (st_mount->mnt_peer_group,0 ); +TST_EXP_EQ_LI (st_mount->mnt_master,0 ); +TST_EXP_EQ_LI (st_mount->propagate_from,0 ); +TST_EXP_EQ_LI (st_mount->mnt_root,0 );
testcases/kernel/syscalls/statmount/statmount01.c line 64
Quoted 10 lines
testcases/kernel/syscalls/statmount/statmount01.c new file +10
-0+TST_EXP_EQ_LI (st_mount->mnt_point,0 ); +} + +static void setup (void ) +{ +struct ltp_statx sx; + +SAFE_STATX (AT_FDCWD ,MNTPOINT ,0 ,STATX_MNT_ID_UNIQUE , &sx); + + root_id = sx.data.stx_mnt_id;
Maybe this should be called mntpoint_id to make it less confusing.
testcases/kernel/syscalls/statmount/statmount01.c line 77
Quoted 13 lines
testcases/kernel/syscalls/statmount/statmount01.c new file +13
-0+} + +static struct tst_test test = { + .test_all = run, + .setup = setup, + .min_kver ="6.8" , + .mount_device =1 , + .mntpoint =MNTPOINT , + .all_filesystems =1 , + .skip_filesystems = (const char *const []) { +"fuse" , +NULL + },
I'm not sure that it makes sense to run this test for all filesystems, it's just at test that the returned buffer is untouched/cleared if we do not request any information. I bet that it does not call any filesystem specific code at all.
Quoted 5 lines
testcases/kernel/syscalls/statmount/statmount01.c new file +5
-0+ .bufs = (struct tst_buffers []) { + {&st_mount, .size =sizeof (struct statmount )}, + {} + } +};
Signature · 5 lines
Cyril Hrubis [email protected] -- Mailing list info: https://lists.linux.it/listinfo/ltp
PATCH v4 7/13 Add statmount02 test
In reply to Andrea CervesatoFrom: Andrea Cervesato <[email protected]>
This test verifies that statmount() is correctly reading basic filesystem info using STATMOUNT_SB_BASIC.
--- runtest/syscalls | 1 + testcases/kernel/syscalls/statmount/.gitignore | 1 + testcases/kernel/syscalls/statmount/statmount02.c | 84 +++++++++++++++++++++++ 3 files changed, 86 insertions(+)
runtest/syscalls +1 -0
@@ -1569,6 +1569,7 @@ stat04 stat04 stat04_64 stat04_64 statmount01 statmount01 +statmount02 statmount02 statfs01 statfs01 statfs01_64 statfs01_64
testcases/kernel/syscalls/statmount/.gitignore +1 -0
@@ -1 +1,2 @@ statmount01 +statmount02
testcases/kernel/syscalls/statmount/statmount02.c new file +84 -0
84 lines not on this page · raw message
Signature · 5 lines
2.43.0 -- Mailing list info: https://lists.linux.it/listinfo/ltp
Re: [LTP] [PATCH v4 07/13] Add statmount02 test
Hi!
testcases/kernel/syscalls/statmount/statmount02.c line 41
Quoted 9 lines
testcases/kernel/syscalls/statmount/statmount02.c new file +9
-0+static void run (void ) +{ +memset (st_mount,0 ,sizeof (struct statmount )); + +TST_EXP_PASS (statmount (sx_mount->data.stx_mnt_id,STATMOUNT_SB_BASIC , + st_mount,sizeof (struct statmount ),0 )); + +if (TST_RET ==-1 ) +return ;
Same here if (!TST_PASS)
The rest looks good:
Signature · 5 lines
Cyril Hrubis [email protected] -- Mailing list info: https://lists.linux.it/listinfo/ltp
PATCH v4 8/13 Add statmount03 test
In reply to Andrea CervesatoFrom: Andrea Cervesato <[email protected]>
This test verifies that statmount() is correctly reading mount information (mount id, parent mount id, mount attributes etc.) using STATMOUNT_MNT_BASIC.
--- runtest/syscalls | 1 + testcases/kernel/syscalls/statmount/.gitignore | 1 + testcases/kernel/syscalls/statmount/statmount.h | 24 ++++ testcases/kernel/syscalls/statmount/statmount03.c | 137 ++++++++++++++++++++++ 4 files changed, 163 insertions(+)
runtest/syscalls +1 -0
@@ -1570,6 +1570,7 @@ stat04_64 stat04_64 statmount01 statmount01 statmount02 statmount02 +statmount03 statmount03 statfs01 statfs01 statfs01_64 statfs01_64
testcases/kernel/syscalls/statmount/.gitignore +1 -0
@@ -1,2 +1,3 @@ statmount01 statmount02 +statmount03
testcases/kernel/syscalls/statmount/statmount.h +24 -0
@@ -10,6 +10,7 @@#include "tst_test.h" #include "lapi/mount.h" #include "lapi/syscalls.h" +#include "tst_safe_stdio.h" static inline int statmount (uint64_t mnt_id,uint64_t mask,struct statmount *buf,size_t bufsize,unsigned int flags)
@@ -23,4 +24,27 @@ static inline int statmount(uint64_t mnt_id, uint64_t mask, struct statmount *bu return tst_syscall(__NR_statmount, &req, buf, bufsize, flags); } +static inline int read_peer_group (const char *path) +{ +FILE *file; +char line[PATH_MAX ]; +char mroot[PATH_MAX ]; +int group =-1 ; + + file =SAFE_FOPEN ("/proc/self/mountinfo" ,"r" ); + +while (fgets (line,sizeof (line), file)) { +if (sscanf (line,"%*d %*d %*d:%*d %s %*s %*s shared:%d" , mroot, &group) !=2 ) +continue ; + +if (strcmp (mroot, path) ==0 ) +break ; + } + +if (group ==-1 ) +tst_brk (TBROK ,"Can't reed peer group ID for %s" , path); + +return group; +} +#endif
testcases/kernel/syscalls/statmount/statmount03.c new file +137 -0
137 lines not on this page · raw message
Signature · 5 lines
2.43.0 -- Mailing list info: https://lists.linux.it/listinfo/ltp
Re: [LTP] [PATCH v4 08/13] Add statmount03 test
Hi!
Quoted 121 lines
This test verifies that
statmount()is correctly reading mount information (mount id, parent mount id, mount attributes etc.) usingSTATMOUNT_MNT_BASIC.Signed-off-by Andrea Cervesato <[email protected]>--- runtest/syscalls | 1 + testcases/kernel/syscalls/statmount/.gitignore | 1 + testcases/kernel/syscalls/statmount/statmount.h | 24 ++++ testcases/kernel/syscalls/statmount/statmount03.c | 137 ++++++++++++++++++++++ 4 files changed, 163 insertions(+)runtest/syscalls +1
-0@@ -1570,6 +1570,7 @@ stat04_64 stat04_64 statmount01 statmount01 statmount02 statmount02 +statmount03 statmount03 statfs01 statfs01 statfs01_64 statfs01_64testcases/kernel/syscalls/statmount/.gitignore +1
-0@@ -1,2 +1,3 @@ statmount01 statmount02 +statmount03testcases/kernel/syscalls/statmount/statmount.h +24
-0@@ -10,6 +10,7 @@#include "tst_test.h" #include "lapi/mount.h" #include "lapi/syscalls.h" +#include "tst_safe_stdio.h" static inline int statmount (uint64_t mnt_id,uint64_t mask,struct statmount *buf,size_t bufsize,unsigned int flags)@@ -23,4 +24,27 @@ static inline int statmount(uint64_t mnt_id, uint64_t mask, struct statmount *bu return tst_syscall(__NR_statmount, &req, buf, bufsize, flags); } +static inline int read_peer_group (const char *path) +{ +FILE *file; +char line[PATH_MAX ]; +char mroot[PATH_MAX ]; +int group =-1 ; + + file =SAFE_FOPEN ("/proc/self/mountinfo" ,"r" ); + +while (fgets (line,sizeof (line), file)) { +if (sscanf (line,"%*d %*d %*d:%*d %s %*s %*s shared:%d" , mroot, &group) !=2 ) +continue ; + +if (strcmp (mroot, path) ==0 ) +break ; + } + +if (group ==-1 ) +tst_brk (TBROK ,"Can't reed peer group ID for %s" , path); + +return group; +} +#endif testcases/kernel/syscalls/statmount/statmount03.c new file +43
-0@@ -0,0 +1,137 @@ +// SPDX-License-Identifier: GPL-2.0-or-later +/* +* Copyright (C) 2024 SUSE LLC Andrea Cervesato <[email protected]> +*/ + +/*\ +* [Description] +* +* This test verifies that statmount() is correctly reading mount information +* (mount id, parent mount id, mount attributes etc.) using STATMOUNT_MNT_BASIC. +* +* [Algorithm] +* +* - create a mount point +* - create a new parent folder inside the mount point and obtain its mount info +* - create the new "/" mount folder and obtain its mount info +* - run statmount() on the mount point using STATMOUNT_MNT_BASIC +* - read results and check if mount info are correct +*/ + +#define _GNU_SOURCE + +#include "statmount.h" +#include "lapi/stat.h" +#include "lapi/sched.h" + +#define DIR_A "LTP_DIR_A" +#define DIR_B "LTP_DIR_B" + +static uint64_t mnt_id; +static uint64_t mnt_id_old; +static uint64_t parent_id; +static uint64_t parent_id_old; +static uint64_t mnt_peer_group; +static uint64_t mnt_master; +static struct statmount *st_mount; + +static void read_mnt_id ( +const char *path, +uint64_t *mnt_id, +uint64_t *mnt_id_unique) +{ +struct ltp_statx sx;
testcases/kernel/syscalls/statmount/statmount03.c line 53
Quoted 10 lines
testcases/kernel/syscalls/statmount/statmount03.c new file +10
-0+ +if (mnt_id) { +SAFE_STATX (AT_FDCWD , path,0 ,STATX_MNT_ID , &sx); + *mnt_id = sx.data.stx_mnt_id; + } + +if (mnt_id_unique) { +SAFE_STATX (AT_FDCWD , path,0 ,STATX_MNT_ID_UNIQUE , &sx); + *mnt_id_unique = sx.data.stx_mnt_id; + }
Technically the stx_mnt_id is only valid if the sx.data.stx_mask has the STATX_MNT_ID or STATX_MNT_ID_UNIQUE set when statx() returns.
We have min_kver set to 6.8 so this should always work, but it wouldn't hurt to double check.
Quoted 21 lines
testcases/kernel/syscalls/statmount/statmount03.c new file +21
-0+} + +static struct tcase { +uint64_t prop_type; +char *msg; +} tcases[] = { + {MS_PRIVATE ,TST_TO_STR_ (MS_PRIVATE ) }, + {MS_SHARED ,TST_TO_STR_ (MS_SHARED ) }, + {MS_SLAVE ,TST_TO_STR_ (MS_SLAVE ) }, + {MS_UNBINDABLE ,TST_TO_STR_ (MS_UNBINDABLE ) }, +}; + +static void run (unsigned int i) +{ +struct tcase *tc = &tcases[i]; + +tst_res (TINFO ,"Testing statmount() on %s" , tc->msg); + +SAFE_MOUNT (DIR_B ,DIR_A ,"none" ,MS_BIND ,NULL ); +SAFE_MOUNT ("none" ,DIR_A ,"none" , tc->prop_type,NULL ); +read_mnt_id (DIR_A , &mnt_id_old, &mnt_id);
testcases/kernel/syscalls/statmount/statmount03.c line 84
Quoted 10 lines
testcases/kernel/syscalls/statmount/statmount03.c new file +10
-0+ +memset (st_mount,0 ,sizeof (struct statmount )); + +TST_EXP_PASS (statmount (mnt_id,STATMOUNT_MNT_BASIC , st_mount, +sizeof (struct statmount ),0 )); + +SAFE_UMOUNT (DIR_A ); + +if (TST_RET ==-1 ) +return ;
Here as well if (!TST_PASS)
testcases/kernel/syscalls/statmount/statmount03.c line 88
Quoted 3 lines
testcases/kernel/syscalls/statmount/statmount03.c new file +3
-0+/* s->sm.mnt_peer_group = IS_MNT_SHARED(m) ? m->mnt_group_id : 0; +* s->sm.mnt_master = IS_MNT_SLAVE(m) ? m->mnt_master->mnt_group_id : 0; +*/
This comment looks like a leftover.
testcases/kernel/syscalls/statmount/statmount03.c line 101
Quoted 13 lines
testcases/kernel/syscalls/statmount/statmount03.c new file +13
-0+ mnt_peer_group = tc->prop_type ==MS_SHARED ?read_peer_group (DIR_A ) :0 ; + mnt_master = tc->prop_type ==MS_SLAVE ?read_peer_group (DIR_A ) :0 ; + +TST_EXP_EQ_LI (st_mount->mask,STATMOUNT_MNT_BASIC ); +TST_EXP_EQ_LI (st_mount->size,sizeof (struct statmount )); +TST_EXP_EQ_LI (st_mount->mnt_id, mnt_id); +TST_EXP_EQ_LI (st_mount->mnt_id_old, mnt_id_old); +TST_EXP_EQ_LI (st_mount->mnt_parent_id, parent_id); +TST_EXP_EQ_LI (st_mount->mnt_parent_id_old, parent_id_old); +TST_EXP_EQ_LU (st_mount->mnt_propagation & tc->prop_type, tc->prop_type); +TST_EXP_EQ_LI (st_mount->mnt_master, mnt_master); +TST_EXP_EQ_LI (st_mount->mnt_peer_group, mnt_peer_group); +}
Otherwise it looks good:
Signature · 5 lines
Cyril Hrubis [email protected] -- Mailing list info: https://lists.linux.it/listinfo/ltp
PATCH v4 9/13 Add statmount04 test
In reply to Andrea CervesatoFrom: Andrea Cervesato <[email protected]>
This test verifies that statmount() is correctly reading propagation from what mount in current namespace using STATMOUNT_PROPAGATE_FROM.
--- runtest/syscalls | 1 + testcases/kernel/syscalls/statmount/.gitignore | 1 + testcases/kernel/syscalls/statmount/statmount04.c | 105 ++++++++++++++++++++++ 3 files changed, 107 insertions(+)
runtest/syscalls +1 -0
@@ -1571,6 +1571,7 @@ stat04_64 stat04_64 statmount01 statmount01 statmount02 statmount02 statmount03 statmount03 +statmount04 statmount04 statfs01 statfs01 statfs01_64 statfs01_64
testcases/kernel/syscalls/statmount/.gitignore +1 -0
@@ -1,3 +1,4 @@ statmount01 statmount02 statmount03 +statmount04
testcases/kernel/syscalls/statmount/statmount04.c new file +105 -0
105 lines not on this page · raw message
Signature · 5 lines
2.43.0 -- Mailing list info: https://lists.linux.it/listinfo/ltp
Re: [LTP] [PATCH v4 09/13] Add statmount04 test
Hi!
Quoted 31 lines
testcases/kernel/syscalls/statmount/statmount04.c new file +31
-0+/*\ +* [Description] +* +* This test verifies that statmount() is correctly reading propagation from +* what mount in current namespace using STATMOUNT_PROPAGATE_FROM. +* +* [Algorithm] +* +* - create a mount point +* - propagate a mounted folder inside the mount point +* - run statmount() on the mount point using STATMOUNT_PROPAGATE_FROM +* - read results and check propagated_from parameter contains the propagated +* folder ID +*/ + +#define _GNU_SOURCE + +#include "statmount.h" +#include "lapi/stat.h" +#include "lapi/sched.h" + +#define MNTPOINT "mntpoint" +#define DIR_A MNTPOINT "/LTP_DIR_A" +#define DIR_C_SUBFOLDER "/LTP_DIR_A/propagated" +#define DIR_C (MNTPOINT DIR_C_SUBFOLDER) +#define DIR_B MNTPOINT "/LTP_DIR_B" +#define DIR_D MNTPOINT "/LTP_DIR_B/propagated" + +static uint64_t peer_group_id; +static uint64_t dird_id; +static struct statmount *st_mount;
testcases/kernel/syscalls/statmount/statmount04.c line 46
Quoted 10 lines
testcases/kernel/syscalls/statmount/statmount04.c new file +10
-0+ +static void run (void ) +{ +memset (st_mount,0 ,sizeof (struct statmount )); + +TST_EXP_PASS (statmount (dird_id,STATMOUNT_PROPAGATE_FROM , st_mount, +sizeof (struct statmount ),0 )); + +if (TST_RET ==-1 ) +return ;
Again if (!TST_PASS)
Quoted 48 lines
testcases/kernel/syscalls/statmount/statmount04.c new file +48
-0+TST_EXP_EQ_LI (st_mount->mask,STATMOUNT_PROPAGATE_FROM ); +TST_EXP_EQ_LI (st_mount->size,sizeof (struct statmount )); +TST_EXP_EQ_LI (st_mount->propagate_from, peer_group_id); +} + +static void setup (void ) +{ +struct ltp_statx sx; + +/* create DIR_A / DIR_C structure with DIR_C mounted */ +SAFE_MKDIR (DIR_A ,0700 ); +SAFE_MOUNT (DIR_A ,DIR_A ,"none" ,MS_BIND ,NULL ); +SAFE_MOUNT ("none" ,DIR_A ,"none" ,MS_SHARED ,NULL ); + +SAFE_MKDIR (DIR_C ,0700 ); +SAFE_MOUNT (DIR_C ,DIR_C ,"none" ,MS_BIND ,NULL ); +SAFE_MOUNT ("none" ,DIR_C ,"none" ,MS_SHARED ,NULL ); + +/* DIR_A mounts into DIR_B. DIR_D is propagated */ +SAFE_MKDIR (DIR_B ,0700 ); +SAFE_MOUNT (DIR_A ,DIR_B ,"none" ,MS_BIND ,NULL ); +SAFE_MOUNT ("none" ,DIR_B ,"none" ,MS_SLAVE ,NULL ); + +SAFE_STATX (AT_FDCWD ,DIR_D ,0 ,STATX_MNT_ID_UNIQUE , &sx); + dird_id = sx.data.stx_mnt_id; + + peer_group_id =read_peer_group (DIR_A ); +} + +static void cleanup (void ) +{ +if (tst_is_mounted (DIR_C )) +SAFE_UMOUNT (DIR_C ); + +if (tst_is_mounted (DIR_B )) +SAFE_UMOUNT (DIR_B ); + +if (tst_is_mounted (DIR_A )) +SAFE_UMOUNT (DIR_A ); +} + +static struct tst_test test = { + .test_all = run, + .setup = setup, + .cleanup = cleanup, + .min_kver ="6.8" , + .mount_device =1 , + .mntpoint =MNTPOINT ,
testcases/kernel/syscalls/statmount/statmount04.c line 105
Quoted 10 lines
testcases/kernel/syscalls/statmount/statmount04.c new file +10
-0+ .all_filesystems = 1, + .skip_filesystems = (const char *const []) { +"fuse" , +NULL + }, + .bufs = (struct tst_buffers []) { + {&st_mount, .size =sizeof (struct statmount )}, + {} + } +};
Otherwise:
Signature · 5 lines
Cyril Hrubis [email protected] -- Mailing list info: https://lists.linux.it/listinfo/ltp
PATCH v4 10/13 Add statmount05 test
In reply to Andrea CervesatoFrom: Andrea Cervesato <[email protected]>
This test verifies STATMOUNT_MNT_ROOT and STATMOUNT_MNT_POINT functionalities of statmount().
--- runtest/syscalls | 1 + testcases/kernel/syscalls/statmount/.gitignore | 1 + testcases/kernel/syscalls/statmount/statmount05.c | 128 ++++++++++++++++++++++ 3 files changed, 130 insertions(+)
runtest/syscalls +1 -0
@@ -1572,6 +1572,7 @@ statmount01 statmount01 statmount02 statmount02 statmount03 statmount03 statmount04 statmount04 +statmount05 statmount05 statfs01 statfs01 statfs01_64 statfs01_64
testcases/kernel/syscalls/statmount/.gitignore +1 -0
@@ -2,3 +2,4 @@ statmount01 statmount02 statmount03 statmount04 +statmount05
testcases/kernel/syscalls/statmount/statmount05.c new file +128 -0
128 lines not on this page · raw message
Signature · 5 lines
2.43.0 -- Mailing list info: https://lists.linux.it/listinfo/ltp
Re: [LTP] [PATCH v4 10/13] Add statmount05 test
Hi!
Quoted 80 lines
This test verifies
STATMOUNT_MNT_ROOTandSTATMOUNT_MNT_POINTfunctionalities ofstatmount().Signed-off-by Andrea Cervesato <[email protected]>--- runtest/syscalls | 1 + testcases/kernel/syscalls/statmount/.gitignore | 1 + testcases/kernel/syscalls/statmount/statmount05.c | 128 ++++++++++++++++++++++ 3 files changed, 130 insertions(+)runtest/syscalls +1
-0@@ -1572,6 +1572,7 @@ statmount01 statmount01 statmount02 statmount02 statmount03 statmount03 statmount04 statmount04 +statmount05 statmount05 statfs01 statfs01 statfs01_64 statfs01_64testcases/kernel/syscalls/statmount/.gitignore +1
-0@@ -2,3 +2,4 @@ statmount01 statmount02 statmount03 statmount04 +statmount05testcases/kernel/syscalls/statmount/statmount05.c new file +43
-0@@ -0,0 +1,128 @@ +// SPDX-License-Identifier: GPL-2.0-or-later +/* +* Copyright (C) 2024 SUSE LLC Andrea Cervesato <[email protected]> +*/ + +/*\ +* [Description] +* +* This test verifies STATMOUNT_MNT_ROOT and STATMOUNT_MNT_POINT functionalities +* of statmount(). In particular, STATMOUNT_MNT_ROOT will give the mount root +* (i.e. mount --bind /mnt /bla -> /mnt) and STATMOUNT_MNT_POINT will +* give the mount point (i.e. mount --bind /mnt /bla -> /bla). +* +* [Algorithm] +* +* - create a mount point +* - mount a folder inside the mount point +* - run statmount() on the mounted folder using STATMOUNT_MNT_ROOT +* - read results and check if contain the mount root path +* - run statmount() on the mounted folder using STATMOUNT_MNT_POINT +* - read results and check if contain the mount point path +*/ + +#define _GNU_SOURCE + +#include "statmount.h" +#include "lapi/stat.h" +#include "lapi/sched.h" +#include "tst_tmpdir.h" + +#define MNTPOINT "mntpoint" +#define DIRA MNTPOINT "/LTP_DIR_A" +#define DIRB MNTPOINT "/LTP_DIR_B" +#define SM_SIZE (1 << 10) + +static uint64_t root_id; +static struct statmount *st_mount; +static char *mnt_root; +static char *mnt_point; + +static void test_mount_root (void ) +{ +tst_res (TINFO ,"Testing STATMOUNT_MNT_ROOT" );
testcases/kernel/syscalls/statmount/statmount05.c line 53
Quoted 10 lines
testcases/kernel/syscalls/statmount/statmount05.c new file +10
-0+ +char *last_root; + +memset (st_mount,0 ,SM_SIZE ); + +TST_EXP_PASS (statmount (root_id,STATMOUNT_MNT_ROOT , st_mount, +SM_SIZE ,0 )); + +if (TST_RET ==-1 ) +return ;
if (!TST_PASSED)
testcases/kernel/syscalls/statmount/statmount05.c line 61
Quoted 7 lines
testcases/kernel/syscalls/statmount/statmount05.c new file +7
-0+ last_root =strrchr (mnt_root,'/' ); + +TST_EXP_EQ_LI (st_mount->mask,STATMOUNT_MNT_ROOT ); +TST_EXP_EXPR (strcmp (st_mount->str + st_mount->mnt_root, last_root) ==0 , +"statmount() read '%s', expected '%s'" , + st_mount->str + st_mount->mnt_root, + last_root);
You have added TST_EXP_EQ_STR() in an subsequent patch, you should use it here as well.
testcases/kernel/syscalls/statmount/statmount05.c line 74
Quoted 13 lines
testcases/kernel/syscalls/statmount/statmount05.c new file +13
-0+} + +static void test_mount_point (void ) +{ +tst_res (TINFO ,"Testing STATMOUNT_MNT_POINT" ); + +memset (st_mount,0 ,SM_SIZE ); + +TST_EXP_POSITIVE (statmount (root_id,STATMOUNT_MNT_POINT , st_mount, +SM_SIZE ,0 )); + +if (TST_RET ==-1 ) +return ;
Here as well.
testcases/kernel/syscalls/statmount/statmount05.c line 79
Quoted 4 lines
testcases/kernel/syscalls/statmount/statmount05.c new file +4
-0+TST_EXP_EQ_LI (st_mount->mask,STATMOUNT_MNT_POINT ); +TST_EXP_EXPR (strcmp (st_mount->str + st_mount->mnt_point, mnt_point) ==0 , +"mount point is '%s'" , + st_mount->str + st_mount->mnt_point);
And here as well.
Quoted 4 lines
testcases/kernel/syscalls/statmount/statmount05.c new file +4
-0+} + +static void run (void ) +{
testcases/kernel/syscalls/statmount/statmount05.c line 93
Quoted 10 lines
testcases/kernel/syscalls/statmount/statmount05.c new file +10
-0+test_mount_root (); +test_mount_point (); +} + +static void setup (void ) +{ +struct ltp_statx sx; + + mnt_root =tst_tmpdir_mkpath (DIRA ); + mnt_point =tst_tmpdir_mkpath (DIRB );
This was renamed to tst_tmpdir_genpath()
Quoted 34 lines
testcases/kernel/syscalls/statmount/statmount05.c new file +34
-0+SAFE_MKDIR (mnt_root,0700 ); +SAFE_MKDIR (mnt_point,0700 ); +SAFE_MOUNT (mnt_root, mnt_point,"none" ,MS_BIND ,NULL ); + +SAFE_STATX (AT_FDCWD , mnt_point,0 ,STATX_MNT_ID_UNIQUE , &sx); + root_id = sx.data.stx_mnt_id; +} + +static void cleanup (void ) +{ +if (tst_is_mounted (DIRB )) +SAFE_UMOUNT (DIRB ); + +if (tst_is_mounted (DIRA )) +SAFE_UMOUNT (DIRA ); +} + +static struct tst_test test = { + .test_all = run, + .setup = setup, + .cleanup = cleanup, + .min_kver ="6.8" , + .mount_device =1 , + .mntpoint =MNTPOINT , + .all_filesystems =1 , + .skip_filesystems = (const char *const []) { +"fuse" , +NULL + }, + .bufs = (struct tst_buffers []) { + {&st_mount, .size =SM_SIZE }, + {} + } +};
Signature · 5 lines
Cyril Hrubis [email protected] -- Mailing list info: https://lists.linux.it/listinfo/ltp
PATCH v4 11/13 Add TST_EXP_EQ_STR macro
In reply to Andrea CervesatoFrom: Andrea Cervesato <[email protected]>
--- include/tst_test_macros.h | 14 ++++++++++++++ 1 file changed, 14 insertions(+)
include/tst_test_macros.h +14 -0
@@ -369,4 +369,18 @@ const char *tst_errno_names(char *buf, const int *exp_errs, int exp_errs_cnt);#define TST_EXP_EQ_SSZ (VAL_A ,VAL_B ) \ TST_EXP_EQ_(VAL_A, #VAL_A, VAL_B, #VAL_B, ssize_t, "%zi") +#define TST_EXP_EQ_STR (STR_A ,STR_B ) do { \ + TST_PASS = strcmp(STR_A, STR_B) == 0; \ + \ + if (TST_PASS) { \ + tst_res_(__FILE__, __LINE__, TPASS, \ + "%s == %s (%s)", \ + #STR_A, #STR_B, STR_B); \ + } else { \ + tst_res_(__FILE__, __LINE__, TFAIL, \ + "%s (%s) != %s (%s)", \ + #STR_A, STR_A, #STR_B, STR_B); \ + } \ +} while (0) +#endif /* TST_TEST_MACROS_H__ */
Signature · 5 lines
2.43.0 -- Mailing list info: https://lists.linux.it/listinfo/ltp
Re: [LTP] [PATCH v4 11/13] Add TST_EXP_EQ_STR macro
Hi!
Signature · 5 lines
Cyril Hrubis [email protected] -- Mailing list info: https://lists.linux.it/listinfo/ltp
PATCH v4 12/13 Add statmount06 test
In reply to Andrea CervesatoFrom: Andrea Cervesato <[email protected]>
This test verifies that statmount() is correctly reading name of the filesystem type using STATMOUNT_FS_TYPE.
--- runtest/syscalls | 1 + testcases/kernel/syscalls/statmount/.gitignore | 1 + testcases/kernel/syscalls/statmount/statmount06.c | 68 +++++++++++++++++++++++ 3 files changed, 70 insertions(+)
runtest/syscalls +1 -0
@@ -1573,6 +1573,7 @@ statmount02 statmount02 statmount03 statmount03 statmount04 statmount04 statmount05 statmount05 +statmount06 statmount06 statfs01 statfs01 statfs01_64 statfs01_64
testcases/kernel/syscalls/statmount/.gitignore +1 -0
@@ -3,3 +3,4 @@ statmount02 statmount03 statmount04 statmount05 +statmount06
testcases/kernel/syscalls/statmount/statmount06.c new file +68 -0
68 lines not on this page · raw message
Signature · 5 lines
2.43.0 -- Mailing list info: https://lists.linux.it/listinfo/ltp
Re: [LTP] [PATCH v4 12/13] Add statmount06 test
Hi!
testcases/kernel/syscalls/statmount/statmount06.c line 39
Quoted 2 lines
testcases/kernel/syscalls/statmount/statmount06.c new file +2
-0+if (TST_RET ==-1 ) +return ;
if (!TST_PASS)
Otherwise:
Signature · 5 lines
Cyril Hrubis [email protected] -- Mailing list info: https://lists.linux.it/listinfo/ltp
PATCH v4 13/13 Add statmount07 test
In reply to Andrea CervesatoFrom: Andrea Cervesato <[email protected]>
This test is verifying that statmount syscall is raising the correct errors according with invalid input values.
--- runtest/syscalls | 1 + testcases/kernel/syscalls/statmount/.gitignore | 1 + testcases/kernel/syscalls/statmount/statmount07.c | 75 +++++++++++++++++++++++ 3 files changed, 77 insertions(+)
runtest/syscalls +1 -0
@@ -1574,6 +1574,7 @@ statmount03 statmount03 statmount04 statmount04 statmount05 statmount05 statmount06 statmount06 +statmount07 statmount07 statfs01 statfs01 statfs01_64 statfs01_64
testcases/kernel/syscalls/statmount/.gitignore +1 -0
@@ -4,3 +4,4 @@ statmount03 statmount04 statmount05 statmount06 +statmount07
testcases/kernel/syscalls/statmount/statmount07.c new file +75 -0
75 lines not on this page · raw message
Signature · 5 lines
2.43.0 -- Mailing list info: https://lists.linux.it/listinfo/ltp
Re: [LTP] [PATCH v4 13/13] Add statmount07 test
Hi!
testcases/kernel/syscalls/statmount/statmount07.c line 25
Quoted 6 lines
testcases/kernel/syscalls/statmount/statmount07.c new file +6
-0+static struct statmount *st_mount; +static struct statmount *st_mount_null; +static uint64_t mnt_id; +static uint64_t mnt_id_dont_exist =-1 ; +static size_t buff_size; +static size_t buff_size_invalid =-1 ;
I suppose that we can as well add buff_size_zero, I would expected getting EINVAL from such test.
Otherwise:
Signature · 5 lines
Cyril Hrubis [email protected] -- Mailing list info: https://lists.linux.it/listinfo/ltp
Re: [LTP] [PATCH v4 13/13] Add statmount07 test
Hi!
Quoted 9 lines · Cyril Hrubis
Hi!
testcases/kernel/syscalls/statmount/statmount07.c line 25
Quoted 6 lines
testcases/kernel/syscalls/statmount/statmount07.c new file +6
-0+static struct statmount *st_mount; +static struct statmount *st_mount_null; +static uint64_t mnt_id; +static uint64_t mnt_id_dont_exist =-1 ; +static size_t buff_size; +static size_t buff_size_invalid =-1 ;I suppose that we can as well add
buff_size_zero, I would expected getting EINVAL from such test.
That seems to be a valid value, since I get PASS. Kernel bug?
Quoted 4 lines
Otherwise:
Reviewed-by Cyril Hrubis <[email protected]>
Andrea
Signature · 1 line
Mailing list info: https://lists.linux.it/listinfo/ltp
Re: [LTP] [PATCH v4 13/13] Add statmount07 test
Hi!
Quoted 1 line
That seems to be a valid value, since I get PASS. Kernel bug?
Looking at kernel it's a bit confusing, the bufsize is supposed to be the size of the structure plus the buffer allocated for the string reply. Which makes the code more complicated than it could have been if these two were separeted properly.
However we do have:
if (kbufsize >= s->bufsize)
return -EOVERFLOW;in statmount_string(), so we will trigger the error there if we pass one of the requests that is supposed to produce a string reply.
But there seems to be something strange going on in the prepare_kstatmount() as well, we do have:
if (ks->mask & STATMOUNT_STRING_REQ) {
if (bufsize == sizeof(ks->sm))
return -EOVERFLOW;
^ This line should probably be if (bufsize <= sizeof(ks->sm))
because we are trying to make sure that the structure is large
enough that we can write at the offset where the
string area starts.
It seems to be guarded by the checks in
statmount_string() later on as well, so I suppose that we
will trigger the EOVERFLOW slightly later if this does not
work though. CCying Jan to have a look.
ks->seq.buf = kvmalloc(seq_size, GFP_KERNEL_ACCOUNT);
if (!ks->seq.buf)
return -ENOMEM;
ks->seq.size = seq_size;
}However the size seems to be properly used in thecopy_statmount_to_user()
size_t copysize = min_t(size_t, s->bufsize, sizeof(*sm));
...
if (copy_to_user(s->buf, sm, copysize))
return -EFAULT;This means that we will copy as much of the statmount structure to userspace as we requested, so in the case that we pass 0 as bufsize none of the data should be copied and indeed we should get back success.
Signature · 5 lines
Cyril Hrubis [email protected] -- Mailing list info: https://lists.linux.it/listinfo/ltp
Re: [LTP] [PATCH v4 13/13] Add statmount07 test
Thanks for the explanation! I will fix the other patches and send the new version.
Andrea
Quoted 59 lines · Cyril Hrubis
Hi!
Quoted 1 line
That seems to be a valid value, since I get PASS. Kernel bug?
Looking at kernel it's a bit confusing, the bufsize is supposed to be the size of the structure plus the buffer allocated for the string reply. Which makes the code more complicated than it could have been if these two were separeted properly.
However we do have:
if (kbufsize >= s->bufsize) return -EOVERFLOW;in
statmount_string(), so we will trigger the error there if we pass one of the requests that is supposed to produce a string reply.But there seems to be something strange going on in the
prepare_kstatmount()as well, we do have:if (ks->mask & STATMOUNT_STRING_REQ) { if (bufsize == sizeof(ks->sm)) return -EOVERFLOW; ^ This line should probably be if (bufsize <= sizeof(ks->sm)) because we are trying to make sure that the structure is large enough that we can write at the offset where the string area starts. It seems to be guarded by the checks in statmount_string() later on as well, so I suppose that we will trigger the EOVERFLOW slightly later if this does not work though. CCying Jan to have a look. ks->seq.buf = kvmalloc(seq_size, GFP_KERNEL_ACCOUNT); if (!ks->seq.buf) return -ENOMEM; ks->seq.size = seq_size; }However the size seems to be properly used in the
copy_statmount_to_user()size_t copysize = min_t(size_t, s->bufsize, sizeof(*sm)); ... if (copy_to_user(s->buf, sm, copysize)) return -EFAULT;This means that we will copy as much of the statmount structure to userspace as we requested, so in the case that we pass 0 as bufsize none of the data should be copied and indeed we should get back success.
Signature · 1 line
Mailing list info: https://lists.linux.it/listinfo/ltp
Re: [LTP] [PATCH v4 13/13] Add statmount07 test
In reply to Cyril HrubisHi!
Quoted 8 lines · Cyril Hrubis
Quoted 1 line
That seems to be a valid value, since I get PASS. Kernel bug?
Looking at kernel it's a bit confusing, the bufsize is supposed to be the size of the structure plus the buffer allocated for the string reply. Which makes the code more complicated than it could have been if these two were separeted properly.
Quoted 7 lines
However we do have:
if (kbufsize >= s->bufsize) return -EOVERFLOW;in
statmount_string(), so we will trigger the error there if we pass one of the requests that is supposed to produce a string reply.
Yes, if STATMOUNT_STRING_REQ is set, the above check should always make sure bufsize is large enough.
Quoted 12 lines
But there seems to be something strange going on in the
prepare_kstatmount()as well, we do have:if (
ks->mask&STATMOUNT_STRING_REQ) {
if (bufsize ==sizeof(ks->sm))
return-EOVERFLOW;^ This line should probably be if (bufsize <=
sizeof(ks->sm))
because we are trying to make sure that the structure is large enough that we can write at the offset where the string area starts.
Quoted 4 lines
It seems to be guarded by the checks in
statmount_string()later on as well, so I suppose that we will trigger the EOVERFLOW slightly later if this does not work though. CCying Jan to have a look.
Yup, this looks confusing to me as well. Christian, is this check indeed meant to bail early if the buffer obviously is not large enough? Shouldn't it then be <= as Cyril suggests? I have a feeling I might be missing some "extensible syscall" magic that does the check bufsize < sizeof(struct) automatically somewhere but I could not find it...
Honza
Signature · 5 lines
Jan Kara <[email protected]> SUSE Labs, CR -- Mailing list info: https://lists.linux.it/listinfo/ltp
Hi!
And we still need an invalid parameters for listmount() test I suppose.
I suppose that we can at least pass invalid size, flags and invalid mnt_id and invalid param.
Also we should add a check for EPERM with LISTMOUNT_UNREACHABLE and unpriviledged user.
See errors at:
https://lore.kernel.org/linux-man/[email protected]/T/#m0eba3ca21ebf29bd5a5cfe681fc4cb2b9aa7f6e7
Signature · 5 lines
Cyril Hrubis [email protected] -- Mailing list info: https://lists.linux.it/listinfo/ltp