Skip to content

Commit 764baba

Browse files
committed
x86_64: Fix ktext mapping if it starts above 0xffffffffa0000000
When all of kernel text is relocated beyond the pre-kASLR highest virtual address, the scan for region end is not even attempted. If the kernel text start address is found above LINUX_KTEXT_END_NOKASLR, unconditionally scan for the region end up to LINUX_KTEXT_END. The corresponding test case is derived from a real-world dump. Signed-off-by: Petr Tesarik <[email protected]>
1 parent 4cb7d32 commit 764baba

6 files changed

+75
-3
lines changed

src/addrxlat/x86_64.c

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -541,9 +541,10 @@ linux_ktext_extents(struct os_init_data *ctl,
541541

542542
linearoff = ctl->sys->meth[ADDRXLAT_SYS_METH_KTEXT].param.linear.off;
543543
*high = *low;
544-
status = highest_linear(&step, high, LINUX_KTEXT_END_NOKASLR,
545-
linearoff);
546-
if (status == ADDRXLAT_OK && *high == LINUX_KTEXT_END_NOKASLR) {
544+
if (*high <= LINUX_KTEXT_END_NOKASLR)
545+
status = highest_linear(&step, high, LINUX_KTEXT_END_NOKASLR,
546+
linearoff);
547+
if (status == ADDRXLAT_OK && *high >= LINUX_KTEXT_END_NOKASLR) {
547548
++*high;
548549
status = highest_linear(&step, high, LINUX_KTEXT_END,
549550
linearoff);

tests/Makefile.am

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -297,6 +297,7 @@ test_scripts = \
297297
xlat-linux-x86_64-ktext-40M \
298298
xlat-linux-x86_64-ktext-512M \
299299
xlat-linux-x86_64-ktext-520M \
300+
xlat-linux-x86_64-ktext-54M-kaslr \
300301
xlat-linux-x86_64-old \
301302
xlat-linux-x86_64-old-nover \
302303
xlat-linux-x86_64-2.6.11 \
@@ -479,6 +480,9 @@ dist_check_DATA = \
479480
xlat-linux-x86_64-ktext-520M.data \
480481
xlat-linux-x86_64-ktext-520M.expect \
481482
xlat-linux-x86_64-ktext-520M.sym \
483+
xlat-linux-x86_64-ktext-54M-kaslr.data \
484+
xlat-linux-x86_64-ktext-54M-kaslr.expect \
485+
xlat-linux-x86_64-ktext-54M-kaslr.sym \
482486
xlat-linux-x86_64-old.expect \
483487
xlat-linux-x86_64-old-nover.data \
484488
xlat-linux-x86_64-old-nover.expect \
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
#! /bin/bash
2+
3+
#
4+
# Check Linux X86_64 translation with a 54M kASLR ktext mapping starting
5+
# above the fixed (non-kASLR) virtual address region.
6+
#
7+
8+
opts=(
9+
arch=x86_64
10+
ostype=linux
11+
phys_base=0x23c00000
12+
)
13+
14+
. "$srcdir"/xlat-os-common
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
# kernel text
2+
@0x4c610ff8
3+
000000004c615067
4+
@0x4c615ff0
5+
000000004c616063
6+
@0x4c616000
7+
0000000000000000*313
8+
000000004ae001e1*27+200000
9+
0000000000000000*172
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
@rootpgt: PGT
2+
target_as=MACHPHYSADDR
3+
root=KVADDR:0xffffffffa8a10000
4+
pte_mask=0x0
5+
pte_format=x86_64
6+
fields=12,9,9,9,9
7+
8+
@ktext: LINEAR
9+
target_as=KPHYSADDR
10+
off=0xa3c00000
11+
12+
@machphys_kphys: LINEAR
13+
target_as=KPHYSADDR
14+
off=0x0
15+
16+
@kphys_machphys: LINEAR
17+
target_as=MACHPHYSADDR
18+
off=0x0
19+
20+
KV -> HW:
21+
0-7fffffffffff: @rootpgt
22+
800000000000-ffff7fffffffffff: NONE
23+
ffff800000000000-ffffffffffffffff: @rootpgt
24+
25+
KV -> PHYS:
26+
0-7fffffffffff: @rootpgt
27+
800000000000-ffff7fffffffffff: NONE
28+
ffff800000000000-ffffffffa71fffff: @rootpgt
29+
ffffffffa7200000-ffffffffaa7fffff: @ktext
30+
ffffffffaa800000-ffffffffffffffff: @rootpgt
31+
32+
KPHYS -> DIRECT:
33+
34+
MACHPHYS -> KPHYS:
35+
0-fffffffffffff: @machphys_kphys
36+
10000000000000-ffffffffffffffff: NONE
37+
38+
KPHYS -> MACHPHYS:
39+
0-fffffffffffff: @kphys_machphys
40+
10000000000000-ffffffffffffffff: NONE
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
@VALUE(init_top_pgt)
2+
ffffffffa8a10000
3+
@VALUE(_stext)
4+
ffffffffa7200000

0 commit comments

Comments
 (0)