-
Notifications
You must be signed in to change notification settings - Fork 52
Expand file tree
/
Copy pathdmesg_fake_numa_init.c
More file actions
104 lines (93 loc) · 3.61 KB
/
Copy pathdmesg_fake_numa_init.c
File metadata and controls
104 lines (93 loc) · 3.61 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
// This file is part of KASLD - https://github.com/bcoles/kasld
//
// fake_numa_init() / dummy_numa_init() prints memblock_start_of_DRAM()
// physical address of the first memblock to dmesg on systems which do not
// support Non-Uniform Memory Access (NUMA).
//
// On systems with a known phys->virt offset mapping, this may be used to
// identify the kernel virtual address region used for direct mapping.
//
// NUMA support may be disabled in BIOS or via Linux kernel command line with
// the `acpi=off` flag. Systems without Advanced Configuration and Power
// Interface (ACPI) do not support NUMA.
//
// Leak primitive:
// Data leaked: physical DRAM base address (memblock_start_of_DRAM)
// Kernel subsystem: mm/numa, arch/x86/mm/numa — dummy_numa_init()
// Data structure: memblock_start_of_DRAM() return value (physical address)
// Address type: physical (DRAM)
// Method: parsed (dmesg string)
// Status: unfixed (printed unconditionally on non-NUMA systems)
// Access check: do_syslog() → check_syslog_permissions(); gated by
// dmesg_restrict
// Source:
// https://elixir.bootlin.com/linux/v6.2-rc3/source/arch/x86/mm/numa.c#L709
//
// Mitigations:
// Access gated by dmesg_restrict (see dmesg.h for shared access gate
// details). Only printed on systems without NUMA support. On decoupled
// architectures, physical addresses cannot derive the virtual text base.
//
// Requires:
// - kernel.dmesg_restrict = 0; or CAP_SYSLOG capabilities; or
// readable /var/log/dmesg.
//
// References:
// https://cateee.net/lkddb/web-lkddb/NUMA.html
// https://elixir.bootlin.com/linux/v6.2-rc3/source/drivers/base/arch_numa.c#L429
// https://elixir.bootlin.com/linux/v6.2-rc3/source/arch/x86/mm/numa.c#L709
// https://elixir.bootlin.com/linux/v6.2-rc3/source/arch/loongarch/kernel/numa.c#L401
// https://elixir.bootlin.com/linux/v6.2-rc3/source/mm/memblock.c#L1663
// ---
// <bcoles@gmail.com>
#define _GNU_SOURCE
#include "include/dmesg.h"
#include "include/kasld/api.h"
#include "include/kasld/cli.h"
#include <stdint.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
KASLD_EXPLAIN(
"Searches dmesg for fake_numa_init() or dummy_numa_init() messages "
"that print memblock_start_of_DRAM() on non-NUMA systems. This "
"reveals the physical base address of system RAM. Access is gated "
"by dmesg_restrict.");
KASLD_META("method:parsed\n"
"phase:inference\n"
"discloses:physical\n"
"sysctl:dmesg_restrict>=1\n"
"bypass:CAP_SYSLOG\n"
"fallback:/var/log/dmesg\n");
static int on_match(const char *line, void *ctx) {
unsigned long *result = ctx;
/* NUMA: Faking a node at [mem 0x0000000080200000-0x00000000bfffffff] */
const char *p = strstr(line, " [mem ");
if (!p)
return 1;
unsigned long addr;
if (kasld_addr_parse(p + 5, 16, &addr, NULL) && addr &&
addr < KERNEL_VIRT_VAS_END) {
*result = addr;
return 0;
}
return 1;
}
int main(void) {
unsigned long addr = 0;
kasld_info("searching dmesg for fake_numa_init() info ...");
int ds = dmesg_search("NUMA: Faking a node at", on_match, &addr);
if (!addr) {
if (ds < 0)
return KASLD_EXIT_NOPERM;
kasld_err("fake_numa_init info not found in dmesg");
return 0;
}
/* "Faking a node at [mem ...]" prints the start of the synthetic node's
* memory range — equivalent to the bottom of usable RAM on single-node
* systems. */
kasld_found("leaked faked NUMA NODE #0 physical address: 0x%016lx", addr);
kasld_result_base(KASLD_TYPE_PHYS, REGION_RAM, addr, NULL, CONF_PARSED);
return 0;
}