Skip to content

Commit 887e6cc

Browse files
authored
tests: accout for syscalls missing on arm64 (#17409)
Both mknod and creat are missing on younger architectures. Jira: https://warthogs.atlassian.net/browse/SNAPDENG-37197 Signed-off-by: Zygmunt Krynicki <zygmunt.krynicki@canonical.com>
1 parent b373311 commit 887e6cc

3 files changed

Lines changed: 20 additions & 8 deletions

File tree

tests/main/snap-seccomp-blocks-certain-creat/test.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
#include <sys/syscall.h>
66
#include <unistd.h>
77

8+
#ifdef SYS_creat
89
static const char *errno_name(int e)
910
{
1011
switch (e) {
@@ -18,6 +19,7 @@ static const char *errno_name(int e)
1819
default: return strerror(e);
1920
}
2021
}
22+
#endif
2123

2224
static void test_creat(const char *dir, const char *name, int mode, const char *label)
2325
{

tests/main/snap-seccomp-blocks-certain-mknod/task.yaml

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -23,14 +23,18 @@ execute: |
2323
snap run test-snapd-sh.sh -c "\$SNAP_COMMON/test-mknod \$SNAP_COMMON" > output.txt
2424
cat output.txt
2525
26-
# mknod with setuid bit (mode S_IFIFO|4644) must be denied
27-
MATCH 'mknod setuid: EACCES' < output.txt
28-
29-
# mknod with setgid bit (mode S_IFIFO|2644) must be denied
30-
MATCH 'mknod setgid: EACCES' < output.txt
31-
32-
# mknod with normal mode (mode S_IFIFO|0644) must succeed
33-
MATCH 'mknod normal: succeeded' < output.txt
26+
# mknod setuid/setgid must be denied; sticky and normal must succeed
27+
# (skipped gracefully on architectures that don't have SYS_mknod, e.g. arm64)
28+
if grep -qE 'mknod setuid: skipped' output.txt; then
29+
echo "SYS_mknod is not available, all mknod tests should be skipped"
30+
MATCH 'mknod setuid: skipped' < output.txt
31+
MATCH 'mknod setgid: skipped' < output.txt
32+
MATCH 'mknod normal: skipped' < output.txt
33+
else
34+
MATCH 'mknod setuid: EACCES' < output.txt
35+
MATCH 'mknod setgid: EACCES' < output.txt
36+
MATCH 'mknod normal: succeeded' < output.txt
37+
fi
3438
3539
# mknodat with setuid bit must be denied
3640
MATCH 'mknodat setuid: EACCES' < output.txt

tests/main/snap-seccomp-blocks-certain-mknod/test.c

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ static void test_mknod(const char *dir, const char *name, mode_t mode, const cha
2626
snprintf(path, sizeof(path), "%s/%s", dir, name);
2727
unlink(path);
2828

29+
#ifdef SYS_mknod
2930
/* Use S_IFIFO (named pipe) as the file type: creating FIFOs does not
3031
* require CAP_MKNOD, so it works in a confined snap without extra
3132
* privileges.
@@ -37,6 +38,11 @@ static void test_mknod(const char *dir, const char *name, mode_t mode, const cha
3738
printf("mknod %s: succeeded\n", label);
3839
unlink(path);
3940
}
41+
#else
42+
/* mknod is not available on this architecture (e.g. arm64); skip. */
43+
(void)mode;
44+
printf("mknod %s: skipped (no SYS_mknod)\n", label);
45+
#endif
4046
}
4147

4248
static void test_mknodat(const char *dir, const char *name, mode_t mode, const char *label)

0 commit comments

Comments
 (0)