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: Restrict access to userspace based on userspace AMR

If an application has configured address protection such that read/write is
denied using pkey even the kernel should receive a FAULT on accessing the same.

This patch use user AMR value stored in pt_regs.amr to achieve the same.

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

authored by

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

+9 -3
+9 -3
arch/powerpc/include/asm/book3s/64/kup.h
··· 314 314 static __always_inline void allow_user_access(void __user *to, const void __user *from, 315 315 unsigned long size, unsigned long dir) 316 316 { 317 + unsigned long thread_amr = 0; 318 + 317 319 // This is written so we can resolve to a single case at build time 318 320 BUILD_BUG_ON(!__builtin_constant_p(dir)); 321 + 322 + if (mmu_has_feature(MMU_FTR_PKEY)) 323 + thread_amr = current_thread_amr(); 324 + 319 325 if (dir == KUAP_READ) 320 - set_kuap(AMR_KUAP_BLOCK_WRITE); 326 + set_kuap(thread_amr | AMR_KUAP_BLOCK_WRITE); 321 327 else if (dir == KUAP_WRITE) 322 - set_kuap(AMR_KUAP_BLOCK_READ); 328 + set_kuap(thread_amr | AMR_KUAP_BLOCK_READ); 323 329 else if (dir == KUAP_READ_WRITE) 324 - set_kuap(0); 330 + set_kuap(thread_amr); 325 331 else 326 332 BUILD_BUG(); 327 333 }