Skip to content

Commit 82f8d54

Browse files
author
Marc Zyngier
committed
Merge branch kvm-arm64/mmu/kmemleak-pkvm into kvmarm-master/next
Prevent kmemleak from peeking into the HYP data, which is fatal in protected mode. * kvm-arm64/mmu/kmemleak-pkvm: KVM: arm64: Unregister HYP sections from kmemleak in protected mode arm64: Move .hyp.rodata outside of the _sdata.._edata range Signed-off-by: Marc Zyngier <[email protected]>
2 parents 3ce5db8 + 47e6223 commit 82f8d54

File tree

2 files changed

+9
-2
lines changed

2 files changed

+9
-2
lines changed

arch/arm64/kernel/vmlinux.lds.S

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -181,6 +181,8 @@ SECTIONS
181181
/* everything from this point to __init_begin will be marked RO NX */
182182
RO_DATA(PAGE_SIZE)
183183

184+
HYPERVISOR_DATA_SECTIONS
185+
184186
idmap_pg_dir = .;
185187
. += IDMAP_DIR_SIZE;
186188
idmap_pg_end = .;
@@ -260,8 +262,6 @@ SECTIONS
260262
_sdata = .;
261263
RW_DATA(L1_CACHE_BYTES, PAGE_SIZE, THREAD_ALIGN)
262264

263-
HYPERVISOR_DATA_SECTIONS
264-
265265
/*
266266
* Data written with the MMU off but read with the MMU on requires
267267
* cache lines to be invalidated, discarding up to a Cache Writeback

arch/arm64/kvm/arm.c

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
#include <linux/fs.h>
1616
#include <linux/mman.h>
1717
#include <linux/sched.h>
18+
#include <linux/kmemleak.h>
1819
#include <linux/kvm.h>
1920
#include <linux/kvm_irqfd.h>
2021
#include <linux/irqbypass.h>
@@ -1973,6 +1974,12 @@ static int finalize_hyp_mode(void)
19731974
if (ret)
19741975
return ret;
19751976

1977+
/*
1978+
* Exclude HYP BSS from kmemleak so that it doesn't get peeked
1979+
* at, which would end badly once the section is inaccessible.
1980+
* None of other sections should ever be introspected.
1981+
*/
1982+
kmemleak_free_part(__hyp_bss_start, __hyp_bss_end - __hyp_bss_start);
19761983
ret = pkvm_mark_hyp_section(__hyp_bss);
19771984
if (ret)
19781985
return ret;

0 commit comments

Comments
 (0)