summaryrefslogtreecommitdiff
path: root/arch/powerpc/mm/pkeys.c
diff options
context:
space:
mode:
authorRam Pai <linuxram@us.ibm.com>2018-12-20 12:03:30 -0800
committerMichael Ellerman <mpe@ellerman.id.au>2018-12-21 14:46:50 +1100
commit2cd4bd192ee94848695c1c052d87913260e10f36 (patch)
tree196e1d7a1fb878dae550092bc739c5ac5e4318db /arch/powerpc/mm/pkeys.c
parent2f07229f02d4c55affccd11a61af4fd4b94dc436 (diff)
powerpc/pkeys: Fix handling of pkey state across fork()
Protection key tracking information is not copied over to the mm_struct of the child during fork(). This can cause the child to erroneously allocate keys that were already allocated. Any allocated execute-only key is lost aswell. Add code; called by dup_mmap(), to copy the pkey state from parent to child explicitly. This problem was originally found by Dave Hansen on x86, which turns out to be a problem on powerpc aswell. Fixes: cf43d3b26452 ("powerpc: Enable pkey subsystem") Cc: stable@vger.kernel.org # v4.16+ Reviewed-by: Thiago Jung Bauermann <bauerman@linux.ibm.com> Signed-off-by: Ram Pai <linuxram@us.ibm.com> Signed-off-by: Michael Ellerman <mpe@ellerman.id.au>
Diffstat (limited to 'arch/powerpc/mm/pkeys.c')
-rw-r--r--arch/powerpc/mm/pkeys.c10
1 files changed, 10 insertions, 0 deletions
diff --git a/arch/powerpc/mm/pkeys.c b/arch/powerpc/mm/pkeys.c
index 04b60a8f6e69..587807763737 100644
--- a/arch/powerpc/mm/pkeys.c
+++ b/arch/powerpc/mm/pkeys.c
@@ -415,3 +415,13 @@ bool arch_vma_access_permitted(struct vm_area_struct *vma, bool write,
return pkey_access_permitted(vma_pkey(vma), write, execute);
}
+
+void arch_dup_pkeys(struct mm_struct *oldmm, struct mm_struct *mm)
+{
+ if (static_branch_likely(&pkey_disabled))
+ return;
+
+ /* Duplicate the oldmm pkey state in mm: */
+ mm_pkey_allocation_map(mm) = mm_pkey_allocation_map(oldmm);
+ mm->context.execute_only_pkey = oldmm->context.execute_only_pkey;
+}