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>
This commit is contained in:

committed by
Michael Ellerman

parent
2679f9bd0a
commit
31ed2b13c4
@@ -896,14 +896,24 @@ load_up_mmu:
|
||||
tophys(r6,r6)
|
||||
lwz r6,_SDR1@l(r6)
|
||||
mtspr SPRN_SDR1,r6
|
||||
li r0,16 /* load up segment register values */
|
||||
li r0, NUM_USER_SEGMENTS /* load up segment register values */
|
||||
mtctr r0 /* for context 0 */
|
||||
lis r3,0x2000 /* Ku = 1, VSID = 0 */
|
||||
#ifdef CONFIG_PPC_KUEP
|
||||
oris r3, r3, SR_NX@h /* Set Nx */
|
||||
#endif
|
||||
li r4,0
|
||||
3: mtsrin r3,r4
|
||||
addi r3,r3,0x111 /* increment VSID */
|
||||
addis r4,r4,0x1000 /* address of next segment */
|
||||
bdnz 3b
|
||||
li r0, 16 - NUM_USER_SEGMENTS /* load up kernel segment registers */
|
||||
mtctr r0 /* for context 0 */
|
||||
rlwinm r3, r3, 0, ~SR_NX /* Nx = 0 */
|
||||
3: mtsrin r3, r4
|
||||
addi r3, r3, 0x111 /* increment VSID */
|
||||
addis r4, r4, 0x1000 /* address of next segment */
|
||||
bdnz 3b
|
||||
|
||||
/* Load the BAT registers with the values set up by MMU_init.
|
||||
MMU_init takes care of whether we're on a 601 or not. */
|
||||
@@ -1007,6 +1017,9 @@ _ENTRY(switch_mmu_context)
|
||||
mulli r3,r3,897 /* multiply context by skew factor */
|
||||
rlwinm r3,r3,4,8,27 /* VSID = (context & 0xfffff) << 4 */
|
||||
addis r3,r3,0x6000 /* Set Ks, Ku bits */
|
||||
#ifdef CONFIG_PPC_KUEP
|
||||
oris r3, r3, SR_NX@h /* Set Nx */
|
||||
#endif
|
||||
li r0,NUM_USER_SEGMENTS
|
||||
mtctr r0
|
||||
|
||||
|
Reference in New Issue
Block a user