Skip to content

Commit 3ec1f9d

Browse files
committed
tests/vm: add stock profile and a vanilla x86_64 reference kernel
`stock`: an unprivileged user (uid 1000) on an out-of-the-box kernel — every sysctl left at its kernel default (kptr_restrict=0, dmesg_restrict=0, perf_event_paranoid=2), neither weakened (unlike `default`) nor hardened. `x86_64-vanilla`: a vanilla upstream-defconfig x86_64 from the pinned kernel.org source, kept out of the default build set and staged under its own name so it never shadows the Alpine matrix kernel. Together they produce reproducible documentation samples from a neutral kernel at default settings.
1 parent 474145c commit 3ec1f9d

4 files changed

Lines changed: 31 additions & 7 deletions

File tree

tests/vm/README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,7 @@ it is wider but still contains the truth — the correct outcome under restricti
5858
| `default` | root, `kptr_restrict=0` | the easy case — kallsyms readable |
5959
| `hide` | root, `kptr_restrict=2` | the pin must come from inference |
6060
| `hardened` | uid 1000, `kptr=2` + `dmesg_restrict=1` + `perf=3` | the realistic unprivileged floor (file-derived facts only) |
61+
| `stock` | uid 1000, kernel-default sysctls (`kptr=0`, `dmesg_restrict=0`, `perf=2`) | an unprivileged user on an out-of-the-box kernel — nothing weakened or hardened |
6162
| `nokaslr` | `nokaslr` on the cmdline | the KASLR-disabled pin |
6263

6364
## Architectures

tests/vm/build-kernel

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -37,11 +37,13 @@ LINUX_VERSION=${LINUX_VERSION:-6.15.6}
3737
LINUX_MIRROR=${LINUX_MIRROR:-https://cdn.kernel.org/pub/linux/kernel}
3838
JOBS=${JOBS:-$(nproc 2>/dev/null || echo 1)}
3939

40-
# Default build set: the gap arches that boot and validate here. armeb has a spec
41-
# (below) but is excluded — the cross set's only big-endian arm toolchain is ARMv5
42-
# BE32, which can neither run on an ARMv7 BE8 kernel nor boot a BE32 kernel under
43-
# qemu; building it would stage a kernel `tests/vm/run` cannot validate. Build it
44-
# explicitly (`build-kernel armeb`) if a BE8-capable armv7 toolchain is added.
40+
# Default build set: the gap arches that boot and validate here. Two specs below
41+
# are excluded from the default and built only on request:
42+
# armeb — the cross set's only big-endian arm toolchain is ARMv5 BE32,
43+
# which can neither run on an ARMv7 BE8 kernel nor boot a BE32
44+
# kernel under qemu, so the staged kernel cannot be validated.
45+
# x86_64-vanilla — Alpine already ships x86_64; this is a neutral upstream build
46+
# for reference/documentation, not a gap to fill.
4547
ALL_ARCHES="mips mipsel riscv32 ppc32"
4648

4749
# arch -> "tc-prefix kernel-ARCH defconfig image endian"
@@ -55,6 +57,10 @@ spec_for() {
5557
riscv32) echo "riscv32 riscv rv32_defconfig Image -" ;;
5658
ppc32) echo "powerpc powerpc pmac32_defconfig vmlinux -" ;;
5759
armeb) echo "armeb arm multi_v7_defconfig zImage be" ;;
60+
# Not a gap arch — Alpine ships x86_64. This is a vanilla upstream-defconfig
61+
# x86_64 kept for a neutral reference build (e.g. documentation samples),
62+
# staged under its own name so it never shadows the Alpine matrix kernel.
63+
x86_64-vanilla) echo "x86_64 x86 x86_64_defconfig bzImage -" ;;
5864
*) echo "" ;;
5965
esac
6066
}

tests/vm/init.c

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -153,8 +153,12 @@ int main(void) {
153153
* inference (exercises the engine, not the kallsyms shortcut).
154154
* hardened — drop to uid 1000 with kptr_restrict=2, dmesg_restrict=1,
155155
* perf_event_paranoid=3: the realistic unprivileged-attacker
156-
* floor, where only file-derived facts survive. */
157-
int hide = 0, hardened = 0;
156+
* floor, where only file-derived facts survive.
157+
* stock — drop to uid 1000 but leave every sysctl at its kernel default
158+
* (kptr_restrict=0, dmesg_restrict=0, perf_event_paranoid=2):
159+
* an unprivileged user on an out-of-the-box kernel, neither
160+
* weakened nor hardened by us. */
161+
int hide = 0, hardened = 0, stock = 0;
158162
{
159163
int cf = open("/proc/cmdline", O_RDONLY);
160164
char cb[512];
@@ -167,6 +171,8 @@ int main(void) {
167171
hide = 1;
168172
if (strstr(cb, "hardened"))
169173
hardened = 1;
174+
if (strstr(cb, "stock"))
175+
stock = 1;
170176
}
171177
close(cf);
172178
}
@@ -203,6 +209,15 @@ int main(void) {
203209
} else if (hide) {
204210
write_file("/proc/sys/kernel/kptr_restrict", "2\n");
205211
printf("=== profile: hide — root, kptr_restrict=2 (no kallsyms) ===\n");
212+
} else if (stock) {
213+
/* Kernel-default sysctls, nothing weakened or hardened by us: vanilla
214+
* defaults are kptr_restrict=0, dmesg_restrict=0, perf_event_paranoid=2.
215+
* Reset perf from the -1 used for the ground-truth dump; leave kptr and
216+
* dmesg at their defaults. Run unprivileged. */
217+
write_file("/proc/sys/kernel/perf_event_paranoid", "2\n");
218+
uid = 1000;
219+
printf("=== profile: stock — uid=1000, kernel-default sysctls "
220+
"(kptr_restrict=0, dmesg_restrict=0, perf_event_paranoid=2) ===\n");
206221
} else {
207222
printf("=== profile: default — root, kptr_restrict=0 ===\n");
208223
}

tests/vm/run

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,7 @@ mipsel | - | local| mipsel | mipsel | -M malta
7272
riscv32 | - | local| riscv32 | riscv32 | -M virt | ttyS0
7373
ppc32 | - | local| powerpc | ppc | -M g3beige | ttyS0
7474
armeb | - | local| armeb | arm | -M virt | ttyAMA0
75+
x86_64-vanilla | - | local| x86_64 | x86_64 | -M q35 -cpu max | ttyS0
7576
'
7677

7778
trim() { echo "$1" | xargs; }
@@ -254,6 +255,7 @@ EOF
254255
default) ;;
255256
hide) append="$append hidekptr" ;;
256257
hardened) append="$append hardened" ;;
258+
stock) append="$append stock" ;;
257259
nokaslr) append="$append nokaslr" ;;
258260
*) echo " unknown mode: $mode"; return 2 ;;
259261
esac

0 commit comments

Comments
 (0)