Skip to content

Commit

Permalink
powerpc/book3s64/kuap: Restrict access to userspace based on userspac…
Browse files Browse the repository at this point in the history
…e 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
  • Loading branch information
Aneesh Kumar K.V authored and Michael Ellerman committed Dec 3, 2020
1 parent 48a8ab4 commit 4d6c551
Showing 1 changed file with 9 additions and 3 deletions.
12 changes: 9 additions & 3 deletions arch/powerpc/include/asm/book3s/64/kup.h
Original file line number Diff line number Diff line change
Expand Up @@ -314,14 +314,20 @@ bad_kuap_fault(struct pt_regs *regs, unsigned long address, bool is_write)
static __always_inline void allow_user_access(void __user *to, const void __user *from,
unsigned long size, unsigned long dir)
{
unsigned long thread_amr = 0;

// This is written so we can resolve to a single case at build time
BUILD_BUG_ON(!__builtin_constant_p(dir));

if (mmu_has_feature(MMU_FTR_PKEY))
thread_amr = current_thread_amr();

if (dir == KUAP_READ)
set_kuap(AMR_KUAP_BLOCK_WRITE);
set_kuap(thread_amr | AMR_KUAP_BLOCK_WRITE);
else if (dir == KUAP_WRITE)
set_kuap(AMR_KUAP_BLOCK_READ);
set_kuap(thread_amr | AMR_KUAP_BLOCK_READ);
else if (dir == KUAP_READ_WRITE)
set_kuap(0);
set_kuap(thread_amr);
else
BUILD_BUG();
}
Expand Down

0 comments on commit 4d6c551

Please sign in to comment.