[PATCH v4 27/41] powerpc/book3s64/pkeys: Reset userspace AMR correctly on exec
From: Aneesh Kumar K.V <hidden>
Date: 2020-06-15 07:09:17
Subsystem:
linux for powerpc (32-bit and 64-bit), the rest · Maintainers:
Madhavan Srinivasan, Linus Torvalds
On fork, we inherit from the parent and on exec, we should switch to default_amr values. Also, avoid changing the AMR register value within the kernel. The kernel now runs with different AMR values. Signed-off-by: Aneesh Kumar K.V <redacted> --- arch/powerpc/include/asm/book3s/64/kup.h | 2 ++ arch/powerpc/kernel/process.c | 6 +++++- arch/powerpc/mm/book3s64/pkeys.c | 18 ++---------------- 3 files changed, 9 insertions(+), 17 deletions(-)
diff --git a/arch/powerpc/include/asm/book3s/64/kup.h b/arch/powerpc/include/asm/book3s/64/kup.h
index 49182efea945..23d6f212d39c 100644
--- a/arch/powerpc/include/asm/book3s/64/kup.h
+++ b/arch/powerpc/include/asm/book3s/64/kup.h@@ -171,6 +171,8 @@ #include <asm/ptrace.h> extern u64 default_uamor; +extern u64 default_amr; +extern u64 default_iamr; static inline void kuap_restore_user_amr(struct pt_regs *regs) {
diff --git a/arch/powerpc/kernel/process.c b/arch/powerpc/kernel/process.c
index dbce0b1daf2f..340e473e8738 100644
--- a/arch/powerpc/kernel/process.c
+++ b/arch/powerpc/kernel/process.c@@ -1485,6 +1485,11 @@ void arch_setup_new_exec(void) current->thread.regs = regs - 1; } +#ifdef CONFIG_PPC_MEM_KEYS + current->thread.regs->kuap = default_amr; + current->thread.regs->kuep = default_iamr; +#endif + } #else void arch_setup_new_exec(void)
@@ -1839,7 +1844,6 @@ void start_thread(struct pt_regs *regs, unsigned long start, unsigned long sp) current->thread.load_tm = 0; #endif /* CONFIG_PPC_TRANSACTIONAL_MEM */ - thread_pkey_regs_init(¤t->thread); } EXPORT_SYMBOL(start_thread);
diff --git a/arch/powerpc/mm/book3s64/pkeys.c b/arch/powerpc/mm/book3s64/pkeys.c
index 7980b013d161..95e972d6bbfa 100644
--- a/arch/powerpc/mm/book3s64/pkeys.c
+++ b/arch/powerpc/mm/book3s64/pkeys.c@@ -21,8 +21,8 @@ int max_pkey; /* Maximum key value supported */ */ u32 reserved_allocation_mask; static u32 initial_allocation_mask; /* Bits set for the initially allocated keys */ -static u64 default_amr; -static u64 default_iamr; +u64 default_amr; +u64 default_iamr; /* Allow all keys to be modified by default */ u64 default_uamor = ~0x0UL; /*
@@ -388,20 +388,6 @@ void thread_pkey_regs_restore(struct thread_struct *new_thread, write_uamor(new_thread->uamor); } -void thread_pkey_regs_init(struct thread_struct *thread) -{ - if (!mmu_has_feature(MMU_FTR_PKEY)) - return; - - thread->amr = default_amr; - thread->iamr = default_iamr; - thread->uamor = default_uamor; - - write_amr(default_amr); - write_iamr(default_iamr); - write_uamor(default_uamor); -} - int execute_only_pkey(struct mm_struct *mm) { if (static_branch_likely(&execute_pkey_disabled))
--
2.26.2