From c235cb62beefd03087e7cfc7f7f55f0c7c6601c9 Mon Sep 17 00:00:00 2001 From: Lena Date: Sat, 1 Aug 2026 00:00:00 +0000 Subject: Enter vmm A QEMU/KVM virtual machine manager in one POSIX shell script. Each VM is a directory of plain files under $VMMDIR, configured by a hand-edited KEY=VALUE file that is parsed rather than sourced, so nothing in it can inject a raw QEMU argument. Control is a QMP FIFO pair inside that directory, guarded by its permissions alone; nothing binds a TCP port. The tests are TAP without a framework and boot real guests where the host allows. --- tests/net | 70 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 70 insertions(+) create mode 100644 tests/net (limited to 'tests/net') diff --git a/tests/net b/tests/net new file mode 100644 index 0000000..af979e5 --- /dev/null +++ b/tests/net @@ -0,0 +1,70 @@ +# What the guest's network looks like from the host. The argv tests say +# what vmm asked for; these say what the kernel then did with it. The +# guest is emulated, so this file needs no accelerator. +# +# /proc/net/tcp lists the local address as ADDRESS:PORT in hex, the +# address little endian, the port big endian, and state 0A is LISTEN. +# 127.0.0.1 is 0100007F and 0.0.0.0 is 00000000. + +port=18022 +hex=$(printf '%04X' "$port") + +"$VMM" create nt1 64M >/dev/null 2>&1 +cfg nt1 </dev/null 2>&1; then + skip 3 "nt1 did not start" +else + holds "the two field form really listens" \ + grep -qi ":$hex .* 0A " /proc/net/tcp + holds "and on 127.0.0.1, not on every interface" \ + grep -qi "0100007F:$hex " /proc/net/tcp + "$VMM" kill nt1 >/dev/null 2>&1 || : + holds "and stops listening once the guest is gone" \ + test -z "$(grep -i ":$hex .* 0A " /proc/net/tcp || :)" +fi + +cfg nt1 </dev/null 2>&1; then + skip 1 "nt1 did not start" +else + holds "an explicit address is bound as written" \ + grep -qi "00000000:$hex " /proc/net/tcp + "$VMM" kill nt1 >/dev/null 2>&1 || : +fi + +# Every file the guest leaves in its directory is 0600 as well, FIFOs +# included: the monitor is reachable by anyone who can write qmp.in. +cfg nt1 </dev/null 2>&1; then + # shellcheck disable=SC2012 # the names are vmm's own, not user input + bad=$(ls -l "$VMMDIR/nt1" | + awk '$1 ~ /^[-p]/ && $1 !~ /^[-p]rw-------$/ { print $NF }') + if [ -z "$bad" ]; then + ok "a running guest leaves every file 0600" + else + notok "a running guest leaves every file 0600" "$bad" + fi + "$VMM" kill nt1 >/dev/null 2>&1 || : +else + skip 1 "nt1 did not start" +fi -- cgit v1.2.3