Skip to content

Commit 359fbd0

Browse files
committed
tests/vm: add a tracefs-open profile for the tracing-group vantage
The tracefs components read /sys/kernel/tracing tables, but the VM init never mounts tracefs, so both read UNAVAILABLE in every profile and the vantage went unexercised. The tracefsopen profile mounts tracefs gid=1000,mode=755 — traversable and group-readable by the unprivileged uid the analysis runs as — and sets kptr_restrict=2, modeling a host that grants a tracing group tracefs access while hardening kallsyms. There the tracefs address tables recover the text base with no kptr_restrict gate. Every other profile leaves tracefs unmounted, so the default and hardened floors are unchanged.
1 parent a1d8902 commit 359fbd0

1 file changed

Lines changed: 25 additions & 1 deletion

File tree

tests/vm/init.c

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -589,7 +589,7 @@ int main(void) {
589589
* (default restores booted). `capture` mode (below) reconstructs a fixture
590590
* and never reaches this. */
591591
int hidden = 0, hardened = 0, perfopen = 0, dmesgopen = 0, bpfopen = 0,
592-
capture = 0;
592+
tracefsopen = 0, capture = 0;
593593
{
594594
int cf = open("/proc/cmdline", O_RDONLY);
595595
char cb[512];
@@ -608,6 +608,8 @@ int main(void) {
608608
dmesgopen = 1;
609609
if (strstr(cb, "bpfopen"))
610610
bpfopen = 1;
611+
if (strstr(cb, "tracefsopen"))
612+
tracefsopen = 1;
611613
if (strstr(cb, "capture"))
612614
capture = 1;
613615
}
@@ -717,6 +719,17 @@ int main(void) {
717719
printf("=== profile: bpf-open — uid=1000, unprivileged_bpf_disabled=0, "
718720
"kptr_restrict=%s perf_event_paranoid=%s (booted) ===\n",
719721
b_kptr, b_perf);
722+
} else if (tracefsopen) {
723+
/* kallsyms hidden (kptr=2) but tracefs group-readable (mounted gid=1000
724+
* below): the tracefs address tables carry no kptr_restrict gate, so they
725+
* recover the text base where /proc/kallsyms is masked. The "tracing group"
726+
* vantage (Android AID_READTRACEFS). */
727+
write_file("/proc/sys/kernel/kptr_restrict", "2\n");
728+
write_file("/proc/sys/kernel/perf_event_paranoid", b_perf);
729+
printf("=== profile: tracefs-open — uid=1000, kptr_restrict=2, "
730+
"tracefs gid=1000 (dmesg_restrict=%s perf_event_paranoid=%s "
731+
"booted) ===\n",
732+
b_dmesg, b_perf);
720733
} else if (hidden) {
721734
write_file("/proc/sys/kernel/kptr_restrict", "2\n");
722735
write_file("/proc/sys/kernel/perf_event_paranoid", b_perf);
@@ -732,6 +745,17 @@ int main(void) {
732745
}
733746
fflush(stdout);
734747

748+
/* tracefs-open vantage only: mount tracefs group-readable by the unprivileged
749+
* uid so the tracefs components (printk_formats,
750+
* available_filter_functions_addrs) read the address tables without root —
751+
* the "tracing group" (Android AID_READTRACEFS) scenario. Done as root here,
752+
* before run_as drops to uid 1000. gid=1000,mode=755 makes the tree
753+
* traversable and leaves the 0440 tables group-readable; a no-op on kernels
754+
* built without tracing (the mountpoint is absent). Other profiles never
755+
* mount it, so those components stay UNAVAILABLE there. */
756+
if (tracefsopen)
757+
mount("tracefs", "/sys/kernel/tracing", "tracefs", 0, "gid=1000,mode=755");
758+
735759
/* Run kasld in JSON mode — tests/vm/run reads the window from the -j output,
736760
* and the ground-truth dump above supplies the comparison value. */
737761
char *av_j[] = {"/kasld", "-j", NULL};

0 commit comments

Comments
 (0)