Skip to content

Commit 1a111b9

Browse files
authored
Merge branch 'main' into seccomp2
2 parents b039ab8 + 0bee970 commit 1a111b9

File tree

11 files changed

+99
-103
lines changed

11 files changed

+99
-103
lines changed

.gitlint

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,8 @@ line-length=72
99

1010
[ignore-body-lines]
1111
# Ignore HTTP reference links
12-
# Ignore lines that start with 'Co-Authored-By' or with 'Signed-off-by'
13-
regex=(^\[.+\]: http.+)|(^Co-Authored-By)|(^Signed-off-by)
12+
# Ignore lines that start with 'Co-Authored-By', with 'Signed-off-by' or with 'Fixes'
13+
regex=(^\[.+\]: http.+)|(^Co-Authored-By)|(^Signed-off-by)|(^Fixes:)
1414

1515
[ignore-by-author-name]
1616
# Ignore certain rules for commits of which the author name matches a regex

Cargo.lock

Lines changed: 1 addition & 26 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/jailer/Cargo.toml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@ bench = false
1414
[dependencies]
1515
libc = "0.2.168"
1616
log-instrument = { path = "../log-instrument", optional = true }
17-
nix = { version = "0.29.0", default-features = false, features = ["dir"] }
1817
regex = { version = "1.11.1", default-features = false, features = ["std"] }
1918
thiserror = "2.0.6"
2019
vmm-sys-util = "0.12.1"

src/utils/Cargo.toml

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -9,17 +9,10 @@ license = "Apache-2.0"
99
bench = false
1010

1111
[dependencies]
12-
derive_more = { version = "1.0.0", default-features = false, features = ["from"] }
1312
displaydoc = "0.2.5"
1413
libc = "0.2.168"
1514
log-instrument = { path = "../log-instrument", optional = true }
16-
serde = { version = "1.0.215", features = ["derive"] }
1715
thiserror = "2.0.6"
18-
vm-memory = { version = "0.16.1", features = ["backend-mmap", "backend-bitmap"] }
19-
vmm-sys-util = "0.12.1"
20-
21-
[dev-dependencies]
22-
serde_json = "1.0.133"
2316

2417
[features]
2518
tracing = ["log-instrument"]

src/vmm/Cargo.toml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,6 @@ gdbstub = { version = "0.7.3", optional = true }
2424
gdbstub_arch = { version = "0.3.1", optional = true }
2525
kvm-bindings = { version = "0.10.0", features = ["fam-wrappers", "serde"] }
2626
kvm-ioctls = "0.19.1"
27-
lazy_static = "1.5.0"
2827
libc = "0.2.168"
2928
linux-loader = "0.13.0"
3029
log = { version = "0.4.22", features = ["std", "serde"] }

tests/framework/utils_vsock.py

Lines changed: 53 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@
1111
from subprocess import Popen
1212
from threading import Thread
1313

14+
from tenacity import Retrying, stop_after_attempt, wait_fixed
15+
1416
ECHO_SERVER_PORT = 5252
1517
SERVER_ACCEPT_BACKLOG = 128
1618
TEST_CONNECTION_COUNT = 50
@@ -142,53 +144,57 @@ def check_guest_connections(vm, server_port_path, blob_path, blob_hash):
142144
["socat", f"UNIX-LISTEN:{server_port_path},fork,backlog=5", "exec:'/bin/cat'"]
143145
)
144146

