syscalls/statx09: Add new test
PATCH RESEND 1/1 syscalls/statx09: Add new test
This test is basically the same as statx04 but here we check for the STATX_ATTR_VERITY flag which is currently only implemented on ext4.
--- configure.ac | 1 + include/lapi/fs.h | 4 + include/lapi/fsverity.h | 38 ++++++ include/lapi/stat.h | 4 + m4/ltp-fsverity.m4 | 22 ++++ runtest/syscalls | 1 + testcases/kernel/syscalls/statx/.gitignore | 1 + testcases/kernel/syscalls/statx/statx09.c | 200 +++++++++++++++++++++++++++++ 8 files changed, 271 insertions(+) create mode 100644 include/lapi/fsverity.h create mode 100644 m4/ltp-fsverity.m4 create mode 100644 testcases/kernel/syscalls/statx/statx09.c
configure.ac +1 -0
@@ -367,6 +367,7 @@ LTP_CHECK_SELINUX LTP_CHECK_SYNC_ADD_AND_FETCH LTP_CHECK_SYSCALL_EVENTFD LTP_CHECK_SYSCALL_FCNTL +LTP_CHECK_FSVERITY if test "x$with_numa" = xyes; then LTP_CHECK_SYSCALL_NUMA
include/lapi/fs.h +4 -0
@@ -41,6 +41,10 @@#define FS_NODUMP_FL 0x00000040/* do not dump file */ #endif +#ifndef FS_VERITY_FL +#define FS_VERITY_FL 0x00100000/* Verity protected inode */ +#endif +/* * Helper function to get MAX_LFS_FILESIZE. * Missing PAGE_SHIFT on some libc prevents defining MAX_LFS_FILESIZE.
include/lapi/fsverity.h new file +38 -0
@@ -0,0 +1,38 @@ +// SPDX-License-Identifier: GPL-2.0-or-later +/* +* Copyright (c) 2022 FUJITSU LIMITED. All rights reserved. +* Author: Dai Shili <[email protected]> +*/ +#ifndef LAPI_FSVERITY_H__ +#define LAPI_FSVERITY_H__ + +#include "config.h" +#include <linux/types.h> + +#ifdef HAVE_LINUX_FSVERITY_H +#include <linux/fsverity.h> +#endif + +#ifndef FS_VERITY_HASH_ALG_SHA256 +# define FS_VERITY_HASH_ALG_SHA256 1 +#endif + +#ifndef FS_IOC_ENABLE_VERITY +# define FS_IOC_ENABLE_VERITY _IOW('f', 133, struct fsverity_enable_arg) +#endif + +#ifndef HAVE_STRUCT_FSVERITY_ENABLE_ARG +struct fsverity_enable_arg { +__u32 version; +__u32 hash_algorithm; +__u32 block_size; +__u32 salt_size; +__u64 salt_ptr; +__u32 sig_size; +__u32 __reserved1; +__u64 sig_ptr; +__u64 __reserved2[11 ]; +}; +#endif + +#endif
include/lapi/stat.h +4 -0
@@ -223,6 +223,10 @@ static inline int statx(int dirfd, const char *pathname, unsigned int flags,# define STATX_ATTR_AUTOMOUNT 0x00001000#endif +#ifndef STATX_ATTR_VERITY +# define STATX_ATTR_VERITY 0x00100000 +#endif +#ifndef AT_SYMLINK_NOFOLLOW # define AT_SYMLINK_NOFOLLOW 0x100#endif
m4/ltp-fsverity.m4 new file +22 -0
@@ -0,0 +1,22 @@ +dnl SPDX-License-Identifier: GPL-2.0-or-later +dnl Copyright (c) 2022 Fujitsu Ltd. +dnl Author: Dai Shili <[email protected]> + +AC_DEFUN([LTP_CHECK_FSVERITY],[ + AC_CHECK_HEADERS([linux/fsverity.h], [have_fsverity=yes] ,[AC_MSG_WARN(missing linux/fsverity.h header)]) + if test "x$have_fsverity" = "xyes"; then + AC_COMPILE_IFELSE([AC_LANG_SOURCE([ +#include <linux/fsverity.h> +int main(void) { + struct fsverity_enable_arg tst_fsverity_enable_arg; + return 0; +}])], [has_fsverity_enable_arg="yes"]) + fi + +if test "x$has_fsverity_enable_arg" = "xyes"; then + AC_DEFINE(HAVE_STRUCT_FSVERITY_ENABLE_ARG, 1, [Define to 1 if you have struct fsverity_enable_arg]) + AC_MSG_RESULT(yes) +else + AC_MSG_RESULT(no) +fi +])
runtest/syscalls +1 -0
@@ -1744,6 +1744,7 @@ statx05 statx05 statx06 statx06 statx07 statx07 statx08 statx08 +statx09 statx09 membarrier01 membarrier01
testcases/kernel/syscalls/statx/.gitignore +1 -0
@@ -6,3 +6,4 @@ /statx06 /statx07 /statx08 +/statx09
testcases/kernel/syscalls/statx/statx09.c new file +200 -0
200 lines not on this page · raw message
Signature · 5 lines
1.8.3.1 -- Mailing list info: https://lists.linux.it/listinfo/ltp
Hi!
Quoted 74 lines
Signed-off-by Dai Shili <[email protected]>--- configure.ac | 1 + include/lapi/fs.h | 4 + include/lapi/fsverity.h | 38 ++++++ include/lapi/stat.h | 4 + m4/ltp-fsverity.m4 | 22 ++++ runtest/syscalls | 1 + testcases/kernel/syscalls/statx/.gitignore | 1 + testcases/kernel/syscalls/statx/statx09.c | 200 +++++++++++++++++++++++++++++ 8 files changed, 271 insertions(+) create mode 100644 include/lapi/fsverity.h create mode 100644 m4/ltp-fsverity.m4 create mode 100644 testcases/kernel/syscalls/statx/statx09.cconfigure.ac +1
-0@@ -367,6 +367,7 @@ LTP_CHECK_SELINUX LTP_CHECK_SYNC_ADD_AND_FETCH LTP_CHECK_SYSCALL_EVENTFD LTP_CHECK_SYSCALL_FCNTL +LTP_CHECK_FSVERITY if test "x$with_numa" = xyes; then LTP_CHECK_SYSCALL_NUMAinclude/lapi/fs.h +4
-0@@ -41,6 +41,10 @@#define FS_NODUMP_FL 0x00000040/* do not dump file */ #endif +#ifndef FS_VERITY_FL +#define FS_VERITY_FL 0x00100000/* Verity protected inode */ +#endif +/* * Helper function to get MAX_LFS_FILESIZE. * Missing PAGE_SHIFT on some libc prevents defining MAX_LFS_FILESIZE. include/lapi/fsverity.h new file +26
-0@@ -0,0 +1,38 @@ +// SPDX-License-Identifier: GPL-2.0-or-later +/* +* Copyright (c) 2022 FUJITSU LIMITED. All rights reserved. +* Author: Dai Shili <[email protected]> +*/ +#ifndef LAPI_FSVERITY_H__ +#define LAPI_FSVERITY_H__ + +#include "config.h" +#include <linux/types.h> + +#ifdef HAVE_LINUX_FSVERITY_H +#include <linux/fsverity.h> +#endif + +#ifndef FS_VERITY_HASH_ALG_SHA256 +# define FS_VERITY_HASH_ALG_SHA256 1 +#endif + +#ifndef FS_IOC_ENABLE_VERITY +# define FS_IOC_ENABLE_VERITY _IOW('f', 133, struct fsverity_enable_arg) +#endif + +#ifndef HAVE_STRUCT_FSVERITY_ENABLE_ARG +struct fsverity_enable_arg { + __u32 version;
include/lapi/fsverity.h line 36
Quoted 10 lines
include/lapi/fsverity.h new file +10
-0+__u32 hash_algorithm; +__u32 block_size; +__u32 salt_size; +__u64 salt_ptr; +__u32 sig_size; +__u32 __reserved1; +__u64 sig_ptr; + __u64 __reserved2[11]; +}; +#endif
Shouldn't this structure fallback be defined before the FS_IOC_ENABLE_VERITY?
Quoted 33 lines
include/lapi/fsverity.h new file +1
-0+#endif include/lapi/stat.h +4
-0@@ -223,6 +223,10 @@ static inline int statx(int dirfd, const char *pathname, unsigned int flags,# define STATX_ATTR_AUTOMOUNT 0x00001000#endif +#ifndef STATX_ATTR_VERITY +# define STATX_ATTR_VERITY 0x00100000 +#endif +#ifndef AT_SYMLINK_NOFOLLOW # define AT_SYMLINK_NOFOLLOW 0x100#endif m4/ltp-fsverity.m4 new file +11
-0@@ -0,0 +1,22 @@ +dnl SPDX-License-Identifier: GPL-2.0-or-later +dnl Copyright (c) 2022 Fujitsu Ltd. +dnl Author: Dai Shili <[email protected]> + +AC_DEFUN([LTP_CHECK_FSVERITY],[ + AC_CHECK_HEADERS([linux/fsverity.h], [have_fsverity=yes] ,[AC_MSG_WARN(missing linux/fsverity.h header)]) + if test "x$have_fsverity" = "xyes"; then + AC_COMPILE_IFELSE([AC_LANG_SOURCE([ +#include <linux/fsverity.h> +int main(void) { + struct fsverity_enable_arg tst_fsverity_enable_arg;
m4/ltp-fsverity.m4 line 21
Quoted 10 lines
m4/ltp-fsverity.m4 new file +10
-0+ return 0; +}])], [has_fsverity_enable_arg="yes"]) + fi + +if test "x$has_fsverity_enable_arg" = "xyes"; then + AC_DEFINE(HAVE_STRUCT_FSVERITY_ENABLE_ARG, 1, [Define to 1 if you have struct fsverity_enable_arg]) + AC_MSG_RESULT(yes) +else + AC_MSG_RESULT(no) +fi
This whole AC_COMPILE_IFELSE() should probably be just:
AC_CHECK_TYPES(struct fsverity_enable_arg,,,[#include <linux/fsverity.h>])
Quoted 75 lines
m4/ltp-fsverity.m4 new file +1
-0+])runtest/syscalls +1
-0@@ -1744,6 +1744,7 @@ statx05 statx05 statx06 statx06 statx07 statx07 statx08 statx08 +statx09 statx09 membarrier01 membarrier01testcases/kernel/syscalls/statx/.gitignore +1
-0@@ -6,3 +6,4 @@ /statx06 /statx07 /statx08 +/statx09testcases/kernel/syscalls/statx/statx09.c new file +47
-0@@ -0,0 +1,200 @@ +// SPDX-License-Identifier: GPL-2.0-or-later +/* +* Copyright (c) 2022 FUJITSU LIMITED. All rights reserved. +* Author: Dai Shili <[email protected]> +*/ + +/*\ +* [Description] +* +* This code tests if the attributes field of statx received expected value. +* File set with following flags by using SAFE_IOCTL: +* +* - STATX_ATTR_VERITY: statx() system call sets STATX_ATTR_VERITY if the file +* has fs-verity enabled. This can perform better than FS_IOC_GETFLAGS and +* FS_IOC_MEASURE_VERITY because it doesn't require opening the file, +* and opening verity files can be expensive. +* +* Minimum Linux version required is v5.5. +* fs-verity is currently supported by the ext4 and f2fs filesystems. +* The CONFIG_FS_VERITY kconfig option must be enabled to use fs-verity +* on either filesystem. +* ext4 supports fs-verity since Linux v5.4 and e2fsprogs v1.45.2. +*/ + +#define _GNU_SOURCE +#include <sys/mount.h> +#include <stdlib.h> +#include <linux/ioctl.h> +#include "tst_test.h" +#include "lapi/fs.h" +#include "lapi/fsverity.h" +#include "lapi/stat.h" +#include <inttypes.h> + +#define MNTPOINT "mnt_point" +#define TESTFILE_FLAGGED MNTPOINT"/test_file1" +#define TESTFILE_UNFLAGGED MNTPOINT"/test_file2" + +static int fd_flagged, fd_unflagged, clear_flags; +static int mount_flag; +static char wrbuf[5 ]; + +static const uint32_t hash_algorithms[] = { +FS_VERITY_HASH_ALG_SHA256 , +}; + +static void test_flagged (void )
testcases/kernel/syscalls/statx/statx09.c line 57
Quoted 10 lines
testcases/kernel/syscalls/statx/statx09.c new file +10
-0+{ +struct statx buf; + +TEST (statx (AT_FDCWD ,TESTFILE_FLAGGED ,0 ,0 , &buf)); +if (TST_RET ==0 ) +tst_res (TPASS , +"sys_statx(AT_FDCWD, %s, 0, 0, &buf)" ,TESTFILE_FLAGGED ); +else +tst_brk (TFAIL |TTERRNO , +"sys_statx(AT_FDCWD, %s, 0, 0, &buf)" ,TESTFILE_FLAGGED );
Just use TST_EXP_PASS().
Quoted 9 lines
testcases/kernel/syscalls/statx/statx09.c new file +9
-0+if (buf.stx_attributes &STATX_ATTR_VERITY ) +tst_res (TPASS ,"STATX_ATTR_VERITY flag is set: (%" PRIu64") " , buf.stx_attributes); +else +tst_res (TFAIL ,"STATX_ATTR_VERITY flag is not set" ); +} + +static void test_unflagged (void ) +{ +struct statx buf;
testcases/kernel/syscalls/statx/statx09.c line 77
Quoted 10 lines
testcases/kernel/syscalls/statx/statx09.c new file +10
-0+ +TEST (statx (AT_FDCWD ,TESTFILE_UNFLAGGED ,0 ,0 , &buf)); +if (TST_RET ==0 ) +tst_res (TPASS , +"sys_statx(AT_FDCWD, %s, 0, 0, &buf)" , +TESTFILE_UNFLAGGED ); +else +tst_brk (TFAIL |TTERRNO , +"sys_statx(AT_FDCWD, %s, 0, 0, &buf)" , +TESTFILE_UNFLAGGED );
Here as well.
Quoted 15 lines
testcases/kernel/syscalls/statx/statx09.c new file +15
-0+if ((buf.stx_attributes &STATX_ATTR_VERITY ) ==0 ) +tst_res (TPASS ,"STATX_ATTR_VERITY flag is not set" ); +else +tst_res (TFAIL ,"STATX_ATTR_VERITY flag is set" ); +} + +static struct test_cases { +void (*tfunc)(void ); +} tcases[] = { + {&test_flagged}, + {&test_unflagged}, +}; + +static void run (unsigned int i) +{
testcases/kernel/syscalls/statx/statx09.c line 103
Quoted 10 lines
testcases/kernel/syscalls/statx/statx09.c new file +10
-0+ tcases[i].tfunc (); +} + +static void flag_setup (void ) +{ +int attr, ret; +struct fsverity_enable_arg enable; + + fd_flagged =SAFE_OPEN (TESTFILE_FLAGGED ,O_RDONLY ,0664 ); + fd_unflagged =SAFE_OPEN (TESTFILE_UNFLAGGED ,O_RDWR |O_CREAT ,0664 );
What is this file descriptor even used for?
I guess that we can create this file in the test setup as well and there is no point in doing anything with the unflagged file here.
Quoted 28 lines
testcases/kernel/syscalls/statx/statx09.c new file +28
-0+ ret =ioctl (fd_flagged,FS_IOC_GETFLAGS , &attr); +if (ret <0 ) { +if (errno ==ENOTTY ) +tst_brk (TCONF |TERRNO ,"FS_IOC_GETFLAGS not supported" ); + +tst_brk (TBROK |TERRNO ,"ioctl(%i, FS_IOC_GETFLAGS, ...)" , fd_flagged); + } + +memset (&enable,0 ,sizeof (enable)); + enable.version =1 ; + enable.hash_algorithm = hash_algorithms[0 ]; + enable.block_size =4096 ; + enable.salt_size =0 ; + enable.salt_ptr = (intptr_t )NULL ; + enable.sig_size =0 ; + enable.sig_ptr = (intptr_t )NULL ; + + ret =ioctl (fd_flagged,FS_IOC_ENABLE_VERITY , &enable); +if (ret <0 ) { +if (errno ==EOPNOTSUPP ) { +tst_brk (TCONF , +"fs-verity is not supported on the file system or by the kernel" ); + } +tst_brk (TBROK |TERRNO ,"ioctl(%i, FS_IOC_ENABLE_VERITY) failed" , fd_flagged); + } + + ret =ioctl (fd_flagged,FS_IOC_GETFLAGS , &attr); +if ((ret ==0 ) && !(attr &FS_VERITY_FL ))
testcases/kernel/syscalls/statx/statx09.c line 142
Quoted 10 lines
testcases/kernel/syscalls/statx/statx09.c new file +10
-0+tst_res (TFAIL ,"%i: fs-verity enabled but FS_VERITY_FL bit not set" , fd_flagged); + + clear_flags =1 ; +} + +static void setup (void ) +{ +const char *fs_opts[] = {"-O verity" ,NULL }; + +SAFE_MKFS (tst_device->dev, tst_device->fs_type, fs_opts,NULL );
Why can't we use the .format_device in tst_test structure along with dev_fs_opts?
testcases/kernel/syscalls/statx/statx09.c line 148
Quoted 6 lines
testcases/kernel/syscalls/statx/statx09.c new file +6
-0+TEST (mount (tst_device->dev,MNTPOINT , tst_device->fs_type,0 ,NULL )); +if (TST_RET ) { +if (TST_RET ==-1 ) { +tst_res (TFAIL |TERRNO ,"mount(%s, %s, %s) failed. " +"Loop device does not support fs-verity, pls export LTP_DEV." , + tst_device->dev,MNTPOINT , tst_device->fs_type);
You should really check the TST_ERR here as well. I guess that you get EINVAL in case that kernel does not support fs-verity?
if (TST_RET) {
if (TST_ERR == EINVAL)
tst_brk(TCONF, "fs-verity not supported on loopdev");
tst_brk(TBROK | TERRNO "mount() failed with %ld", TST_RET);
}Also this code actually uses tst_brk() which exits the test if the mount failed.
testcases/kernel/syscalls/statx/statx09.c line 159
Quoted 11 lines
testcases/kernel/syscalls/statx/statx09.c new file +11
-0+ }else { +tst_res (TFAIL |TERRNO ,"Invalid mount(%s, %s, %s) return value %ld" , + tst_device->dev,MNTPOINT , tst_device->fs_type,TST_RET ); + } + } + mount_flag =1 ; + + fd_flagged =SAFE_OPEN (TESTFILE_FLAGGED ,O_RDWR |O_CREAT ,0664 ); +memset (wrbuf,'a' ,5 ); +SAFE_WRITE (1 , fd_flagged, wrbuf,5 ); +SAFE_CLOSE (fd_flagged);
Just use SAFE_FILE_PRINTF() instead.
testcases/kernel/syscalls/statx/statx09.c line 172
Quoted 12 lines
testcases/kernel/syscalls/statx/statx09.c new file +12
-0+flag_setup (); +} + +static void cleanup (void ) +{ +int attr; + +if (clear_flags) { +SAFE_IOCTL (fd_flagged,FS_IOC_GETFLAGS , &attr); + attr &= ~FS_VERITY_FL ; +SAFE_IOCTL (fd_flagged,FS_IOC_SETFLAGS , &attr); + }
Is there a reason to clear the flags here? Does that prevent the MNTPOINT from being unmounted? If not we can remove this piece of code and also close fd_flagged at the end of the flag_setup() function.
Quoted 33 lines
testcases/kernel/syscalls/statx/statx09.c new file +27
-0+if (fd_flagged >0 ) +SAFE_CLOSE (fd_flagged); +if (fd_unflagged >0 ) +SAFE_CLOSE (fd_unflagged); + +if (mount_flag) +tst_umount (MNTPOINT ); +} + +static struct tst_test test = { + .test = run, + .tcnt =ARRAY_SIZE (tcases), + .setup = setup, + .cleanup = cleanup, + .needs_root =1 , + .mntpoint =MNTPOINT , + .needs_device =1 , + .dev_fs_type ="ext4" , + .needs_kconfigs = (const char *[]) { +"CONFIG_FS_VERITY" , +NULL + }, + .needs_cmds = (const char *[]) { +"mkfs.ext4 >= 1.45.2" , +NULL + } +};Signature · 5 lines
1.8.3.1 -- Mailing list info: https://lists.linux.it/listinfo/ltp
Signature · 5 lines
Cyril Hrubis [email protected] -- Mailing list info: https://lists.linux.it/listinfo/ltp
Quoted 79 lines · Cyril Hrubis
Hi!
Quoted 78 lines
Signed-off-by Dai Shili <[email protected]>--- configure.ac | 1 + include/lapi/fs.h | 4 + include/lapi/fsverity.h | 38 ++++++ include/lapi/stat.h | 4 + m4/ltp-fsverity.m4 | 22 ++++ runtest/syscalls | 1 + testcases/kernel/syscalls/statx/.gitignore | 1 + testcases/kernel/syscalls/statx/statx09.c | 200 +++++++++++++++++++++++++++++ 8 files changed, 271 insertions(+)create mode 100644
include/lapi/fsverity.h
create mode 100644 m4/ltp-fsverity.m4
create mode 100644testcases/kernel/syscalls/statx/statx09.cconfigure.ac +1
-0@@ -367,6 +367,7 @@ LTP_CHECK_SELINUX LTP_CHECK_SYNC_ADD_AND_FETCH LTP_CHECK_SYSCALL_EVENTFD LTP_CHECK_SYSCALL_FCNTL +LTP_CHECK_FSVERITY if test "x$with_numa" = xyes; then LTP_CHECK_SYSCALL_NUMAinclude/lapi/fs.h +4
-0@@ -41,6 +41,10 @@#define FS_NODUMP_FL 0x00000040/* do not dump file */ #endif +#ifndef FS_VERITY_FL +#define FS_VERITY_FL 0x00100000/* Verity protected inode */ +#endif +/* * Helper function to get MAX_LFS_FILESIZE. * Missing PAGE_SHIFT on some libc prevents defining MAX_LFS_FILESIZE. include/lapi/fsverity.h new file +30
-0@@ -0,0 +1,38 @@ +// SPDX-License-Identifier: GPL-2.0-or-later +/* +* Copyright (c) 2022 FUJITSU LIMITED. All rights reserved. +* Author: Dai Shili <[email protected]> +*/ +#ifndef LAPI_FSVERITY_H__ +#define LAPI_FSVERITY_H__ + +#include "config.h" +#include <linux/types.h> + +#ifdef HAVE_LINUX_FSVERITY_H +#include <linux/fsverity.h> +#endif + +#ifndef FS_VERITY_HASH_ALG_SHA256 +# define FS_VERITY_HASH_ALG_SHA256 1 +#endif + +#ifndef FS_IOC_ENABLE_VERITY +# define FS_IOC_ENABLE_VERITY _IOW('f', 133, struct fsverity_enable_arg) +#endif + +#ifndef HAVE_STRUCT_FSVERITY_ENABLE_ARG +struct fsverity_enable_arg { + __u32 version; + __u32 hash_algorithm; + __u32 block_size; + __u32 salt_size; + __u64 salt_ptr;
Quoted 8 lines
include/lapi/fsverity.h line 36
Quoted 6 lines
include/lapi/fsverity.h new file +6
-0+__u32 sig_size; +__u32 __reserved1; +__u64 sig_ptr; + __u64 __reserved2[11]; +}; +#endif Shouldn't this structure fallback be defined before the
FS_IOC_ENABLE_VERITY?
Yes.
Quoted 45 lines
Quoted 33 lines
include/lapi/fsverity.h new file +1
-0+#endif include/lapi/stat.h +4
-0@@ -223,6 +223,10 @@ static inline int statx(int dirfd, const char *pathname, unsigned int flags,# define STATX_ATTR_AUTOMOUNT 0x00001000#endif +#ifndef STATX_ATTR_VERITY +# define STATX_ATTR_VERITY 0x00100000 +#endif +#ifndef AT_SYMLINK_NOFOLLOW # define AT_SYMLINK_NOFOLLOW 0x100#endif m4/ltp-fsverity.m4 new file +11
-0@@ -0,0 +1,22 @@ +dnl SPDX-License-Identifier: GPL-2.0-or-later +dnl Copyright (c) 2022 Fujitsu Ltd. +dnl Author: Dai Shili <[email protected]> + +AC_DEFUN([LTP_CHECK_FSVERITY],[ + AC_CHECK_HEADERS([linux/fsverity.h], [have_fsverity=yes] ,[AC_MSG_WARN(missing linux/fsverity.h header)]) + if test "x$have_fsverity" = "xyes"; then + AC_COMPILE_IFELSE([AC_LANG_SOURCE([ +#include <linux/fsverity.h> +int main(void) { + struct fsverity_enable_arg tst_fsverity_enable_arg;m4/ltp-fsverity.m4 line 21
Quoted 10 lines
m4/ltp-fsverity.m4 new file +10
-0+ return 0; +}])], [has_fsverity_enable_arg="yes"]) + fi + +if test "x$has_fsverity_enable_arg" = "xyes"; then + AC_DEFINE(HAVE_STRUCT_FSVERITY_ENABLE_ARG, 1, [Define to 1 if you have struct fsverity_enable_arg]) + AC_MSG_RESULT(yes) +else + AC_MSG_RESULT(no) +fiThis whole
AC_COMPILE_IFELSE()should probably be just:
Quoted 1 line
AC_CHECK_TYPES(struct fsverity_enable_arg,,,[#include <linux/fsverity.h>])
OK.
Quoted 78 lines
Quoted 78 lines
m4/ltp-fsverity.m4 new file +1
-0+])runtest/syscalls +1
-0@@ -1744,6 +1744,7 @@ statx05 statx05 statx06 statx06 statx07 statx07 statx08 statx08 +statx09 statx09 membarrier01 membarrier01testcases/kernel/syscalls/statx/.gitignore +1
-0@@ -6,3 +6,4 @@ /statx06 /statx07 /statx08 +/statx09testcases/kernel/syscalls/statx/statx09.c new file +50
-0@@ -0,0 +1,200 @@ +// SPDX-License-Identifier: GPL-2.0-or-later +/* +* Copyright (c) 2022 FUJITSU LIMITED. All rights reserved. +* Author: Dai Shili <[email protected]> +*/ + +/*\ +* [Description] +* +* This code tests if the attributes field of statx received expected value. +* File set with following flags by using SAFE_IOCTL: +* +* - STATX_ATTR_VERITY: statx() system call sets STATX_ATTR_VERITY if the file +* has fs-verity enabled. This can perform better than FS_IOC_GETFLAGS and +* FS_IOC_MEASURE_VERITY because it doesn't require opening the file, +* and opening verity files can be expensive. +* +* Minimum Linux version required is v5.5. +* fs-verity is currently supported by the ext4 and f2fs filesystems. +* The CONFIG_FS_VERITY kconfig option must be enabled to use fs-verity +* on either filesystem. +* ext4 supports fs-verity since Linux v5.4 and e2fsprogs v1.45.2. +*/ + +#define _GNU_SOURCE +#include <sys/mount.h> +#include <stdlib.h> +#include <linux/ioctl.h> +#include "tst_test.h" +#include "lapi/fs.h" +#include "lapi/fsverity.h" +#include "lapi/stat.h" +#include <inttypes.h> + +#define MNTPOINT "mnt_point" +#define TESTFILE_FLAGGED MNTPOINT"/test_file1" +#define TESTFILE_UNFLAGGED MNTPOINT"/test_file2" + +static int fd_flagged, fd_unflagged, clear_flags; +static int mount_flag; +static char wrbuf[5 ]; + +static const uint32_t hash_algorithms[] = { +FS_VERITY_HASH_ALG_SHA256 , +}; + +static void test_flagged (void ) +{ +struct statx buf; +
Quoted 8 lines
testcases/kernel/syscalls/statx/statx09.c line 57
Quoted 7 lines
testcases/kernel/syscalls/statx/statx09.c new file +7
-0+TEST (statx (AT_FDCWD ,TESTFILE_FLAGGED ,0 ,0 , &buf)); +if (TST_RET ==0 ) +tst_res (TPASS , +"sys_statx(AT_FDCWD, %s, 0, 0, &buf)" ,TESTFILE_FLAGGED ); +else +tst_brk (TFAIL |TTERRNO , +"sys_statx(AT_FDCWD, %s, 0, 0, &buf)" ,TESTFILE_FLAGGED );Just use
TST_EXP_PASS().
OK. I will replace it.
Quoted 12 lines
Quoted 12 lines
testcases/kernel/syscalls/statx/statx09.c new file +12
-0+if (buf.stx_attributes &STATX_ATTR_VERITY ) +tst_res (TPASS ,"STATX_ATTR_VERITY flag is set: (%" PRIu64") " , buf.stx_attributes); +else +tst_res (TFAIL ,"STATX_ATTR_VERITY flag is not set" ); +} + +static void test_unflagged (void ) +{ +struct statx buf; + +TEST (statx (AT_FDCWD ,TESTFILE_UNFLAGGED ,0 ,0 , &buf)); +if (TST_RET ==0 )
Quoted 8 lines
testcases/kernel/syscalls/statx/statx09.c line 77
Quoted 7 lines
testcases/kernel/syscalls/statx/statx09.c new file +7
-0+tst_res (TPASS , +"sys_statx(AT_FDCWD, %s, 0, 0, &buf)" , +TESTFILE_UNFLAGGED ); + else + tst_brk(TFAIL | TTERRNO, +"sys_statx(AT_FDCWD, %s, 0, 0, &buf)" , + TESTFILE_UNFLAGGED);Here as well.
OK. I will replace it.
Quoted 27 lines
Quoted 15 lines
testcases/kernel/syscalls/statx/statx09.c new file +15
-0+if ((buf.stx_attributes &STATX_ATTR_VERITY ) ==0 ) +tst_res (TPASS ,"STATX_ATTR_VERITY flag is not set" ); +else +tst_res (TFAIL ,"STATX_ATTR_VERITY flag is set" ); +} + +static struct test_cases { +void (*tfunc)(void ); +} tcases[] = { + {&test_flagged}, + {&test_unflagged}, +}; + +static void run (unsigned int i) +{testcases/kernel/syscalls/statx/statx09.c line 103
Quoted 10 lines
testcases/kernel/syscalls/statx/statx09.c new file +10
-0+ tcases[i].tfunc (); +} + +static void flag_setup (void ) +{ +int attr, ret; +struct fsverity_enable_arg enable; + + fd_flagged =SAFE_OPEN (TESTFILE_FLAGGED ,O_RDONLY ,0664 ); + fd_unflagged =SAFE_OPEN (TESTFILE_UNFLAGGED ,O_RDWR |O_CREAT ,0664 );What is this file descriptor even used for?
Quoted 2 lines
I guess that we can create this file in the test setup as well and there is no point in doing anything with the unflagged file here.
Agree. Move it to setup is better.
Quoted 32 lines
Quoted 32 lines
testcases/kernel/syscalls/statx/statx09.c new file +32
-0+ ret =ioctl (fd_flagged,FS_IOC_GETFLAGS , &attr); +if (ret <0 ) { +if (errno ==ENOTTY ) +tst_brk (TCONF |TERRNO ,"FS_IOC_GETFLAGS not supported" ); + +tst_brk (TBROK |TERRNO ,"ioctl(%i, FS_IOC_GETFLAGS, ...)" , fd_flagged); + } + +memset (&enable,0 ,sizeof (enable)); + enable.version =1 ; + enable.hash_algorithm = hash_algorithms[0 ]; + enable.block_size =4096 ; + enable.salt_size =0 ; + enable.salt_ptr = (intptr_t )NULL ; + enable.sig_size =0 ; + enable.sig_ptr = (intptr_t )NULL ; + + ret =ioctl (fd_flagged,FS_IOC_ENABLE_VERITY , &enable); +if (ret <0 ) { +if (errno ==EOPNOTSUPP ) { +tst_brk (TCONF , +"fs-verity is not supported on the file system or by the kernel" ); + } +tst_brk (TBROK |TERRNO ,"ioctl(%i, FS_IOC_ENABLE_VERITY) failed" , fd_flagged); + } + + ret =ioctl (fd_flagged,FS_IOC_GETFLAGS , &attr); +if ((ret ==0 ) && !(attr &FS_VERITY_FL )) +tst_res (TFAIL ,"%i: fs-verity enabled but FS_VERITY_FL bit not set" , fd_flagged); + + clear_flags =1 ; +}
Quoted 8 lines
testcases/kernel/syscalls/statx/statx09.c line 142
Quoted 6 lines
testcases/kernel/syscalls/statx/statx09.c new file +6
-0+ +static void setup (void ) +{ +const char *fs_opts[] = {"-O verity" ,NULL }; + +SAFE_MKFS (tst_device->dev, tst_device->fs_type, fs_opts,NULL );Why can't we use the .format_device in
tst_teststructure along withdev_fs_opts?
OK.
Quoted 8 lines
testcases/kernel/syscalls/statx/statx09.c line 148
Quoted 6 lines
testcases/kernel/syscalls/statx/statx09.c new file +6
-0+TEST (mount (tst_device->dev,MNTPOINT , tst_device->fs_type,0 ,NULL )); +if (TST_RET ) { +if (TST_RET ==-1 ) { +tst_res (TFAIL |TERRNO ,"mount(%s, %s, %s) failed. " +"Loop device does not support fs-verity, pls export LTP_DEV." , + tst_device->dev,MNTPOINT , tst_device->fs_type);You should really check the
TST_ERRhere as well. I guess that you get EINVAL in case that kernel does not support fs-verity?
OK. I will check TST_ERR.
I get EINVAL because the loopdev does not support fs-verity.
Kernel support was checked in struct tst_test.
Quoted 9 lines
if (TST_RET) { if (TST_ERR == EINVAL) tst_brk(TCONF, "fs-verity not supported on loopdev"); tst_brk(TBROK | TERRNO "mount() failed with %ld", TST_RET); }Also this code actually uses
tst_brk()which exits the test if the mount failed.
OK.
Quoted 4 lines
Quoted 4 lines
testcases/kernel/syscalls/statx/statx09.c new file +4
-0+ }else { +tst_res (TFAIL |TERRNO ,"Invalid mount(%s, %s, %s) return value %ld" , + tst_device->dev,MNTPOINT , tst_device->fs_type,TST_RET ); + }
Quoted 8 lines
testcases/kernel/syscalls/statx/statx09.c line 159
Quoted 7 lines
testcases/kernel/syscalls/statx/statx09.c new file +7
-0+ } + mount_flag =1 ; + + fd_flagged =SAFE_OPEN (TESTFILE_FLAGGED ,O_RDWR |O_CREAT ,0664 ); +memset (wrbuf,'a' ,5 ); +SAFE_WRITE (1 , fd_flagged, wrbuf,5 ); +SAFE_CLOSE (fd_flagged);Just use
SAFE_FILE_PRINTF()instead.
OK.
Quoted 7 lines
Quoted 7 lines
testcases/kernel/syscalls/statx/statx09.c new file +7
-0+flag_setup (); +} + +static void cleanup (void ) +{ +int attr; +
Quoted 8 lines
testcases/kernel/syscalls/statx/statx09.c line 172
Quoted 5 lines
testcases/kernel/syscalls/statx/statx09.c new file +5
-0+if (clear_flags) { +SAFE_IOCTL (fd_flagged,FS_IOC_GETFLAGS , &attr); + attr &= ~FS_VERITY_FL ; +SAFE_IOCTL (fd_flagged,FS_IOC_SETFLAGS , &attr); + }Is there a reason to clear the flags here? Does that prevent the MNTPOINT from being unmounted? If not we can remove this piece of code and also close
fd_flaggedat the end of theflag_setup()function.
There is no point to clear the flags here.
I will remove this piece of code and close fd_flagged at the end of the flag_setup() function.
Quoted 33 lines
Quoted 33 lines
testcases/kernel/syscalls/statx/statx09.c new file +27
-0+if (fd_flagged >0 ) +SAFE_CLOSE (fd_flagged); +if (fd_unflagged >0 ) +SAFE_CLOSE (fd_unflagged); + +if (mount_flag) +tst_umount (MNTPOINT ); +} + +static struct tst_test test = { + .test = run, + .tcnt =ARRAY_SIZE (tcases), + .setup = setup, + .cleanup = cleanup, + .needs_root =1 , + .mntpoint =MNTPOINT , + .needs_device =1 , + .dev_fs_type ="ext4" , + .needs_kconfigs = (const char *[]) { +"CONFIG_FS_VERITY" , +NULL + }, + .needs_cmds = (const char *[]) { +"mkfs.ext4 >= 1.45.2" , +NULL + } +};Signature · 5 lines
1.8.3.1 -- Mailing list info: https://lists.linux.it/listinfo/ltp
Signature · 1 line
Mailing list info: https://lists.linux.it/listinfo/ltp
PATCH v2 1/1 syscalls/statx09: Add new test
In reply to Cyril HrubisThis test is basically the same as statx04 but here we check for the STATX_ATTR_VERITY flag which is currently only implemented on ext4.
--- configure.ac | 1 + include/lapi/fs.h | 4 + include/lapi/fsverity.h | 38 +++++++ include/lapi/stat.h | 4 + m4/ltp-fsverity.m4 | 10 ++ runtest/syscalls | 1 + testcases/kernel/syscalls/statx/.gitignore | 1 + testcases/kernel/syscalls/statx/statx09.c | 172 +++++++++++++++++++++++++++++ 8 files changed, 231 insertions(+) create mode 100644 include/lapi/fsverity.h create mode 100644 m4/ltp-fsverity.m4 create mode 100644 testcases/kernel/syscalls/statx/statx09.c
configure.ac +1 -0
@@ -367,6 +367,7 @@ LTP_CHECK_SELINUX LTP_CHECK_SYNC_ADD_AND_FETCH LTP_CHECK_SYSCALL_EVENTFD LTP_CHECK_SYSCALL_FCNTL +LTP_CHECK_FSVERITY if test "x$with_numa" = xyes; then LTP_CHECK_SYSCALL_NUMA
include/lapi/fs.h +4 -0
@@ -41,6 +41,10 @@#define FS_NODUMP_FL 0x00000040/* do not dump file */ #endif +#ifndef FS_VERITY_FL +#define FS_VERITY_FL 0x00100000/* Verity protected inode */ +#endif +/* * Helper function to get MAX_LFS_FILESIZE. * Missing PAGE_SHIFT on some libc prevents defining MAX_LFS_FILESIZE.
include/lapi/fsverity.h new file +38 -0
@@ -0,0 +1,38 @@ +// SPDX-License-Identifier: GPL-2.0-or-later +/* +* Copyright (c) 2022 FUJITSU LIMITED. All rights reserved. +* Author: Dai Shili <[email protected]> +*/ +#ifndef LAPI_FSVERITY_H__ +#define LAPI_FSVERITY_H__ + +#include "config.h" +#include <linux/types.h> + +#ifdef HAVE_LINUX_FSVERITY_H +#include <linux/fsverity.h> +#endif + +#ifndef FS_VERITY_HASH_ALG_SHA256 +# define FS_VERITY_HASH_ALG_SHA256 1 +#endif + +#ifndef HAVE_STRUCT_FSVERITY_ENABLE_ARG +struct fsverity_enable_arg { +__u32 version; +__u32 hash_algorithm; +__u32 block_size; +__u32 salt_size; +__u64 salt_ptr; +__u32 sig_size; +__u32 __reserved1; +__u64 sig_ptr; +__u64 __reserved2[11 ]; +}; +#endif + +#ifndef FS_IOC_ENABLE_VERITY +# define FS_IOC_ENABLE_VERITY _IOW('f', 133, struct fsverity_enable_arg) +#endif + +#endif
include/lapi/stat.h +4 -0
@@ -223,6 +223,10 @@ static inline int statx(int dirfd, const char *pathname, unsigned int flags,# define STATX_ATTR_AUTOMOUNT 0x00001000#endif +#ifndef STATX_ATTR_VERITY +# define STATX_ATTR_VERITY 0x00100000 +#endif +#ifndef AT_SYMLINK_NOFOLLOW # define AT_SYMLINK_NOFOLLOW 0x100#endif
m4/ltp-fsverity.m4 new file +10 -0
@@ -0,0 +1,10 @@ +dnl SPDX-License-Identifier: GPL-2.0-or-later +dnl Copyright (c) 2022 Fujitsu Ltd. +dnl Author: Dai Shili <[email protected]> + +AC_DEFUN([LTP_CHECK_FSVERITY],[ + AC_CHECK_HEADERS([linux/fsverity.h], [have_fsverity=yes], [AC_MSG_WARN(missing linux/fsverity.h header)]) + if test "x$have_fsverity" = "xyes"; then + AC_CHECK_TYPES(struct fsverity_enable_arg,,,[#include <linux/fsverity.h>]) + fi +])
runtest/syscalls +1 -0
@@ -1744,6 +1744,7 @@ statx05 statx05 statx06 statx06 statx07 statx07 statx08 statx08 +statx09 statx09 membarrier01 membarrier01
testcases/kernel/syscalls/statx/.gitignore +1 -0
@@ -6,3 +6,4 @@ /statx06 /statx07 /statx08 +/statx09
testcases/kernel/syscalls/statx/statx09.c new file +172 -0
172 lines not on this page · raw message
Signature · 5 lines
1.8.3.1 -- Mailing list info: https://lists.linux.it/listinfo/ltp
Hi!
Quoted 27 lines
new file mode 100644
index 0000000..0125fa8include/lapi/fsverity.h new file +22
-0@@ -0,0 +1,38 @@ +// SPDX-License-Identifier: GPL-2.0-or-later +/* +* Copyright (c) 2022 FUJITSU LIMITED. All rights reserved. +* Author: Dai Shili <[email protected]> +*/ +#ifndef LAPI_FSVERITY_H__ +#define LAPI_FSVERITY_H__ + +#include "config.h" +#include <linux/types.h> + +#ifdef HAVE_LINUX_FSVERITY_H +#include <linux/fsverity.h> +#endif + +#ifndef FS_VERITY_HASH_ALG_SHA256 +# define FS_VERITY_HASH_ALG_SHA256 1 +#endif + +#ifndef HAVE_STRUCT_FSVERITY_ENABLE_ARG +struct fsverity_enable_arg { + __u32 version;
include/lapi/fsverity.h line 32
Quoted 10 lines
include/lapi/fsverity.h new file +10
-0+__u32 hash_algorithm; +__u32 block_size; +__u32 salt_size; +__u64 salt_ptr; +__u32 sig_size; +__u32 __reserved1; +__u64 sig_ptr; + __u64 __reserved2[11]; +}; +#endif
I haven't caught that in the previous review, however in userspace we are use the stdint types so this should:
* include stdint.h instead of linux/types.h
* replace __u32 with uint32_t
* replace __u64 with uint64_t
Quoted 75 lines
include/lapi/fsverity.h new file +5
-0+#ifndef FS_IOC_ENABLE_VERITY +# define FS_IOC_ENABLE_VERITY _IOW('f', 133, struct fsverity_enable_arg) +#endif + +#endif include/lapi/stat.h +4
-0@@ -223,6 +223,10 @@ static inline int statx(int dirfd, const char *pathname, unsigned int flags,# define STATX_ATTR_AUTOMOUNT 0x00001000#endif +#ifndef STATX_ATTR_VERITY +# define STATX_ATTR_VERITY 0x00100000 +#endif +#ifndef AT_SYMLINK_NOFOLLOW # define AT_SYMLINK_NOFOLLOW 0x100#endif m4/ltp-fsverity.m4 new file +10
-0@@ -0,0 +1,10 @@ +dnl SPDX-License-Identifier: GPL-2.0-or-later +dnl Copyright (c) 2022 Fujitsu Ltd. +dnl Author: Dai Shili <[email protected]> + +AC_DEFUN([LTP_CHECK_FSVERITY],[ + AC_CHECK_HEADERS([linux/fsverity.h], [have_fsverity=yes], [AC_MSG_WARN(missing linux/fsverity.h header)]) + if test "x$have_fsverity" = "xyes"; then + AC_CHECK_TYPES(struct fsverity_enable_arg,,,[#include <linux/fsverity.h>]) + fi +])runtest/syscalls +1
-0@@ -1744,6 +1744,7 @@ statx05 statx05 statx06 statx06 statx07 statx07 statx08 statx08 +statx09 statx09 membarrier01 membarrier01testcases/kernel/syscalls/statx/.gitignore +1
-0@@ -6,3 +6,4 @@ /statx06 /statx07 /statx08 +/statx09testcases/kernel/syscalls/statx/statx09.c new file +12
-0@@ -0,0 +1,172 @@ +// SPDX-License-Identifier: GPL-2.0-or-later +/* +* Copyright (c) 2022 FUJITSU LIMITED. All rights reserved. +* Author: Dai Shili <[email protected]> +*/ + +/*\ +* [Description] +* +* This code tests if the attributes field of statx received expected value. +* File set with following flags by using SAFE_IOCTL: +*
testcases/kernel/syscalls/statx/statx09.c line 22
Quoted 10 lines
testcases/kernel/syscalls/statx/statx09.c new file +10
-0+* - STATX_ATTR_VERITY: statx() system call sets STATX_ATTR_VERITY if the file +* has fs-verity enabled. This can perform better than FS_IOC_GETFLAGS and +* FS_IOC_MEASURE_VERITY because it doesn't require opening the file, +* and opening verity files can be expensive. +* +* Minimum Linux version required is v5.5. +* fs-verity is currently supported by the ext4 and f2fs filesystems. +* The CONFIG_FS_VERITY kconfig option must be enabled to use fs-verity +* on either filesystem. +* ext4 supports fs-verity since Linux v5.4 and e2fsprogs v1.45.2.
We have the CONFIG_FS_VERITY and e2fsprogs requirements in the tst_test structure so I wouldn't repeat them here.
Quoted 22 lines
testcases/kernel/syscalls/statx/statx09.c new file +22
-0+*/ + +#define _GNU_SOURCE +#include <sys/mount.h> +#include <stdlib.h> +#include <linux/ioctl.h> +#include "tst_test.h" +#include "lapi/fs.h" +#include "lapi/fsverity.h" +#include "lapi/stat.h" +#include <inttypes.h> + +#define MNTPOINT "mnt_point" +#define TESTFILE_FLAGGED MNTPOINT"/test_file3" +#define TESTFILE_UNFLAGGED MNTPOINT"/test_file4" + +static int fd_flagged, fd_unflagged; +static int mount_flag; + +static const uint32_t hash_algorithms[] = { +FS_VERITY_HASH_ALG_SHA256 , +};
testcases/kernel/syscalls/statx/statx09.c line 54
Quoted 10 lines
testcases/kernel/syscalls/statx/statx09.c new file +10
-0+ +static void test_flagged (void ) +{ +struct statx buf; + +TST_EXP_PASS (statx (AT_FDCWD ,TESTFILE_FLAGGED ,0 ,0 , &buf), +"statx(AT_FDCWD, %s, 0, 0, &buf)" ,TESTFILE_FLAGGED ); + +if (buf.stx_attributes &STATX_ATTR_VERITY ) +tst_res (TPASS ,"STATX_ATTR_VERITY flag is set: (%" PRIu64") " , buf.stx_attributes);
The stx_attributes is actually incompatible with PRIu64 so there should be a cast:
@@ -51,7 +50,7 @@ static void test_flagged(void)
"statx(AT_FDCWD, %s, 0, 0, &buf)", TESTFILE_FLAGGED);
if (buf.stx_attributes & STATX_ATTR_VERITY)
- tst_res(TPASS, "STATX_ATTR_VERITY flag is set: (%"PRIu64") ", buf.stx_attributes);
+ tst_res(TPASS, "STATX_ATTR_VERITY flag is set: (%"PRIu64") ", (uint64_t)buf.stx_attributes);
else
tst_res(TFAIL, "STATX_ATTR_VERITY flag is not set");}
Quoted 73 lines
testcases/kernel/syscalls/statx/statx09.c new file +73
-0+else +tst_res (TFAIL ,"STATX_ATTR_VERITY flag is not set" ); +} + +static void test_unflagged (void ) +{ +struct statx buf; + +TST_EXP_PASS (statx (AT_FDCWD ,TESTFILE_UNFLAGGED ,0 ,0 , &buf), +"statx(AT_FDCWD, %s, 0, 0, &buf)" ,TESTFILE_UNFLAGGED ); + +if ((buf.stx_attributes &STATX_ATTR_VERITY ) ==0 ) +tst_res (TPASS ,"STATX_ATTR_VERITY flag is not set" ); +else +tst_res (TFAIL ,"STATX_ATTR_VERITY flag is set" ); +} + +static struct test_cases { +void (*tfunc)(void ); +} tcases[] = { + {&test_flagged}, + {&test_unflagged}, +}; + +static void run (unsigned int i) +{ + tcases[i].tfunc (); +} + +static void flag_setup (void ) +{ +int attr, ret; +struct fsverity_enable_arg enable; + + fd_flagged =SAFE_OPEN (TESTFILE_FLAGGED ,O_RDONLY ,0664 ); + + ret =ioctl (fd_flagged,FS_IOC_GETFLAGS , &attr); +if (ret <0 ) { +if (errno ==ENOTTY ) +tst_brk (TCONF |TERRNO ,"FS_IOC_GETFLAGS not supported" ); + +tst_brk (TBROK |TERRNO ,"ioctl(%i, FS_IOC_GETFLAGS, ...)" , fd_flagged); + } + +memset (&enable,0 ,sizeof (enable)); + enable.version =1 ; + enable.hash_algorithm = hash_algorithms[0 ]; + enable.block_size =4096 ; + enable.salt_size =0 ; + enable.salt_ptr = (intptr_t )NULL ; + enable.sig_size =0 ; + enable.sig_ptr = (intptr_t )NULL ; + + ret =ioctl (fd_flagged,FS_IOC_ENABLE_VERITY , &enable); +if (ret <0 ) { +if (errno ==EOPNOTSUPP ) { +tst_brk (TCONF , +"fs-verity is not supported on the file system or by the kernel" ); + } +tst_brk (TBROK |TERRNO ,"ioctl(%i, FS_IOC_ENABLE_VERITY) failed" , fd_flagged); + } + + ret =ioctl (fd_flagged,FS_IOC_GETFLAGS , &attr); +if ((ret ==0 ) && !(attr &FS_VERITY_FL )) +tst_res (TFAIL ,"%i: fs-verity enabled but FS_VERITY_FL bit not set" , fd_flagged); + +SAFE_CLOSE (fd_flagged); +} + +static void setup (void ) +{ +TEST (mount (tst_device->dev,MNTPOINT , tst_device->fs_type,0 ,NULL )); +if (TST_RET ) {
testcases/kernel/syscalls/statx/statx09.c line 137
Quoted 10 lines
testcases/kernel/syscalls/statx/statx09.c new file +10
-0+if (TST_ERR ==EINVAL ) +tst_brk (TCONF ,"fs-verity not supported on loopdev" ); + +tst_brk (TBROK |TERRNO ,"mount() failed with %ld" ,TST_RET ); + } + mount_flag =1 ; + + fd_unflagged =SAFE_OPEN (TESTFILE_UNFLAGGED ,O_RDWR |O_CREAT ,0664 ); + fd_flagged =SAFE_OPEN (TESTFILE_FLAGGED ,O_RDWR |O_CREAT ,0664 ); +SAFE_FILE_PRINTF (TESTFILE_FLAGGED ,"a" );
There is no reason to actually open the file descriptors here when the file is created with SAFE_FILE_PRINTF().
So the whole test can be simplified as:
@@ -36,7 +36,6 @@
#define TESTFILE_FLAGGED MNTPOINT"/test_file3"
#define TESTFILE_UNFLAGGED MNTPOINT"/test_file4"
-static int fd_flagged, fd_unflagged;
static int mount_flag;
static const uint32_t hash_algorithms[] = {
@@ -85,15 +84,16 @@ static void flag_setup(void)
{
int attr, ret;
struct fsverity_enable_arg enable;+ int fd;
- fd_flagged = SAFE_OPEN(TESTFILE_FLAGGED, O_RDONLY, 0664);
+ fd = SAFE_OPEN(TESTFILE_FLAGGED, O_RDONLY, 0664);
- ret = ioctl(fd_flagged, FS_IOC_GETFLAGS, &attr);
+ ret = ioctl(fd, FS_IOC_GETFLAGS, &attr);
if (ret < 0) {
if (errno == ENOTTY)
tst_brk(TCONF | TERRNO, "FS_IOC_GETFLAGS not supported");- tst_brk(TBROK | TERRNO, "ioctl(%i, FS_IOC_GETFLAGS, ...)", fd_flagged);
+ tst_brk(TBROK | TERRNO, "ioctl(%i, FS_IOC_GETFLAGS, ...)", fd);
}
memset(&enable, 0, sizeof(enable));
@@ -105,20 +105,20 @@ static void flag_setup(void)
enable.sig_size = 0;
enable.sig_ptr = (intptr_t)NULL;- ret = ioctl(fd_flagged, FS_IOC_ENABLE_VERITY, &enable);
+ ret = ioctl(fd, FS_IOC_ENABLE_VERITY, &enable);
if (ret < 0) {
if (errno == EOPNOTSUPP) {
tst_brk(TCONF,
"fs-verity is not supported on the file system or by the kernel");
}
- tst_brk(TBROK | TERRNO, "ioctl(%i, FS_IOC_ENABLE_VERITY) failed", fd_flagged);
+ tst_brk(TBROK | TERRNO, "ioctl(%i, FS_IOC_ENABLE_VERITY) failed", fd);
}- ret = ioctl(fd_flagged, FS_IOC_GETFLAGS, &attr);
+ ret = ioctl(fd, FS_IOC_GETFLAGS, &attr);
if ((ret == 0) && !(attr & FS_VERITY_FL))- tst_res(TFAIL, "%i: fs-verity enabled but FS_VERITY_FL bit not set", fd_flagged);
+ tst_res(TFAIL, "%i: fs-verity enabled but FS_VERITY_FL bit not set", fd);
- SAFE_CLOSE(fd_flagged);
+ SAFE_CLOSE(fd);
}
static void setup(void)
@@ -132,21 +132,14 @@ static void setup(void)
}
mount_flag = 1;- fd_unflagged = SAFE_OPEN(TESTFILE_UNFLAGGED, O_RDWR | O_CREAT, 0664);
- fd_flagged = SAFE_OPEN(TESTFILE_FLAGGED, O_RDWR | O_CREAT, 0664);
SAFE_FILE_PRINTF(TESTFILE_FLAGGED, "a");- SAFE_CLOSE(fd_flagged);
+ SAFE_FILE_PRINTF(TESTFILE_UNFLAGGED, "a");
flag_setup();
}
static void cleanup(void)
{
- if (fd_flagged > 0)
- SAFE_CLOSE(fd_flagged);
- if (fd_unflagged > 0)
- SAFE_CLOSE(fd_unflagged);
-
if (mount_flag)
tst_umount(MNTPOINT);}
Quoted 38 lines
testcases/kernel/syscalls/statx/statx09.c new file +35
-0+SAFE_CLOSE (fd_flagged); + +flag_setup (); +} + +static void cleanup (void ) +{ +if (fd_flagged >0 ) +SAFE_CLOSE (fd_flagged); +if (fd_unflagged >0 ) +SAFE_CLOSE (fd_unflagged); + +if (mount_flag) +tst_umount (MNTPOINT ); +} + +static struct tst_test test = { + .test = run, + .tcnt =ARRAY_SIZE (tcases), + .setup = setup, + .cleanup = cleanup, + .needs_root =1 , + .mntpoint =MNTPOINT , + .format_device =1 , + .dev_fs_type ="ext4" , + .dev_fs_opts = (const char *const []){"-O verity" ,NULL }, + .needs_kconfigs = (const char *[]) { +"CONFIG_FS_VERITY" , +NULL + }, + .needs_cmds = (const char *[]) { +"mkfs.ext4 >= 1.45.2" , +NULL + } +};Signature · 1 line
1.8.3.1
Signature · 5 lines
Cyril Hrubis [email protected] -- Mailing list info: https://lists.linux.it/listinfo/ltp
PATCH v3 1/1 syscalls/statx09: Add new test
This test is basically the same as statx04 but here we check for the STATX_ATTR_VERITY flag which is currently only implemented on ext4.
--- configure.ac | 1 + include/lapi/fs.h | 4 + include/lapi/fsverity.h | 38 +++++++ include/lapi/stat.h | 4 + m4/ltp-fsverity.m4 | 10 ++ runtest/syscalls | 1 + testcases/kernel/syscalls/statx/.gitignore | 1 + testcases/kernel/syscalls/statx/statx09.c | 161 +++++++++++++++++++++++++++++ 8 files changed, 220 insertions(+) create mode 100644 include/lapi/fsverity.h create mode 100644 m4/ltp-fsverity.m4 create mode 100644 testcases/kernel/syscalls/statx/statx09.c
configure.ac +1 -0
@@ -367,6 +367,7 @@ LTP_CHECK_SELINUX LTP_CHECK_SYNC_ADD_AND_FETCH LTP_CHECK_SYSCALL_EVENTFD LTP_CHECK_SYSCALL_FCNTL +LTP_CHECK_FSVERITY if test "x$with_numa" = xyes; then LTP_CHECK_SYSCALL_NUMA
include/lapi/fs.h +4 -0
@@ -41,6 +41,10 @@#define FS_NODUMP_FL 0x00000040/* do not dump file */ #endif +#ifndef FS_VERITY_FL +#define FS_VERITY_FL 0x00100000/* Verity protected inode */ +#endif +/* * Helper function to get MAX_LFS_FILESIZE. * Missing PAGE_SHIFT on some libc prevents defining MAX_LFS_FILESIZE.
include/lapi/fsverity.h new file +38 -0
@@ -0,0 +1,38 @@ +// SPDX-License-Identifier: GPL-2.0-or-later +/* +* Copyright (c) 2022 FUJITSU LIMITED. All rights reserved. +* Author: Dai Shili <[email protected]> +*/ +#ifndef LAPI_FSVERITY_H__ +#define LAPI_FSVERITY_H__ + +#include "config.h" +#include <stdint.h> + +#ifdef HAVE_LINUX_FSVERITY_H +#include <linux/fsverity.h> +#endif + +#ifndef FS_VERITY_HASH_ALG_SHA256 +# define FS_VERITY_HASH_ALG_SHA256 1 +#endif + +#ifndef HAVE_STRUCT_FSVERITY_ENABLE_ARG +struct fsverity_enable_arg { +uint32_t version; +uint32_t hash_algorithm; +uint32_t block_size; +uint32_t salt_size; +uint64_t salt_ptr; +uint32_t sig_size; +uint32_t __reserved1; +uint64_t sig_ptr; +uint64_t __reserved2[11 ]; +}; +#endif + +#ifndef FS_IOC_ENABLE_VERITY +# define FS_IOC_ENABLE_VERITY _IOW('f', 133, struct fsverity_enable_arg) +#endif + +#endif
include/lapi/stat.h +4 -0
@@ -223,6 +223,10 @@ static inline int statx(int dirfd, const char *pathname, unsigned int flags,# define STATX_ATTR_AUTOMOUNT 0x00001000#endif +#ifndef STATX_ATTR_VERITY +# define STATX_ATTR_VERITY 0x00100000 +#endif +#ifndef AT_SYMLINK_NOFOLLOW # define AT_SYMLINK_NOFOLLOW 0x100#endif
m4/ltp-fsverity.m4 new file +10 -0
@@ -0,0 +1,10 @@ +dnl SPDX-License-Identifier: GPL-2.0-or-later +dnl Copyright (c) 2022 Fujitsu Ltd. +dnl Author: Dai Shili <[email protected]> + +AC_DEFUN([LTP_CHECK_FSVERITY],[ + AC_CHECK_HEADERS([linux/fsverity.h], [have_fsverity=yes], [AC_MSG_WARN(missing linux/fsverity.h header)]) + if test "x$have_fsverity" = "xyes"; then + AC_CHECK_TYPES(struct fsverity_enable_arg,,,[#include <linux/fsverity.h>]) + fi +])
runtest/syscalls +1 -0
@@ -1744,6 +1744,7 @@ statx05 statx05 statx06 statx06 statx07 statx07 statx08 statx08 +statx09 statx09 membarrier01 membarrier01
testcases/kernel/syscalls/statx/.gitignore +1 -0
@@ -6,3 +6,4 @@ /statx06 /statx07 /statx08 +/statx09
testcases/kernel/syscalls/statx/statx09.c new file +161 -0
161 lines not on this page · raw message
Signature · 5 lines
1.8.3.1 -- Mailing list info: https://lists.linux.it/listinfo/ltp
Hi Dai
Quoted 76 lines
This test is basically the same as statx04 but here we check for the
STATX_ATTR_VERITYflag which is currently only implemented on ext4.Signed-off-by Dai Shili<[email protected]>--- configure.ac | 1 + include/lapi/fs.h | 4 + include/lapi/fsverity.h | 38 +++++++ include/lapi/stat.h | 4 + m4/ltp-fsverity.m4 | 10 ++ runtest/syscalls | 1 + testcases/kernel/syscalls/statx/.gitignore | 1 + testcases/kernel/syscalls/statx/statx09.c | 161 +++++++++++++++++++++++++++++ 8 files changed, 220 insertions(+)create mode 100644
include/lapi/fsverity.h
create mode 100644 m4/ltp-fsverity.m4
create mode 100644testcases/kernel/syscalls/statx/statx09.cconfigure.ac +1
-0@@ -367,6 +367,7 @@ LTP_CHECK_SELINUX LTP_CHECK_SYNC_ADD_AND_FETCH LTP_CHECK_SYSCALL_EVENTFD LTP_CHECK_SYSCALL_FCNTL +LTP_CHECK_FSVERITY if test "x$with_numa" = xyes; then LTP_CHECK_SYSCALL_NUMAinclude/lapi/fs.h +4
-0@@ -41,6 +41,10 @@#define FS_NODUMP_FL 0x00000040/* do not dump file */ #endif +#ifndef FS_VERITY_FL +#define FS_VERITY_FL 0x00100000/* Verity protected inode */ +#endif +/* * Helper function to get MAX_LFS_FILESIZE. * Missing PAGE_SHIFT on some libc prevents defining MAX_LFS_FILESIZE. include/lapi/fsverity.h new file +25
-0@@ -0,0 +1,38 @@ +// SPDX-License-Identifier: GPL-2.0-or-later +/* +* Copyright (c) 2022 FUJITSU LIMITED. All rights reserved. +* Author: Dai Shili<[email protected]> +*/ +#ifndef LAPI_FSVERITY_H__ +#define LAPI_FSVERITY_H__ + +#include "config.h" +#include<stdint.h> + +#ifdef HAVE_LINUX_FSVERITY_H +#include<linux/fsverity.h> +#endif + +#ifndef FS_VERITY_HASH_ALG_SHA256 +# define FS_VERITY_HASH_ALG_SHA256 1 +#endif + +#ifndef HAVE_STRUCT_FSVERITY_ENABLE_ARG +struct fsverity_enable_arg { + uint32_t version; + uint32_t hash_algorithm; + uint32_t block_size; + uint32_t salt_size;
include/lapi/fsverity.h line 35
Quoted 10 lines
include/lapi/fsverity.h new file +10
-0+uint64_t salt_ptr; +uint32_t sig_size; +uint32_t __reserved1; +uint64_t sig_ptr; + uint64_t __reserved2[11]; +}; +#endif + +#ifndef FS_IOC_ENABLE_VERITY +# define FS_IOC_ENABLE_VERITY _IOW('f', 133, struct fsverity_enable_arg)
The _IOW definition is in <sys/ioctl.h>, so we should include it in here.
Quoted 75 lines
include/lapi/fsverity.h new file +3
-0+#endif + +#endif include/lapi/stat.h +4
-0@@ -223,6 +223,10 @@ static inline int statx(int dirfd, const char *pathname, unsigned int flags,# define STATX_ATTR_AUTOMOUNT 0x00001000#endif +#ifndef STATX_ATTR_VERITY +# define STATX_ATTR_VERITY 0x00100000 +#endif +#ifndef AT_SYMLINK_NOFOLLOW # define AT_SYMLINK_NOFOLLOW 0x100#endif m4/ltp-fsverity.m4 new file +10
-0@@ -0,0 +1,10 @@ +dnl SPDX-License-Identifier: GPL-2.0-or-later +dnl Copyright (c) 2022 Fujitsu Ltd. +dnl Author: Dai Shili<[email protected]> + +AC_DEFUN([LTP_CHECK_FSVERITY],[ + AC_CHECK_HEADERS([linux/fsverity.h], [have_fsverity=yes], [AC_MSG_WARN(missing linux/fsverity.h header)]) + if test "x$have_fsverity" = "xyes"; then + AC_CHECK_TYPES(struct fsverity_enable_arg,,,[#include<linux/fsverity.h>]) + fi +])runtest/syscalls +1
-0@@ -1744,6 +1744,7 @@ statx05 statx05 statx06 statx06 statx07 statx07 statx08 statx08 +statx09 statx09 membarrier01 membarrier01testcases/kernel/syscalls/statx/.gitignore +1
-0@@ -6,3 +6,4 @@ /statx06 /statx07 /statx08 +/statx09testcases/kernel/syscalls/statx/statx09.c new file +14
-0@@ -0,0 +1,161 @@ +// SPDX-License-Identifier: GPL-2.0-or-later +/* +* Copyright (c) 2022 FUJITSU LIMITED. All rights reserved. +* Author: Dai Shili<[email protected]> +*/ + +/*\ +* [Description] +* +* This code tests if the attributes field of statx received expected value. +* File set with following flags by using SAFE_IOCTL: +* +* - STATX_ATTR_VERITY: statx() system call sets STATX_ATTR_VERITY if the file +* has fs-verity enabled. This can perform better than FS_IOC_GETFLAGS and
testcases/kernel/syscalls/statx/statx09.c line 24
Quoted 10 lines
testcases/kernel/syscalls/statx/statx09.c new file +10
-0+* FS_IOC_MEASURE_VERITY because it doesn't require opening the file, +* and opening verity files can be expensive. +* +* Minimum Linux version required is v5.5. +*/ + +#define _GNU_SOURCE +#include <sys/mount.h> +#include <stdlib.h> +#include <linux/ioctl.h>
This can be removed if we use <sys/ioctl.h> in lapi/fsverity.h.
testcases/kernel/syscalls/statx/statx09.c line 33
Quoted 9 lines
testcases/kernel/syscalls/statx/statx09.c new file +9
-0+#include "tst_test.h" +#include "lapi/fs.h" +#include "lapi/fsverity.h" +#include "lapi/stat.h" +#include <inttypes.h> + +#define MNTPOINT "mnt_point" +#define TESTFILE_FLAGGED MNTPOINT"/test_file3" +#define TESTFILE_UNFLAGGED MNTPOINT"/test_file4"
I think using MNTPOINT"/testfile_flagged" or test_file1 is meaningful.
Best Regards
Yang Xu
Quoted 128 lines
testcases/kernel/syscalls/statx/statx09.c new file +128
-0+ +static int mount_flag; + +static const uint32_t hash_algorithms[] = { +FS_VERITY_HASH_ALG_SHA256 , +}; + +static void test_flagged (void ) +{ +struct statx buf; + +TST_EXP_PASS (statx (AT_FDCWD ,TESTFILE_FLAGGED ,0 ,0 ,&buf), +"statx(AT_FDCWD, %s, 0, 0,&buf)" ,TESTFILE_FLAGGED ); + +if (buf.stx_attributes&STATX_ATTR_VERITY ) +tst_res (TPASS ,"STATX_ATTR_VERITY flag is set: (%" PRIu64") " , + (uint64_t )buf.stx_attributes); +else +tst_res (TFAIL ,"STATX_ATTR_VERITY flag is not set" ); +} + +static void test_unflagged (void ) +{ +struct statx buf; + +TST_EXP_PASS (statx (AT_FDCWD ,TESTFILE_UNFLAGGED ,0 ,0 ,&buf), +"statx(AT_FDCWD, %s, 0, 0,&buf)" ,TESTFILE_UNFLAGGED ); + +if ((buf.stx_attributes&STATX_ATTR_VERITY ) ==0 ) +tst_res (TPASS ,"STATX_ATTR_VERITY flag is not set" ); +else +tst_res (TFAIL ,"STATX_ATTR_VERITY flag is set" ); +} + +static struct test_cases { +void (*tfunc)(void ); +} tcases[] = { + {&test_flagged}, + {&test_unflagged}, +}; + +static void run (unsigned int i) +{ + tcases[i].tfunc (); +} + +static void flag_setup (void ) +{ +int fd, attr, ret; +struct fsverity_enable_arg enable; + + fd =SAFE_OPEN (TESTFILE_FLAGGED ,O_RDONLY ,0664 ); + + ret =ioctl (fd,FS_IOC_GETFLAGS ,&attr); +if (ret<0 ) { +if (errno ==ENOTTY ) +tst_brk (TCONF |TERRNO ,"FS_IOC_GETFLAGS not supported" ); + +tst_brk (TBROK |TERRNO ,"ioctl(%i, FS_IOC_GETFLAGS, ...)" , fd); + } + +memset (&enable,0 ,sizeof (enable)); + enable.version =1 ; + enable.hash_algorithm = hash_algorithms[0 ]; + enable.block_size =4096 ; + enable.salt_size =0 ; + enable.salt_ptr = (intptr_t )NULL ; + enable.sig_size =0 ; + enable.sig_ptr = (intptr_t )NULL ; + + ret =ioctl (fd,FS_IOC_ENABLE_VERITY ,&enable); +if (ret<0 ) { +if (errno ==EOPNOTSUPP ) { +tst_brk (TCONF , +"fs-verity is not supported on the file system or by the kernel" ); + } +tst_brk (TBROK |TERRNO ,"ioctl(%i, FS_IOC_ENABLE_VERITY) failed" , fd); + } + + ret =ioctl (fd,FS_IOC_GETFLAGS ,&attr); +if ((ret ==0 )&& !(attr&FS_VERITY_FL )) +tst_res (TFAIL ,"%i: fs-verity enabled but FS_VERITY_FL bit not set" , fd); + +SAFE_CLOSE (fd); +} + +static void setup (void ) +{ +TEST (mount (tst_device->dev,MNTPOINT , tst_device->fs_type,0 ,NULL )); +if (TST_RET ) { +if (TST_ERR ==EINVAL ) +tst_brk (TCONF ,"fs-verity not supported on loopdev" ); + +tst_brk (TBROK |TERRNO ,"mount() failed with %ld" ,TST_RET ); + } + mount_flag =1 ; + +SAFE_FILE_PRINTF (TESTFILE_FLAGGED ,"a" ); +SAFE_FILE_PRINTF (TESTFILE_UNFLAGGED ,"a" ); + +flag_setup (); +} + +static void cleanup (void ) +{ +if (mount_flag) +tst_umount (MNTPOINT ); +} + +static struct tst_test test = { + .test = run, + .tcnt =ARRAY_SIZE (tcases), + .setup = setup, + .cleanup = cleanup, + .needs_root =1 , + .mntpoint =MNTPOINT , + .format_device =1 , + .dev_fs_type ="ext4" , + .dev_fs_opts = (const char *const []){"-O verity" ,NULL }, + .needs_kconfigs = (const char *[]) { +"CONFIG_FS_VERITY" , +NULL + }, + .needs_cmds = (const char *[]) { +"mkfs.ext4>= 1.45.2" , +NULL + } +};
Signature · 1 line
Mailing list info: https://lists.linux.it/listinfo/ltp
PATCH v4 1/1 syscalls/statx09: Add new test
This test is basically the same as statx04 but here we check for the STATX_ATTR_VERITY flag which is currently only implemented on ext4.
--- configure.ac | 1 + include/lapi/fs.h | 4 + include/lapi/fsverity.h | 39 +++++++ include/lapi/stat.h | 4 + m4/ltp-fsverity.m4 | 10 ++ runtest/syscalls | 1 + testcases/kernel/syscalls/statx/.gitignore | 1 + testcases/kernel/syscalls/statx/statx09.c | 160 +++++++++++++++++++++++++++++ 8 files changed, 220 insertions(+) create mode 100644 include/lapi/fsverity.h create mode 100644 m4/ltp-fsverity.m4 create mode 100644 testcases/kernel/syscalls/statx/statx09.c
configure.ac +1 -0
@@ -367,6 +367,7 @@ LTP_CHECK_SELINUX LTP_CHECK_SYNC_ADD_AND_FETCH LTP_CHECK_SYSCALL_EVENTFD LTP_CHECK_SYSCALL_FCNTL +LTP_CHECK_FSVERITY if test "x$with_numa" = xyes; then LTP_CHECK_SYSCALL_NUMA
include/lapi/fs.h +4 -0
@@ -41,6 +41,10 @@#define FS_NODUMP_FL 0x00000040/* do not dump file */ #endif +#ifndef FS_VERITY_FL +#define FS_VERITY_FL 0x00100000/* Verity protected inode */ +#endif +/* * Helper function to get MAX_LFS_FILESIZE. * Missing PAGE_SHIFT on some libc prevents defining MAX_LFS_FILESIZE.
include/lapi/fsverity.h new file +39 -0
@@ -0,0 +1,39 @@ +// SPDX-License-Identifier: GPL-2.0-or-later +/* +* Copyright (c) 2022 FUJITSU LIMITED. All rights reserved. +* Author: Dai Shili <[email protected]> +*/ +#ifndef LAPI_FSVERITY_H__ +#define LAPI_FSVERITY_H__ + +#include "config.h" +#include <stdint.h> +#include <sys/ioctl.h> + +#ifdef HAVE_LINUX_FSVERITY_H +#include <linux/fsverity.h> +#endif + +#ifndef FS_VERITY_HASH_ALG_SHA256 +# define FS_VERITY_HASH_ALG_SHA256 1 +#endif + +#ifndef HAVE_STRUCT_FSVERITY_ENABLE_ARG +struct fsverity_enable_arg { +uint32_t version; +uint32_t hash_algorithm; +uint32_t block_size; +uint32_t salt_size; +uint64_t salt_ptr; +uint32_t sig_size; +uint32_t __reserved1; +uint64_t sig_ptr; +uint64_t __reserved2[11 ]; +}; +#endif + +#ifndef FS_IOC_ENABLE_VERITY +# define FS_IOC_ENABLE_VERITY _IOW('f', 133, struct fsverity_enable_arg) +#endif + +#endif
include/lapi/stat.h +4 -0
@@ -223,6 +223,10 @@ static inline int statx(int dirfd, const char *pathname, unsigned int flags,# define STATX_ATTR_AUTOMOUNT 0x00001000#endif +#ifndef STATX_ATTR_VERITY +# define STATX_ATTR_VERITY 0x00100000 +#endif +#ifndef AT_SYMLINK_NOFOLLOW # define AT_SYMLINK_NOFOLLOW 0x100#endif
m4/ltp-fsverity.m4 new file +10 -0
@@ -0,0 +1,10 @@ +dnl SPDX-License-Identifier: GPL-2.0-or-later +dnl Copyright (c) 2022 Fujitsu Ltd. +dnl Author: Dai Shili <[email protected]> + +AC_DEFUN([LTP_CHECK_FSVERITY],[ + AC_CHECK_HEADERS([linux/fsverity.h], [have_fsverity=yes], [AC_MSG_WARN(missing linux/fsverity.h header)]) + if test "x$have_fsverity" = "xyes"; then + AC_CHECK_TYPES(struct fsverity_enable_arg,,,[#include <linux/fsverity.h>]) + fi +])
runtest/syscalls +1 -0
@@ -1744,6 +1744,7 @@ statx05 statx05 statx06 statx06 statx07 statx07 statx08 statx08 +statx09 statx09 membarrier01 membarrier01
testcases/kernel/syscalls/statx/.gitignore +1 -0
@@ -6,3 +6,4 @@ /statx06 /statx07 /statx08 +/statx09
testcases/kernel/syscalls/statx/statx09.c new file +160 -0
160 lines not on this page · raw message
Signature · 5 lines
1.8.3.1 -- Mailing list info: https://lists.linux.it/listinfo/ltp
Hi Dai
Now, looks good to me
ps: I won't be online next week because of enjoying the Chinese New Year holiday
Best Regards
Yang Xu
Quoted 308 lines
This test is basically the same as statx04 but here we check for the
STATX_ATTR_VERITYflag which is currently only implemented on ext4.Signed-off-by Dai Shili<[email protected]>--- configure.ac | 1 + include/lapi/fs.h | 4 + include/lapi/fsverity.h | 39 +++++++ include/lapi/stat.h | 4 + m4/ltp-fsverity.m4 | 10 ++ runtest/syscalls | 1 + testcases/kernel/syscalls/statx/.gitignore | 1 + testcases/kernel/syscalls/statx/statx09.c | 160 +++++++++++++++++++++++++++++ 8 files changed, 220 insertions(+)create mode 100644
include/lapi/fsverity.h
create mode 100644 m4/ltp-fsverity.m4
create mode 100644testcases/kernel/syscalls/statx/statx09.cconfigure.ac +1
-0@@ -367,6 +367,7 @@ LTP_CHECK_SELINUX LTP_CHECK_SYNC_ADD_AND_FETCH LTP_CHECK_SYSCALL_EVENTFD LTP_CHECK_SYSCALL_FCNTL +LTP_CHECK_FSVERITY if test "x$with_numa" = xyes; then LTP_CHECK_SYSCALL_NUMAinclude/lapi/fs.h +4
-0@@ -41,6 +41,10 @@#define FS_NODUMP_FL 0x00000040/* do not dump file */ #endif +#ifndef FS_VERITY_FL +#define FS_VERITY_FL 0x00100000/* Verity protected inode */ +#endif +/* * Helper function to get MAX_LFS_FILESIZE. * Missing PAGE_SHIFT on some libc prevents defining MAX_LFS_FILESIZE. include/lapi/fsverity.h new file +39
-0@@ -0,0 +1,39 @@ +// SPDX-License-Identifier: GPL-2.0-or-later +/* +* Copyright (c) 2022 FUJITSU LIMITED. All rights reserved. +* Author: Dai Shili<[email protected]> +*/ +#ifndef LAPI_FSVERITY_H__ +#define LAPI_FSVERITY_H__ + +#include "config.h" +#include <stdint.h> +#include <sys/ioctl.h> + +#ifdef HAVE_LINUX_FSVERITY_H +#include <linux/fsverity.h> +#endif + +#ifndef FS_VERITY_HASH_ALG_SHA256 +# define FS_VERITY_HASH_ALG_SHA256 1 +#endif + +#ifndef HAVE_STRUCT_FSVERITY_ENABLE_ARG +struct fsverity_enable_arg { +uint32_t version; +uint32_t hash_algorithm; +uint32_t block_size; +uint32_t salt_size; +uint64_t salt_ptr; +uint32_t sig_size; +uint32_t __reserved1; +uint64_t sig_ptr; +uint64_t __reserved2[11 ]; +}; +#endif + +#ifndef FS_IOC_ENABLE_VERITY +# define FS_IOC_ENABLE_VERITY _IOW('f', 133, struct fsverity_enable_arg) +#endif + +#endif include/lapi/stat.h +4
-0@@ -223,6 +223,10 @@ static inline int statx(int dirfd, const char *pathname, unsigned int flags,# define STATX_ATTR_AUTOMOUNT 0x00001000#endif +#ifndef STATX_ATTR_VERITY +# define STATX_ATTR_VERITY 0x00100000 +#endif +#ifndef AT_SYMLINK_NOFOLLOW # define AT_SYMLINK_NOFOLLOW 0x100#endif m4/ltp-fsverity.m4 new file +10
-0@@ -0,0 +1,10 @@ +dnl SPDX-License-Identifier: GPL-2.0-or-later +dnl Copyright (c) 2022 Fujitsu Ltd. +dnl Author: Dai Shili<[email protected]> + +AC_DEFUN([LTP_CHECK_FSVERITY],[ + AC_CHECK_HEADERS([linux/fsverity.h], [have_fsverity=yes], [AC_MSG_WARN(missing linux/fsverity.h header)]) + if test "x$have_fsverity" = "xyes"; then + AC_CHECK_TYPES(struct fsverity_enable_arg,,,[#include<linux/fsverity.h>]) + fi +])runtest/syscalls +1
-0@@ -1744,6 +1744,7 @@ statx05 statx05 statx06 statx06 statx07 statx07 statx08 statx08 +statx09 statx09 membarrier01 membarrier01testcases/kernel/syscalls/statx/.gitignore +1
-0@@ -6,3 +6,4 @@ /statx06 /statx07 /statx08 +/statx09testcases/kernel/syscalls/statx/statx09.c new file +160
-0@@ -0,0 +1,160 @@ +// SPDX-License-Identifier: GPL-2.0-or-later +/* +* Copyright (c) 2022 FUJITSU LIMITED. All rights reserved. +* Author: Dai Shili<[email protected]> +*/ + +/*\ +* [Description] +* +* This code tests if the attributes field of statx received expected value. +* File set with following flags by using SAFE_IOCTL: +* +* - STATX_ATTR_VERITY: statx() system call sets STATX_ATTR_VERITY if the file +* has fs-verity enabled. This can perform better than FS_IOC_GETFLAGS and +* FS_IOC_MEASURE_VERITY because it doesn't require opening the file, +* and opening verity files can be expensive. +* +* Minimum Linux version required is v5.5. +*/ + +#define _GNU_SOURCE +#include <sys/mount.h> +#include <stdlib.h> +#include "tst_test.h" +#include "lapi/fs.h" +#include "lapi/fsverity.h" +#include "lapi/stat.h" +#include <inttypes.h> + +#define MNTPOINT "mnt_point" +#define TESTFILE_FLAGGED MNTPOINT"/test_file1" +#define TESTFILE_UNFLAGGED MNTPOINT"/test_file2" + +static int mount_flag; + +static const uint32_t hash_algorithms[] = { +FS_VERITY_HASH_ALG_SHA256 , +}; + +static void test_flagged (void ) +{ +struct statx buf; + +TST_EXP_PASS (statx (AT_FDCWD ,TESTFILE_FLAGGED ,0 ,0 ,&buf), +"statx(AT_FDCWD, %s, 0, 0,&buf)" ,TESTFILE_FLAGGED ); + +if (buf.stx_attributes&STATX_ATTR_VERITY ) +tst_res (TPASS ,"STATX_ATTR_VERITY flag is set: (%" PRIu64") " , + (uint64_t )buf.stx_attributes); +else +tst_res (TFAIL ,"STATX_ATTR_VERITY flag is not set" ); +} + +static void test_unflagged (void ) +{ +struct statx buf; + +TST_EXP_PASS (statx (AT_FDCWD ,TESTFILE_UNFLAGGED ,0 ,0 ,&buf), +"statx(AT_FDCWD, %s, 0, 0,&buf)" ,TESTFILE_UNFLAGGED ); + +if ((buf.stx_attributes&STATX_ATTR_VERITY ) ==0 ) +tst_res (TPASS ,"STATX_ATTR_VERITY flag is not set" ); +else +tst_res (TFAIL ,"STATX_ATTR_VERITY flag is set" ); +} + +static struct test_cases { +void (*tfunc)(void ); +} tcases[] = { + {&test_flagged}, + {&test_unflagged}, +}; + +static void run (unsigned int i) +{ + tcases[i].tfunc (); +} + +static void flag_setup (void ) +{ +int fd, attr, ret; +struct fsverity_enable_arg enable; + + fd =SAFE_OPEN (TESTFILE_FLAGGED ,O_RDONLY ,0664 ); + + ret =ioctl (fd,FS_IOC_GETFLAGS ,&attr); +if (ret<0 ) { +if (errno ==ENOTTY ) +tst_brk (TCONF |TERRNO ,"FS_IOC_GETFLAGS not supported" ); + +tst_brk (TBROK |TERRNO ,"ioctl(%i, FS_IOC_GETFLAGS, ...)" , fd); + } + +memset (&enable,0 ,sizeof (enable)); + enable.version =1 ; + enable.hash_algorithm = hash_algorithms[0 ]; + enable.block_size =4096 ; + enable.salt_size =0 ; + enable.salt_ptr = (intptr_t )NULL ; + enable.sig_size =0 ; + enable.sig_ptr = (intptr_t )NULL ; + + ret =ioctl (fd,FS_IOC_ENABLE_VERITY ,&enable); +if (ret<0 ) { +if (errno ==EOPNOTSUPP ) { +tst_brk (TCONF , +"fs-verity is not supported on the file system or by the kernel" ); + } +tst_brk (TBROK |TERRNO ,"ioctl(%i, FS_IOC_ENABLE_VERITY) failed" , fd); + } + + ret =ioctl (fd,FS_IOC_GETFLAGS ,&attr); +if ((ret ==0 )&& !(attr&FS_VERITY_FL )) +tst_res (TFAIL ,"%i: fs-verity enabled but FS_VERITY_FL bit not set" , fd); + +SAFE_CLOSE (fd); +} + +static void setup (void ) +{ +TEST (mount (tst_device->dev,MNTPOINT , tst_device->fs_type,0 ,NULL )); +if (TST_RET ) { +if (TST_ERR ==EINVAL ) +tst_brk (TCONF ,"fs-verity not supported on loopdev" ); + +tst_brk (TBROK |TERRNO ,"mount() failed with %ld" ,TST_RET ); + } + mount_flag =1 ; + +SAFE_FILE_PRINTF (TESTFILE_FLAGGED ,"a" ); +SAFE_FILE_PRINTF (TESTFILE_UNFLAGGED ,"a" ); + +flag_setup (); +} + +static void cleanup (void ) +{ +if (mount_flag) +tst_umount (MNTPOINT ); +} + +static struct tst_test test = { + .test = run, + .tcnt =ARRAY_SIZE (tcases), + .setup = setup, + .cleanup = cleanup, + .needs_root =1 , + .mntpoint =MNTPOINT , + .format_device =1 , + .dev_fs_type ="ext4" , + .dev_fs_opts = (const char *const []){"-O verity" ,NULL }, + .needs_kconfigs = (const char *[]) { +"CONFIG_FS_VERITY" , +NULL + }, + .needs_cmds = (const char *[]) { +"mkfs.ext4>= 1.45.2" , +NULL + } +};
Signature · 1 line
Mailing list info: https://lists.linux.it/listinfo/ltp
Hi!
Pushed with minor adjustenment to the documentation comment, thanks.
Signature · 5 lines
Cyril Hrubis [email protected] -- Mailing list info: https://lists.linux.it/listinfo/ltp
Hi all,
Quoted 10 lines
+++
b/testcases/kernel/syscalls/statx/statx09.ctestcases/kernel/syscalls/statx/statx09.c new file +8
-0@@ -0,0 +1,160 @@ +// SPDX-License-Identifier: GPL-2.0-or-later +/* +* Copyright (c) 2022 FUJITSU LIMITED. All rights reserved. +* Author: Dai Shili <[email protected]> +*/ + +/*\ +* [Description]
testcases/kernel/syscalls/statx/statx09.c line 18
Quoted 10 lines
testcases/kernel/syscalls/statx/statx09.c new file +10
-0+* +* This code tests if the attributes field of statx received expected value. +* File set with following flags by using SAFE_IOCTL: +* +* - STATX_ATTR_VERITY: statx() system call sets STATX_ATTR_VERITY if the file +* has fs-verity enabled. This can perform better than FS_IOC_GETFLAGS and +* FS_IOC_MEASURE_VERITY because it doesn't require opening the file, +* and opening verity files can be expensive. +* +* Minimum Linux version required is v5.5.
I know this has been merged, this probably not worth of fixing it, but the "required" is misleading when we detect via EOPNOTSUPP and EINVAL and thus not use .min_kver. If it was due possible backport,
thus it should have been e.g. "functionality has been merged in kernel v5.5".
Quoted 2 lines
(quoted diff) +2
-0+ */ +
...
testcases/kernel/syscalls/statx/statx09.c line 77
Quoted 11 lines
testcases/kernel/syscalls/statx/statx09.c new file +11
-0+static struct test_cases { +void (*tfunc)(void ); +} tcases[] = { + {&test_flagged}, + {&test_unflagged}, +}; + +static void run (unsigned int i) +{ + tcases[i].tfunc (); +}
OT: we may lack something in the API, when function like this need to be defined.
Kind regards,
Petr
Signature · 1 line
Mailing list info: https://lists.linux.it/listinfo/ltp
Hi!
Quoted 6 lines
testcases/kernel/syscalls/statx/statx09.c line 77
Quoted 4 lines
testcases/kernel/syscalls/statx/statx09.c new file +4
-0+static void run (unsigned int i) +{ + tcases[i].tfunc (); +}OT: we may lack something in the API, when function like this need to be defined.
See:
https://lists.linux.it/pipermail/ltp/2017-October/005829.html
https://lists.linux.it/pipermail/ltp/2017-July/005132.html
Signature · 5 lines
Cyril Hrubis [email protected] -- Mailing list info: https://lists.linux.it/listinfo/ltp
Hi all,
Quoted 8 lines
Hi!
Quoted 6 lines
testcases/kernel/syscalls/statx/statx09.c line 77
Quoted 4 lines
testcases/kernel/syscalls/statx/statx09.c new file +4
-0+static void run (unsigned int i) +{ + tcases[i].tfunc (); +}OT: we may lack something in the API, when function like this need to be defined.
Quoted 4 lines
See:
https://lists.linux.it/pipermail/ltp/2017-October/005829.html
https://lists.linux.it/pipermail/ltp/2017-July/005132.html
https://lore.kernel.org/ltp/[email protected]/
https://lore.kernel.org/ltp/[email protected]/
Very nice that you remember your old work :) (we didn't have patchwork back then).
Now I remember it - you already implemented it in 5 years old RFC, Jan didn't see a value and that's why it haven't been merged.
Yes, Jan is right that it complicates code a bit, but even if you replace this code:
statx09.c
static struct test_cases {
void (*tfunc)(void);
} tcases[] = {
{&test_flagged},
{&test_unflagged},
};static void run(unsigned int i)
{
tcases[i].tfunc();
}with .test_all where you have the switch it still kind of boilerplate. Thus I agree with cyrils argument:
https://lore.kernel.org/ltp/20171003125958.GB11692@rei/
"aiming to avoid the need to have a switch () in each testcase that implements a similar tests but cannot be easily data driven (as we do for most of tests that loop over an array of structures describing the test data)"
Thus, not sure if we want to rething the implementation, but I'd be for adding the support (sure doc and docparse adoption would need to be added but that's obvious).
Kind regards,
Petr
Signature · 1 line
Mailing list info: https://lists.linux.it/listinfo/ltp
Hi!
I also think that support for an array of functions is needed to cover all scenarios and cleanup the code a little bit. The real problem with tcases is that sometimes we are doing what we might do with multiple functions, but using an approach which is expecting struct and some sort of "filtering" in .test_all function.
And in some cases, where one particular testcase differs by a statement from an another, struct needs a flag to filter out the specific testcase. This would be easy to handle with two different functions.
Also the output message sometimes is stored into the struct, in order to show the correct TPASS/TFAIL message we need, according with the tcase. And this is probably an overengineering solution, since that would be handled well using multiple testcases functions, testing different scenarios and using different output messages.
Also simple tests, such as input arguments unit tests, would benefit from array of tests functions, since we can split tcases into multiple functions and make code more readable.
To sum up things, I think that having support for an array of test functions can cleanup code in many tests and make them easier to read/maintain. tcases can still do well sometimes, but adding the support for an array of functions can improve the LTP framework and so the way we are testing the kernel.
Andrea
Quoted 53 lines · Petr Vorel
Hi all,
Quoted 10 lines
Hi!
Quoted 6 lines
testcases/kernel/syscalls/statx/statx09.c line 77
Quoted 4 lines
testcases/kernel/syscalls/statx/statx09.c new file +4
-0+static void run (unsigned int i) +{ + tcases[i].tfunc (); +}OT: we may lack something in the API, when function like this need to be defined.
See:
https://lists.linux.it/pipermail/ltp/2017-October/005829.html
https://lists.linux.it/pipermail/ltp/2017-July/005132.htmlhttps://lore.kernel.org/ltp/[email protected]/
https://lore.kernel.org/ltp/[email protected]/Very nice that you remember your old work :) (we didn't have patchwork back then).
Now I remember it - you already implemented it in 5 years old RFC, Jan didn't see a value and that's why it haven't been merged.
Yes, Jan is right that it complicates code a bit, but even if you replace this code:
statx09.cstatic struct test_cases { void (*tfunc)(void); } tcases[] = { {&test_flagged}, {&test_unflagged}, };static void run(unsigned int i)
{ tcases[i].tfunc(); }with .test_all where you have the switch it still kind of boilerplate. Thus I agree with cyrils argument:
https://lore.kernel.org/ltp/20171003125958.GB11692@rei/
"aiming to avoid the need to have a switch () in each testcase that implements a similar tests but cannot be easily data driven (as we do for most of tests that loop over an array of structures describing the test data)"
Thus, not sure if we want to rething the implementation, but I'd be for adding the support (sure doc and docparse adoption would need to be added but that's obvious).
Kind regards,
Petr
Signature · 2 lines
-- Mailing list info: https://lists.linux.it/listinfo/ltp