Skip to content

Commit 00dbdf7

Browse files
committed
tests/vm: mount debugfs and dump the page-table ground truth
The init mounted proc, sysfs, devtmpfs and tmpfs but not debugfs, so a debugfs-sourced component saw the interface as absent rather than present. Mount debugfs where CONFIG_DEBUG_FS is built in; the call fails harmlessly otherwise. Alongside the kallsyms _text/_stext truth, dump as root the page-table high-kernel-mapping region and the first kmemleak objects, so a run carries the landmarks the debugfs components recover and cross-checks them against the kernel's own _text.
1 parent 11f9e3f commit 00dbdf7

1 file changed

Lines changed: 51 additions & 0 deletions

File tree

tests/vm/init.c

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -226,6 +226,55 @@ static const char *const region_syms[] = {"page_offset_base", "vmalloc_base",
226226
* 0x<value>" line per region that resolves; nothing where kcore/the symbols are
227227
* absent. Emitted alongside the kallsyms/iomem truth so tests/vm/run can gate
228228
* each region's resolved window the same way it gates the text base. */
229+
/* Dump the debugfs page-table walk's kernel-image region, as root, where
230+
* CONFIG_PTDUMP_DEBUGFS is built in. The first MAPPED run of the "High Kernel
231+
* Mapping" region begins at _text — the landmark ptdump_kernel_page_tables
232+
* recovers; an unmapped gap (no protection flags) precedes it. Bounded so a
233+
* large walk cannot flood the log. Absent/unreadable prints one line. */
234+
static void dump_page_tables_hkm(void) {
235+
printf("=== page-table dump: High Kernel Mapping "
236+
"(/sys/kernel/debug/page_tables/kernel) ===\n");
237+
FILE *f = fopen("/sys/kernel/debug/page_tables/kernel", "r");
238+
if (!f) {
239+
printf(" <absent or unreadable>\n");
240+
return;
241+
}
242+
char line[512];
243+
int in = 0, n = 0;
244+
while (fgets(line, sizeof line, f)) {
245+
if (strstr(line, "---[")) {
246+
in = strstr(line, "High Kernel Mapping") != NULL;
247+
if (!in && n)
248+
break;
249+
if (in)
250+
fputs(line, stdout);
251+
continue;
252+
}
253+
if (in && n++ < 20)
254+
fputs(line, stdout);
255+
}
256+
fclose(f);
257+
}
258+
259+
/* Dump the first few kmemleak object lines, as root. Empty on a system with no
260+
* currently-unreferenced objects (the common case on a clean boot). */
261+
static void dump_kmemleak_objects(void) {
262+
printf("=== kmemleak objects (/sys/kernel/debug/kmemleak) ===\n");
263+
FILE *f = fopen("/sys/kernel/debug/kmemleak", "r");
264+
if (!f) {
265+
printf(" <absent or unreadable>\n");
266+
return;
267+
}
268+
char line[1024];
269+
int n = 0;
270+
while (fgets(line, sizeof line, f))
271+
if (strstr(line, "unreferenced object") && n++ < 8)
272+
fputs(line, stdout);
273+
if (!n)
274+
printf(" <no leaked objects reported>\n");
275+
fclose(f);
276+
}
277+
229278
static void dump_region_kaslr_truth(void) {
230279
printf("=== region kaslr truth (/proc/kcore) ===\n");
231280
int any = 0;
@@ -653,6 +702,8 @@ int main(void) {
653702
dump_bpf_kfunc_offsets();
654703
dump_iomem_kernel();
655704
dump_region_kaslr_truth();
705+
dump_page_tables_hkm();
706+
dump_kmemleak_objects();
656707
printf("=== presence probes ===\n");
657708
printf("/sys/firmware/efi: %d /proc/device-tree: %d "
658709
"/proc/device-tree/chosen/kaslr-seed: %d\n",

0 commit comments

Comments
 (0)