diff options
author | Eugene Syromyatnikov <evgsyr@gmail.com> | 2022-05-27 16:17:21 +0200 |
---|---|---|
committer | Dmitry V. Levin <ldv@strace.io> | 2022-05-27 14:38:34 +0000 |
commit | d65d4c13fb9f6531399aacb560087e89fc24a282 (patch) | |
tree | 39d4ee02efc574b74505bf4ca65d52c149c8c3ad | |
parent | e860eae1e8d8923599a78807e6ae49394a717b42 (diff) | |
download | strace-d65d4c13fb9f6531399aacb560087e89fc24a282.tar.gz |
tests: support both old and new landlock pseudopath
Since the ABI of landlock ruleset file name has been broken by Linux
commit v5.18-rc1~88^2, the landlock_create_ruleset-y now has to account
for both new and old possible names. Opt for checking the link value
in the test instead.
* tests/landlock_create_ruleset-y.c (FD_PATH): Remove.
(DECODE_FD): New macro.
* tests/landlock_create_ruleset.c: Include "xmalloc.h" and <stdlib.h>.
[!DECODE_FD] (DECODE_FD): New macro.
(main) <fd_str>: New variable.
[DECODE_FD] (main): Check the link path of the fd returned
by the landlock_create_ruleset call and set it to fd_str, which
is then printed.
-rw-r--r-- | tests/landlock_create_ruleset-y.c | 2 | ||||
-rw-r--r-- | tests/landlock_create_ruleset.c | 33 |
2 files changed, 33 insertions, 2 deletions
diff --git a/tests/landlock_create_ruleset-y.c b/tests/landlock_create_ruleset-y.c index 50e19c2d5..87632fd34 100644 --- a/tests/landlock_create_ruleset-y.c +++ b/tests/landlock_create_ruleset-y.c @@ -1,4 +1,4 @@ -#define FD_PATH "<anon_inode:[landlock-ruleset]>" +#define DECODE_FD 1 #define SKIP_IF_PROC_IS_UNAVAILABLE skip_if_unavailable("/proc/self/fd/") #include "landlock_create_ruleset.c" diff --git a/tests/landlock_create_ruleset.c b/tests/landlock_create_ruleset.c index bc1bcc2cf..476c40236 100644 --- a/tests/landlock_create_ruleset.c +++ b/tests/landlock_create_ruleset.c @@ -9,10 +9,12 @@ #include "tests.h" #include "scno.h" +#include "xmalloc.h" #include <inttypes.h> #include <stdio.h> #include <stdint.h> +#include <stdlib.h> #include <unistd.h> #include <linux/landlock.h> @@ -20,6 +22,9 @@ #ifndef RETVAL_INJECTED # define RETVAL_INJECTED 0 #endif +#ifndef DECODE_FD +# define DECODE_FD 0 +#endif #ifndef SKIP_IF_PROC_IS_UNAVAILABLE # define SKIP_IF_PROC_IS_UNAVAILABLE @@ -124,14 +129,40 @@ main(void) static const kernel_ulong_t sizes[] = { 8, 12, 16 }; for (size_t i = 0; i < ARRAY_SIZE(attr_vals); i++) { for (size_t j = 0; j < ARRAY_SIZE(sizes); j++) { + const char *fd_str = FD_PATH; + attr->handled_access_fs = attr_vals[i].val; rc = sys_landlock_create_ruleset(attr, sizes[j], 0); + +#if DECODE_FD + /* + * The ABI has been broken in commit v5.18-rc1~88^2 + * by adding brackets to the link value, hence, we can't + * rely on a specific name anymore and have to fetch it + * ourselves. + */ + if (rc >= 0) { + static char buf[256]; + char *path = xasprintf("/proc/self/fd/%ld", rc); + ssize_t ret = readlink(path, buf + 1, + sizeof(buf) - 3); + free(path); + + if (ret >= 0) { + buf[0] = '<'; + buf[ret + 1] = '>'; + buf[ret + 2] = '\0'; + fd_str = buf; + } + } +#endif + printf("landlock_create_ruleset({handled_access_fs=%s" "%s}, %llu, 0) = %s%s" INJ_STR, attr_vals[i].str, sizes[j] > sizeof(*attr) ? ", ..." : "", (unsigned long long) sizes[j], - errstr, rc > 0 ? FD_PATH : ""); + errstr, rc >= 0 ? fd_str : ""); } } |