-
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/8xx: Add Kernel Userspace Access Protection
This patch adds Kernel Userspace Access Protection on the 8xx. When a page is RO or RW, it is set RO or RW for Key 0 and NA for Key 1. Up to now, the User group is defined with Key 0 for both User and Supervisor. By changing the group to Key 0 for User and Key 1 for Supervisor, this patch prevents the Kernel from being able to access user data. At exception entry, the kernel saves SPRN_MD_AP in the regs struct, and reapply the protection. At exception exit it restores SPRN_MD_AP with the value saved on exception entry. Signed-off-by: Christophe Leroy <christophe.leroy@c-s.fr> [mpe: Drop allow_read/write_to/from_user() as they're now in kup.h] Signed-off-by: Michael Ellerman <mpe@ellerman.id.au>
- Loading branch information
Christophe Leroy
authored and
Michael Ellerman
committed
Apr 21, 2019
1 parent
06fbe81
commit 2679f9b
Showing
5 changed files
with
81 additions
and
0 deletions.
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
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,58 @@ | ||
/* SPDX-License-Identifier: GPL-2.0 */ | ||
#ifndef _ASM_POWERPC_KUP_8XX_H_ | ||
#define _ASM_POWERPC_KUP_8XX_H_ | ||
|
||
#include <asm/bug.h> | ||
|
||
#ifdef CONFIG_PPC_KUAP | ||
|
||
#ifdef __ASSEMBLY__ | ||
|
||
.macro kuap_save_and_lock sp, thread, gpr1, gpr2, gpr3 | ||
lis \gpr2, MD_APG_KUAP@h /* only APG0 and APG1 are used */ | ||
mfspr \gpr1, SPRN_MD_AP | ||
mtspr SPRN_MD_AP, \gpr2 | ||
stw \gpr1, STACK_REGS_KUAP(\sp) | ||
.endm | ||
|
||
.macro kuap_restore sp, current, gpr1, gpr2, gpr3 | ||
lwz \gpr1, STACK_REGS_KUAP(\sp) | ||
mtspr SPRN_MD_AP, \gpr1 | ||
.endm | ||
|
||
.macro kuap_check current, gpr | ||
#ifdef CONFIG_PPC_KUAP_DEBUG | ||
mfspr \gpr, SPRN_MD_AP | ||
rlwinm \gpr, \gpr, 16, 0xffff | ||
999: twnei \gpr, MD_APG_KUAP@h | ||
EMIT_BUG_ENTRY 999b, __FILE__, __LINE__, (BUGFLAG_WARNING | BUGFLAG_ONCE) | ||
#endif | ||
.endm | ||
|
||
#else /* !__ASSEMBLY__ */ | ||
|
||
#include <asm/reg.h> | ||
|
||
static inline void allow_user_access(void __user *to, const void __user *from, | ||
unsigned long size) | ||
{ | ||
mtspr(SPRN_MD_AP, MD_APG_INIT); | ||
} | ||
|
||
static inline void prevent_user_access(void __user *to, const void __user *from, | ||
unsigned long size) | ||
{ | ||
mtspr(SPRN_MD_AP, MD_APG_KUAP); | ||
} | ||
|
||
static inline bool bad_kuap_fault(struct pt_regs *regs, bool is_write) | ||
{ | ||
return WARN(!((regs->kuap ^ MD_APG_KUAP) & 0xf0000000), | ||
"Bug: fault blocked by AP register !"); | ||
} | ||
|
||
#endif /* !__ASSEMBLY__ */ | ||
|
||
#endif /* CONFIG_PPC_KUAP */ | ||
|
||
#endif /* _ASM_POWERPC_KUP_8XX_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