Skip to contentSkip to conversation

powerpc/pkeys: Detach execute_only key on !PROT_EXEC

PATCH Applied Ram Pai 3 participants 3 messages May 4, 2018 – Jun 5, 2018 PowerPC

lore
Share & tools
lore

Ram Pai

author
#0 lore raw

PATCH 1/1 powerpc/pkeys: Detach execute_only key on !PROT_EXEC

Disassociate the exec_key from a VMA if the VMA permission is not PROT_EXEC anymore. Otherwise the exec_only key continues to be associated with the vma, causing unexpected behavior.

The problem was reported on x86 by Shakeel Butt,
which is also applicable on powerpc.

Fixes 5586cf6 ("powerpc: introduce execute-only pkey")

---
 arch/powerpc/mm/pkeys.c |    4 ++--
 1 files changed, 2 insertions(+), 2 deletions(-)
arch/powerpc/mm/pkeys.c +2 -2
index e81d59e..fdeb9f5 100644
@@ -425,9 +425,9 @@ int __arch_override_mprotect_pkey(struct vm_area_struct *vma, int prot,
 {
 	/*
 	 * If the currently associated pkey is execute-only, but the requested
-	 * protection requires read or write, move it back to the default pkey.
+	 * protection is not execute-only, move it back to the default pkey.
 	 */
-	if (vma_is_pkey_exec_only(vma) && (prot & (PROT_READ | PROT_WRITE)))
+	if (vma_is_pkey_exec_only(vma) && (prot != PROT_EXEC))
 		return 0;
 
 	/*
Signature · 1 line
1.7.1
Reviewed-by on v1 1/1
#1 lore raw
Quoted 10 lines · Ram Pai

Disassociate the exec_key from a VMA if the VMA permission is not PROT_EXEC anymore. Otherwise the exec_only key continues to be associated with the vma, causing unexpected behavior.

The problem was reported on x86 by Shakeel Butt,
which is also applicable on powerpc.

Fixes 5586cf6 ("powerpc: introduce execute-only pkey")

^
Missing a colon here.

Quoted 11 lines
---
 arch/powerpc/mm/pkeys.c |    4 ++--
 1 files changed, 2 insertions(+), 2 deletions(-)
arch/powerpc/mm/pkeys.c +0 -0
index e81d59e..fdeb9f5 100644
@@ -425,9 +425,9 @@ int __arch_override_mprotect_pkey(struct vm_area_struct *vma, int prot,
 {

arch/powerpc/mm/pkeys.c int __arch_override_mprotect_pkey(struct vm_area_struct *vma, int prot, · line 433

Quoted 10 lines
arch/powerpc/mm/pkeys.c +2 -2
 	/*
 	 * If the currently associated pkey is execute-only, but the requested
-	 * protection requires read or write, move it back to the default pkey.
+	 * protection is not execute-only, move it back to the default pkey.
 	 */
-	if (vma_is_pkey_exec_only(vma) && (prot & (PROT_READ | PROT_WRITE)))
+	if (vma_is_pkey_exec_only(vma) && (prot != PROT_EXEC))
 		return 0;
 
 	/*

I think I'm slow today. It took me a while to figure out why this is buggy. It will leave the VMA with the execute-only pkey if prot = 0. Other bit combinations work fine IIUC.

--
Thiago Jung Bauermann
IBM Linux Technology Center

#2 lore raw
In reply to Ram Pai
Quoted 4 lines · Ram Pai

Disassociate the exec_key from a VMA if the VMA permission is not PROT_EXEC anymore. Otherwise the exec_only key continues to be associated with the vma, causing unexpected behavior.

Quoted 8 lines

The problem was reported on x86 by Shakeel Butt,
which is also applicable on powerpc.

Fixes 5586cf6 ("powerpc: introduce execute-only pkey")

Applied to powerpc next, thanks.

https://git.kernel.org/powerpc/c/eabdb8ca8690eedd461e61ea778059

cheers