145-
# Link the listening Unix socket into the VM's jail, so that
146-
# Firecracker can connect to it.
147-
attempt = 0
148-
# But 1st, give socat a bit of time to create the socket
149-
while not Path(server_port_path).exists() and attempt < 3:
150-
time.sleep(0.2)
151-
attempt += 1
152-
vm.create_jailed_resource(server_port_path)
153-
154-
# Increase maximum process count for the ssh service.
155-
# Avoids: "bash: fork: retry: Resource temporarily unavailable"
156-
# Needed to execute the bash script that tests for concurrent
157-
# vsock guest initiated connections.
158-
pids_max_file = "/sys/fs/cgroup/system.slice/ssh.service/pids.max"
159-
ecode, _, _ = vm.ssh.run(f"echo 1024 > {pids_max_file}")
160-
assert ecode == 0, "Unable to set max process count for guest ssh service."
161-
162-
# Build the guest worker sub-command.
163-
# `vsock_helper` will read the blob file from STDIN and send the echo
164-
# server response to STDOUT. This response is then hashed, and the
165-
# hash is compared against `blob_hash` (computed on the host). This
166-
# comparison sets the exit status of the worker command.
167-
worker_cmd = "hash=$("
168-
worker_cmd += "cat {}".format(blob_path)
169-
worker_cmd += " | /tmp/vsock_helper echo 2 {}".format(ECHO_SERVER_PORT)
170-
worker_cmd += " | md5sum | cut -f1 -d\\ "
171-
worker_cmd += ")"
172-
worker_cmd += ' && [[ "$hash" = "{}" ]]'.format(blob_hash)
173-
174-
# Run `TEST_CONNECTION_COUNT` concurrent workers, using the above
175-
# worker sub-command.
176-
# If any worker fails, this command will fail. If all worker sub-commands
177-
# succeed, this will also succeed.
178-
cmd = 'workers="";'
179-
cmd += "for i in $(seq 1 {}); do".format(TEST_CONNECTION_COUNT)
180-
cmd += " ({})& ".format(worker_cmd)
181-
cmd += ' workers="$workers $!";'
182-
cmd += "done;"
183-
cmd += "for w in $workers; do wait $w || (wait; exit 1); done"
184-
185-
ecode, _, stderr = vm.ssh.run(cmd)
186-
echo_server.terminate()
187-
rc = echo_server.wait()
188-
# socat exits with 128 + 15 (SIGTERM)
189-
assert rc == 143
190-
191-
assert ecode == 0, stderr
147+
try:
148+
# Give socat a bit of time to create the socket
149+
for attempt in Retrying(
150+
wait=wait_fixed(0.2),
151+
stop=stop_after_attempt(3),
152+
reraise=True,
153+
):
154+
with attempt:
155+
assert Path(server_port_path).exists()
156+
157+
# Link the listening Unix socket into the VM's jail, so that
158+
# Firecracker can connect to it.
159+
vm.create_jailed_resource(server_port_path)
160+
161+
# Increase maximum process count for the ssh service.
162+
# Avoids: "bash: fork: retry: Resource temporarily unavailable"
163+
# Needed to execute the bash script that tests for concurrent
164+
# vsock guest initiated connections.
165+
vm.ssh.check_output(
166+
"echo 1024 > /sys/fs/cgroup/system.slice/ssh.service/pids.max"
167+
)
168+
169+
# Build the guest worker sub-command.
170+
# `vsock_helper` will read the blob file from STDIN and send the echo
171+
# server response to STDOUT. This response is then hashed, and the
172+
# hash is compared against `blob_hash` (computed on the host). This
173+
# comparison sets the exit status of the worker command.
174+
worker_cmd = "hash=$("
175+
worker_cmd += "cat {}".format(blob_path)
176+
worker_cmd += " | /tmp/vsock_helper echo 2 {}".format(ECHO_SERVER_PORT)
177+
worker_cmd += " | md5sum | cut -f1 -d\\ "
178+
worker_cmd += ")"
179+
worker_cmd += ' && [[ "$hash" = "{}" ]]'.format(blob_hash)
180+
181+
# Run `TEST_CONNECTION_COUNT` concurrent workers, using the above
182+
# worker sub-command.
183+
# If any worker fails, this command will fail. If all worker sub-commands
184+
# succeed, this will also succeed.
185+
cmd = 'workers="";'
186+
cmd += "for i in $(seq 1 {}); do".format(TEST_CONNECTION_COUNT)
187+
cmd += " ({})& ".format(worker_cmd)
188+
cmd += ' workers="$workers $!";'
189+
cmd += "done;"
190+
cmd += "for w in $workers; do wait $w || (wait; exit 1); done"
191+
192+
vm.ssh.check_output(cmd)
193+
finally:
194+
echo_server.terminate()
195+
rc = echo_server.wait()
196+
# socat exits with 128 + 15 (SIGTERM)
197+
assert rc == 143
192198

