-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
powerpc/32s: Implement Kernel Userspace Execution Prevention.
To implement Kernel Userspace Execution Prevention, this patch sets NX bit on all user segments on kernel entry and clears NX bit on all user segments on kernel exit. Note that powerpc 601 doesn't have the NX bit, so KUEP will not work on it. A warning is displayed at startup. Signed-off-by: Christophe Leroy <christophe.leroy@c-s.fr> Signed-off-by: Michael Ellerman <mpe@ellerman.id.au>
- Loading branch information
Christophe Leroy
authored and
Michael Ellerman
committed
Apr 21, 2019
1 parent
2679f9b
commit 31ed2b1
Showing
7 changed files
with
85 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
/* SPDX-License-Identifier: GPL-2.0 */ | ||
#ifndef _ASM_POWERPC_BOOK3S_32_KUP_H | ||
#define _ASM_POWERPC_BOOK3S_32_KUP_H | ||
|
||
#include <asm/book3s/32/mmu-hash.h> | ||
|
||
#ifdef __ASSEMBLY__ | ||
|
||
.macro kuep_update_sr gpr1, gpr2 /* NEVER use r0 as gpr2 due to addis */ | ||
101: mtsrin \gpr1, \gpr2 | ||
addi \gpr1, \gpr1, 0x111 /* next VSID */ | ||
rlwinm \gpr1, \gpr1, 0, 0xf0ffffff /* clear VSID overflow */ | ||
addis \gpr2, \gpr2, 0x1000 /* address of next segment */ | ||
bdnz 101b | ||
isync | ||
.endm | ||
|
||
.macro kuep_lock gpr1, gpr2 | ||
#ifdef CONFIG_PPC_KUEP | ||
li \gpr1, NUM_USER_SEGMENTS | ||
li \gpr2, 0 | ||
mtctr \gpr1 | ||
mfsrin \gpr1, \gpr2 | ||
oris \gpr1, \gpr1, SR_NX@h /* set Nx */ | ||
kuep_update_sr \gpr1, \gpr2 | ||
#endif | ||
.endm | ||
|
||
.macro kuep_unlock gpr1, gpr2 | ||
#ifdef CONFIG_PPC_KUEP | ||
li \gpr1, NUM_USER_SEGMENTS | ||
li \gpr2, 0 | ||
mtctr \gpr1 | ||
mfsrin \gpr1, \gpr2 | ||
rlwinm \gpr1, \gpr1, 0, ~SR_NX /* Clear Nx */ | ||
kuep_update_sr \gpr1, \gpr2 | ||
#endif | ||
.endm | ||
|
||
#endif /* __ASSEMBLY__ */ | ||
|
||
#endif /* _ASM_POWERPC_BOOK3S_32_KUP_H */ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters