Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

tests: compile test_syscall with musl-gcc #4957

Merged
merged 2 commits into from
Dec 13, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 6 additions & 7 deletions tests/host_tools/test_syscalls.c
Original file line number Diff line number Diff line change
Expand Up @@ -28,14 +28,14 @@ void install_bpf_filter(char *bpf_file) {
exit(EXIT_FAILURE);
}
size_t size = sb.st_size;
size_t insn_len = size / sizeof(struct sock_filter);
struct sock_filter *filterbuf = (struct sock_filter*)malloc(size);
if (read(fd, filterbuf, size) == -1) {
perror("read");
exit(EXIT_FAILURE);
}

/* Install seccomp filter */
size_t insn_len = size / sizeof(struct sock_filter);
struct sock_fprog prog = {
.len = (unsigned short)(insn_len),
.filter = filterbuf,
Expand All @@ -60,18 +60,17 @@ int main(int argc, char **argv) {
char *bpf_file = argv[1];
long syscall_id = atoi(argv[2]);
long arg0, arg1, arg2, arg3;
arg0 = arg1 = arg2 = arg3 = 0;
if (argc > 3) arg0 = atoi(argv[3]);
if (argc > 4) arg1 = atoi(argv[4]);
if (argc > 5) arg2 = atoi(argv[5]);
if (argc > 6) arg3 = atoi(argv[6]);
arg0 = arg1 = arg2 = arg3 = 0L;
if (argc > 3) arg0 = atol(argv[3]);
if (argc > 4) arg1 = atol(argv[4]);
if (argc > 5) arg2 = atol(argv[5]);
if (argc > 6) arg3 = atol(argv[6]);

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

long res = syscall(syscall_id, arg0, arg1, arg2, arg3);
printf("%ld\n", res);
return EXIT_SUCCESS;
}
16 changes: 8 additions & 8 deletions tests/integration_tests/security/test_seccomp_validate.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,18 +13,18 @@
import seccomp

from framework import utils
from host_tools import cargo_build

ARCH = platform.machine()


@pytest.fixture(scope="session")
def bin_test_syscall(test_fc_session_root_path):
@pytest.fixture
def bin_test_syscall(tmp_path):
"""Build the test_syscall binary."""
test_syscall_bin = Path(test_fc_session_root_path) / "test_syscall"
cargo_build.gcc_compile("host_tools/test_syscalls.c", test_syscall_bin)
test_syscall_bin = tmp_path / "test_syscall"
compile_cmd = f"musl-gcc -static host_tools/test_syscalls.c -o {test_syscall_bin}"
utils.check_output(compile_cmd)
assert test_syscall_bin.exists()
yield test_syscall_bin
yield test_syscall_bin.resolve()


class BpfMapReader:
Expand Down Expand Up @@ -77,11 +77,11 @@ def split(self):
for _ in range(map_len):
# read key
key_str_len = self.read_format("<Q")
key_str = self.read_format(f"{key_str_len}s")
key_str = self.read_format(f"{key_str_len}s").decode("ascii")
# read value: vec of instructions
insn_len = self.read_format("<Q")
data = self.lookahead(insn_len * self.INSN_SIZEOF)
threads[key_str.decode("ascii")] = data
threads[key_str] = data
self.offset += len(data)

assert self.is_eof()
Expand Down
Loading