Skip to content

Commit 4d6c551

Browse files
kvaneeshmpe
authored andcommitted
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 <[email protected]> Reviewed-by: Sandipan Das <[email protected]> Signed-off-by: Michael Ellerman <[email protected]> Link: https://lore.kernel.org/r/[email protected]
1 parent 48a8ab4 commit 4d6c551

File tree

1 file changed

+9
-3
lines changed
  • arch/powerpc/include/asm/book3s/64

1 file changed

+9
-3
lines changed

arch/powerpc/include/asm/book3s/64/kup.h

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -314,14 +314,20 @@ bad_kuap_fault(struct pt_regs *regs, unsigned long address, bool is_write)
314314
static __always_inline void allow_user_access(void __user *to, const void __user *from,
315315
unsigned long size, unsigned long dir)
316316
{
317+
unsigned long thread_amr = 0;
318+
317319
// This is written so we can resolve to a single case at build time
318320
BUILD_BUG_ON(!__builtin_constant_p(dir));
321+
322+
if (mmu_has_feature(MMU_FTR_PKEY))
323+
thread_amr = current_thread_amr();
324+
319325
if (dir == KUAP_READ)
320-
set_kuap(AMR_KUAP_BLOCK_WRITE);
326+
set_kuap(thread_amr | AMR_KUAP_BLOCK_WRITE);
321327
else if (dir == KUAP_WRITE)
322-
set_kuap(AMR_KUAP_BLOCK_READ);
328+
set_kuap(thread_amr | AMR_KUAP_BLOCK_READ);
323329
else if (dir == KUAP_READ_WRITE)
324-
set_kuap(0);
330+
set_kuap(thread_amr);
325331
else
326332
BUILD_BUG();
327333
}

0 commit comments

Comments
 (0)