Skip to content

Commit e7ccf54

Browse files
committed
tests: compile test_syscall with musl-gcc
In addition do a few more cleanups to the test: - Use `atol` to read longs - musl makes an ioctl that is not permitted in seccomp. We didn't use the return code anyway, so remove it. Signed-off-by: Pablo Barbáchano <[email protected]>
1 parent e56b6a2 commit e7ccf54

File tree

2 files changed

+14
-15
lines changed

2 files changed

+14
-15
lines changed

tests/host_tools/test_syscalls.c

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -28,14 +28,14 @@ void install_bpf_filter(char *bpf_file) {
2828
exit(EXIT_FAILURE);
2929
}
3030
size_t size = sb.st_size;
31-
size_t insn_len = size / sizeof(struct sock_filter);
3231
struct sock_filter *filterbuf = (struct sock_filter*)malloc(size);
3332
if (read(fd, filterbuf, size) == -1) {
3433
perror("read");
3534
exit(EXIT_FAILURE);
3635
}
3736

3837
/* Install seccomp filter */
38+
size_t insn_len = size / sizeof(struct sock_filter);
3939
struct sock_fprog prog = {
4040
.len = (unsigned short)(insn_len),
4141
.filter = filterbuf,
@@ -60,18 +60,17 @@ int main(int argc, char **argv) {
6060
char *bpf_file = argv[1];
6161
long syscall_id = atoi(argv[2]);
6262
long arg0, arg1, arg2, arg3;
63-
arg0 = arg1 = arg2 = arg3 = 0;
64-
if (argc > 3) arg0 = atoi(argv[3]);
65-
if (argc > 4) arg1 = atoi(argv[4]);
66-
if (argc > 5) arg2 = atoi(argv[5]);
67-
if (argc > 6) arg3 = atoi(argv[6]);
63+
arg0 = arg1 = arg2 = arg3 = 0L;
64+
if (argc > 3) arg0 = atol(argv[3]);
65+
if (argc > 4) arg1 = atol(argv[4]);
66+
if (argc > 5) arg2 = atol(argv[5]);
67+
if (argc > 6) arg3 = atol(argv[6]);
6868

6969
/* read seccomp filter from file */
7070
if (strcmp(bpf_file, "/dev/null") != 0) {
7171
install_bpf_filter(bpf_file);
7272
}
7373

7474
long res = syscall(syscall_id, arg0, arg1, arg2, arg3);
75-
printf("%ld\n", res);
7675
return EXIT_SUCCESS;
7776
}

tests/integration_tests/security/test_seccomp_validate.py

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -13,18 +13,18 @@
1313
import seccomp
1414

1515
from framework import utils
16-
from host_tools import cargo_build
1716

1817
ARCH = platform.machine()
1918

2019

21-
@pytest.fixture(scope="session")
22-
def bin_test_syscall(test_fc_session_root_path):
20+
@pytest.fixture
21+
def bin_test_syscall(tmp_path):
2322
"""Build the test_syscall binary."""
24-
test_syscall_bin = Path(test_fc_session_root_path) / "test_syscall"
25-
cargo_build.gcc_compile("host_tools/test_syscalls.c", test_syscall_bin)
23+
test_syscall_bin = tmp_path / "test_syscall"
24+
compile_cmd = f"musl-gcc -static host_tools/test_syscalls.c -o {test_syscall_bin}"
25+
utils.check_output(compile_cmd)
2626
assert test_syscall_bin.exists()
27-
yield test_syscall_bin
27+
yield test_syscall_bin.resolve()
2828

2929

3030
class BpfMapReader:
@@ -77,11 +77,11 @@ def split(self):
7777
for _ in range(map_len):
7878
# read key
7979
key_str_len = self.read_format("<Q")
80-
key_str = self.read_format(f"{key_str_len}s")
80+
key_str = self.read_format(f"{key_str_len}s").decode("ascii")
8181
# read value: vec of instructions
8282
insn_len = self.read_format("<Q")
8383
data = self.lookahead(insn_len * self.INSN_SIZEOF)
84-
threads[key_str.decode("ascii")] = data
84+
threads[key_str] = data
8585
self.offset += len(data)
8686

8787
assert self.is_eof()

0 commit comments

Comments
 (0)