Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

powerpc/book3s64/kuap: Improve error reporting with KUAP

With hash translation use DSISR_KEYFAULT to identify a wrong access.
With Radix we look at the AMR value and type of fault.

Signed-off-by: Aneesh Kumar K.V <aneesh.kumar@linux.ibm.com>
Signed-off-by: Michael Ellerman <mpe@ellerman.id.au>
Link: https://lore.kernel.org/r/20201127044424.40686-17-aneesh.kumar@linux.ibm.com

authored by

Aneesh Kumar K.V and committed by
Michael Ellerman
eb232b16 4d6c551e

+29 -12
+2 -2
arch/powerpc/include/asm/book3s/32/kup.h
··· 177 177 allow_user_access(to, to, end - addr, KUAP_READ_WRITE); 178 178 } 179 179 180 - static inline bool 181 - bad_kuap_fault(struct pt_regs *regs, unsigned long address, bool is_write) 180 + static inline bool bad_kuap_fault(struct pt_regs *regs, unsigned long address, 181 + bool is_write, unsigned long error_code) 182 182 { 183 183 unsigned long begin = regs->kuap & 0xf0000000; 184 184 unsigned long end = regs->kuap << 28;
+22 -5
arch/powerpc/include/asm/book3s/64/kup.h
··· 303 303 isync(); 304 304 } 305 305 306 - static inline bool 307 - bad_kuap_fault(struct pt_regs *regs, unsigned long address, bool is_write) 306 + #define RADIX_KUAP_BLOCK_READ UL(0x4000000000000000) 307 + #define RADIX_KUAP_BLOCK_WRITE UL(0x8000000000000000) 308 + 309 + static inline bool bad_kuap_fault(struct pt_regs *regs, unsigned long address, 310 + bool is_write, unsigned long error_code) 308 311 { 309 - return WARN(mmu_has_feature(MMU_FTR_BOOK3S_KUAP) && 310 - (regs->kuap & (is_write ? AMR_KUAP_BLOCK_WRITE : AMR_KUAP_BLOCK_READ)), 311 - "Bug: %s fault blocked by AMR!", is_write ? "Write" : "Read"); 312 + if (!mmu_has_feature(MMU_FTR_BOOK3S_KUAP)) 313 + return false; 314 + 315 + if (radix_enabled()) { 316 + /* 317 + * Will be a storage protection fault. 318 + * Only check the details of AMR[0] 319 + */ 320 + return WARN((regs->kuap & (is_write ? RADIX_KUAP_BLOCK_WRITE : RADIX_KUAP_BLOCK_READ)), 321 + "Bug: %s fault blocked by AMR!", is_write ? "Write" : "Read"); 322 + } 323 + /* 324 + * We don't want to WARN here because userspace can setup 325 + * keys such that a kernel access to user address can cause 326 + * fault 327 + */ 328 + return !!(error_code & DSISR_KEYFAULT); 312 329 } 313 330 314 331 static __always_inline void allow_user_access(void __user *to, const void __user *from,
+2 -2
arch/powerpc/include/asm/kup.h
··· 59 59 #else 60 60 static inline void setup_kuap(bool disabled) { } 61 61 62 - static inline bool 63 - bad_kuap_fault(struct pt_regs *regs, unsigned long address, bool is_write) 62 + static inline bool bad_kuap_fault(struct pt_regs *regs, unsigned long address, 63 + bool is_write, unsigned long error_code) 64 64 { 65 65 return false; 66 66 }
+2 -2
arch/powerpc/include/asm/nohash/32/kup-8xx.h
··· 60 60 mtspr(SPRN_MD_AP, flags); 61 61 } 62 62 63 - static inline bool 64 - bad_kuap_fault(struct pt_regs *regs, unsigned long address, bool is_write) 63 + static inline bool bad_kuap_fault(struct pt_regs *regs, unsigned long address, 64 + bool is_write, unsigned long error_code) 65 65 { 66 66 return WARN(!((regs->kuap ^ MD_APG_KUAP) & 0xff000000), 67 67 "Bug: fault blocked by AP register !");
+1 -1
arch/powerpc/mm/fault.c
··· 227 227 228 228 // Read/write fault in a valid region (the exception table search passed 229 229 // above), but blocked by KUAP is bad, it can never succeed. 230 - if (bad_kuap_fault(regs, address, is_write)) 230 + if (bad_kuap_fault(regs, address, is_write, error_code)) 231 231 return true; 232 232 233 233 // What's left? Kernel fault on user in well defined regions (extable