-
Notifications
You must be signed in to change notification settings - Fork 52
Expand file tree
/
Copy pathdmesg_check_for_initrd.c
More file actions
93 lines (82 loc) · 2.97 KB
/
Copy pathdmesg_check_for_initrd.c
File metadata and controls
93 lines (82 loc) · 2.97 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
// This file is part of KASLD - https://github.com/bcoles/kasld
//
// check_for_initrd() prints initrd start address during boot:
// https://elixir.bootlin.com/linux/v6.1.1/source/arch/powerpc/kernel/setup-common.c#L385
//
// ppc64:
// [ 0.000000] Found initrd at 0xc000000001a00000:0xc000000002a26000
//
// Leak primitive:
// Data leaked: initrd physical/virtual load address
// Kernel subsystem: arch/powerpc/kernel — check_for_initrd()
// Data structure: initrd_start / initrd_end (kernel virtual addresses)
// Address type: virtual (kernel direct-map, ppc64)
// Method: parsed (dmesg string)
// Status: unfixed (boot message printed unconditionally)
// Access check: do_syslog() → check_syslog_permissions(); gated by
// dmesg_restrict
// Source:
// https://elixir.bootlin.com/linux/v6.1.1/source/arch/powerpc/kernel/setup-common.c#L385
//
// Mitigations:
// CONFIG_BLK_DEV_INITRD=n prevents the message. Access gated by
// dmesg_restrict (see dmesg.h for shared access gate details).
//
// Requires:
// - CONFIG_BLK_DEV_INITRD=y
// - kernel.dmesg_restrict = 0; or CAP_SYSLOG capabilities; or
// readable /var/log/dmesg.
//
// References:
// https://elixir.bootlin.com/linux/v6.1.1/source/arch/powerpc/kernel/setup-common.c#L385
// ---
// <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 the PowerPC check_for_initrd() message that "
"prints the initrd start virtual address. On ppc64, this is a "
"direct-map (linear map) virtual address that reveals the kernel "
"PAGE_OFFSET. Access is gated by dmesg_restrict.");
KASLD_META("method:parsed\n"
"phase:inference\n"
"discloses:virtual\n"
"sysctl:dmesg_restrict>=1\n"
"bypass:CAP_SYSLOG\n"
"fallback:/var/log/dmesg\n"
"config:CONFIG_BLK_DEV_INITRD\n");
static const char *needle = "Found initrd at 0x";
static int on_match(const char *line, void *ctx) {
unsigned long *result = ctx;
const char *p = strstr(line, needle);
if (!p)
return 1;
unsigned long addr;
if (kasld_addr_parse(p + strlen(needle), 16, &addr, NULL) && addr &&
addr < KERNEL_VIRT_VAS_END) {
*result = addr;
return 0; /* stop after first match */
}
return 1;
}
int main(void) {
unsigned long addr = 0;
kasld_info("searching dmesg for check_for_initrd() info ...");
int ds = dmesg_search(needle, on_match, &addr);
if (!addr) {
if (ds < 0)
return KASLD_EXIT_NOPERM;
kasld_err("check_for_initrd info not found in dmesg");
return 0;
}
kasld_found("leaked initrd start: %lx", addr);
kasld_info("possible kernel base: %lx", kasld_floor_text_base(addr));
kasld_result_sample(KASLD_TYPE_VIRT, REGION_INITRD, addr, NULL, CONF_PARSED);
return 0;
}