193199

194200
def make_host_port_path(uds_path, port):

tests/host_tools/cargo_build.py

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,18 +14,27 @@
1414
DEFAULT_TARGET_DIR = f"{DEFAULT_TARGET}/release/"
1515

1616

17+
def nightly_toolchain() -> str:
18+
"""Receives the name of the installed nightly toolchain"""
19+
return utils.check_output("rustup toolchain list | grep nightly").stdout.strip()
20+
21+
1722
def cargo(
1823
subcommand,
1924
cargo_args: str = "",
2025
subcommand_args: str = "",
2126
*,
2227
env: dict = None,
2328
cwd: str = None,
29+
nightly: bool = False,
2430
):
2531
"""Executes the specified cargo subcommand"""
32+
toolchain = f"+{nightly_toolchain()}" if nightly else ""
2633
env = env or {}
2734
env_string = " ".join(f'{key}="{str(value)}"' for key, value in env.items())
28-
cmd = f"{env_string} cargo {subcommand} {cargo_args} -- {subcommand_args}"
35+
cmd = (
36+
f"{env_string} cargo {toolchain} {subcommand} {cargo_args} -- {subcommand_args}"
37+
)
2938
return utils.check_output(cmd, cwd=cwd)
3039

3140

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
}
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
# Copyright 2024 Amazon.com, Inc. or its affiliates. All Rights Reserved.
2+
# SPDX-License-Identifier: Apache-2.0
3+
"""Enforces controls over dependencies."""
4+
5+
from host_tools.cargo_build import cargo
6+
7+
8+
def test_unused_dependencies():
9+
"""
10+
Test that there are no unused dependencies.
11+
"""
12+
cargo("udeps", "--all", nightly=True)

tests/integration_tests/functional/test_cpu_features_x86_64.py

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -314,7 +314,7 @@ def test_cpu_rdmsr(
314314
)
315315
vm.start()
316316
vm.ssh.scp_put(DATA_FILES / "msr_reader.sh", "/tmp/msr_reader.sh")
317-
_, stdout, stderr = vm.ssh.run("/tmp/msr_reader.sh")
317+
_, stdout, stderr = vm.ssh.run("/tmp/msr_reader.sh", timeout=None)
318318
assert stderr == ""
319319

320320
# Load results read from the microvm
@@ -362,7 +362,9 @@ def dump_msr_state_to_file(dump_fname, ssh_conn, shared_names):
362362
ssh_conn.scp_put(
363363
shared_names["msr_reader_host_fname"], shared_names["msr_reader_guest_fname"]
364364
)
365-
_, stdout, stderr = ssh_conn.run(shared_names["msr_reader_guest_fname"])
365+
_, stdout, stderr = ssh_conn.run(
366+
shared_names["msr_reader_guest_fname"], timeout=None
367+
)
366368
assert stderr == ""
367369

368370
with open(dump_fname, "w", encoding="UTF-8") as file:
@@ -416,7 +418,9 @@ def test_cpu_wrmsr_snapshot(microvm_factory, guest_kernel, rootfs, msr_cpu_templ
416418
wrmsr_input_guest_fname = "/tmp/wrmsr_input.txt"
417419
vm.ssh.scp_put(wrmsr_input_host_fname, wrmsr_input_guest_fname)
418420

419-
_, _, stderr = vm.ssh.run(f"{msr_writer_guest_fname} {wrmsr_input_guest_fname}")
421+
_, _, stderr = vm.ssh.run(
422+
f"{msr_writer_guest_fname} {wrmsr_input_guest_fname}", timeout=None
423+
)
420424
assert stderr == ""
421425

422426
# Dump MSR state to a file that will be published to S3 for the 2nd part of the test

0 commit comments

Comments
 (0)