-
Notifications
You must be signed in to change notification settings - Fork 52
Expand file tree
/
Copy pathdmesg_android_ion_snapshot.c
More file actions
99 lines (88 loc) · 3.01 KB
/
Copy pathdmesg_android_ion_snapshot.c
File metadata and controls
99 lines (88 loc) · 3.01 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
// This file is part of KASLD - https://github.com/bcoles/kasld
//
// Search kernel log for Android ION ion_snapshot map message which
// prints last_ion_buf symbol address:
//
// ion_snapshot: 0x7e9d0000 map to 0xe0907000 and copy to 0xc0e5d374
//
// Android ION drivers were removed in kernel v5.11-rc1.
//
// Leak primitive:
// Data leaked: kernel symbol address (last_ion_buf) and virtual mapping
// Kernel subsystem: drivers/staging/android/ion — ion_snapshot()
// Data structure: ion_snapshot map address (kernel virtual pointer)
// Address type: virtual
// Method: parsed (dmesg string)
// Status: removed in v5.11 (Android ION subsystem deleted)
// Access check: do_syslog() → check_syslog_permissions(); gated by
// dmesg_restrict
// Source:
// https://elixir.bootlin.com/linux/v5.10.89/source/drivers/staging/android/ion
//
// Mitigations:
// Android ION was removed in v5.11. Access gated by dmesg_restrict
// (see dmesg.h for shared access gate details).
//
// Requires:
// - kernel.dmesg_restrict = 0; or CAP_SYSLOG capabilities; or
// readable /var/log/dmesg.
//
// References:
// https://lwn.net/Articles/576966/
// https://lwn.net/Articles/565469/
// https://lwn.net/Articles/480055/
// https://elixir.bootlin.com/linux/v5.10.89/source/drivers/staging/android/ion
// ---
// <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 Android ION ion_snapshot messages that print "
"the last_ion_buf symbol virtual address. The ION memory allocator "
"was removed from mainline in v5.11. Access is gated by "
"dmesg_restrict.");
KASLD_META("method:parsed\n"
"phase:inference\n"
"discloses:virtual\n"
"sysctl:dmesg_restrict>=1\n"
"patch:v5.11\n"
"bypass:CAP_SYSLOG\n"
"fallback:/var/log/dmesg\n");
static int on_match(const char *line, void *ctx) {
unsigned long *result = ctx;
const char *needle2 = "and copy to 0x";
/* ion_snapshot: 0x7e9d0000 map to 0xe0907000 and copy to 0xc0e5d374 */
const char *p = strstr(line, needle2);
if (!p)
return 1;
unsigned long addr;
if (kasld_addr_parse(p + strlen(needle2), 16, &addr, NULL) &&
kasld_addr_is_kernel_text(addr)) {
*result = addr;
return 0;
}
return 1;
}
int main(void) {
unsigned long addr = 0;
kasld_info("searching dmesg for 'ion_snapshot: ' ...");
int ds = dmesg_search("ion_snapshot: ", on_match, &addr);
if (!addr) {
if (ds < 0)
return KASLD_EXIT_NOPERM;
kasld_err("ion_snapshot not found in dmesg");
return 0;
}
kasld_found("leaked last_ion_buf: %lx", addr);
kasld_result_sample(KASLD_TYPE_VIRT, REGION_KERNEL_TEXT, addr, "last_ion_buf",
CONF_PARSED);
kasld_info("possible kernel base: %lx", kasld_floor_text_base(addr));
return 0;
}