All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH ] powerpc/pkeys: Detach execute_only key on !PROT_EXEC
@ 2018-05-04 20:01 Ram Pai
  2018-05-22  1:42 ` Thiago Jung Bauermann
  2018-06-05 15:19 ` Michael Ellerman
  0 siblings, 2 replies; 3+ messages in thread
From: Ram Pai @ 2018-05-04 20:01 UTC (permalink / raw)
  To: mpe
  Cc: linuxppc-dev, benh, paulus, aneesh.kumar, bsingharora, hbabu,
	mhocko, bauerman, linuxram, msuchanek, Ulrich.Weigand,
	dave.hansen, Shakeel Butt

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.

cc: Shakeel Butt <shakeelb@google.com>
Reported-by: Shakeel Butt <shakeelb@google.com>
Fixes 5586cf6 ("powerpc: introduce execute-only pkey")
Signed-off-by: Ram Pai <linuxram@us.ibm.com>
---
 arch/powerpc/mm/pkeys.c |    4 ++--
 1 files changed, 2 insertions(+), 2 deletions(-)

diff --git a/arch/powerpc/mm/pkeys.c b/arch/powerpc/mm/pkeys.c
index e81d59e..fdeb9f5 100644
--- a/arch/powerpc/mm/pkeys.c
+++ b/arch/powerpc/mm/pkeys.c
@@ -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;
 
 	/*
-- 
1.7.1

^ permalink raw reply related	[flat|nested] 3+ messages in thread

* Re: [PATCH ] powerpc/pkeys: Detach execute_only key on !PROT_EXEC
  2018-05-04 20:01 [PATCH ] powerpc/pkeys: Detach execute_only key on !PROT_EXEC Ram Pai
@ 2018-05-22  1:42 ` Thiago Jung Bauermann
  2018-06-05 15:19 ` Michael Ellerman
  1 sibling, 0 replies; 3+ messages in thread
From: Thiago Jung Bauermann @ 2018-05-22  1:42 UTC (permalink / raw)
  To: Ram Pai
  Cc: mpe, linuxppc-dev, benh, paulus, aneesh.kumar, bsingharora,
	hbabu, mhocko, bauerman, msuchanek, Ulrich.Weigand, dave.hansen,
	Shakeel Butt


Ram Pai <linuxram@us.ibm.com> writes:

> 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.
>
> cc: Shakeel Butt <shakeelb@google.com>
> Reported-by: Shakeel Butt <shakeelb@google.com>
> Fixes 5586cf6 ("powerpc: introduce execute-only pkey")
       ^
         Missing a colon here.

> Signed-off-by: Ram Pai <linuxram@us.ibm.com>
> ---
>  arch/powerpc/mm/pkeys.c |    4 ++--
>  1 files changed, 2 insertions(+), 2 deletions(-)
>
> diff --git a/arch/powerpc/mm/pkeys.c b/arch/powerpc/mm/pkeys.c
> index e81d59e..fdeb9f5 100644
> --- a/arch/powerpc/mm/pkeys.c
> +++ b/arch/powerpc/mm/pkeys.c
> @@ -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;
>
>  	/*

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.

Reviewed-by: Thiago Jung Bauermann <bauerman@linux.ibm.com>

--
Thiago Jung Bauermann
IBM Linux Technology Center

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: powerpc/pkeys: Detach execute_only key on !PROT_EXEC
  2018-05-04 20:01 [PATCH ] powerpc/pkeys: Detach execute_only key on !PROT_EXEC Ram Pai
  2018-05-22  1:42 ` Thiago Jung Bauermann
@ 2018-06-05 15:19 ` Michael Ellerman
  1 sibling, 0 replies; 3+ messages in thread
From: Michael Ellerman @ 2018-06-05 15:19 UTC (permalink / raw)
  To: Ram Pai
  Cc: dave.hansen, msuchanek, Ulrich.Weigand, linuxram, mhocko, paulus,
	aneesh.kumar, bauerman, Shakeel Butt, linuxppc-dev

On Fri, 2018-05-04 at 20:01:51 UTC, Ram Pai wrote:
> 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.
> 
> cc: Shakeel Butt <shakeelb@google.com>
> Reported-by: Shakeel Butt <shakeelb@google.com>
> Fixes 5586cf6 ("powerpc: introduce execute-only pkey")
> Signed-off-by: Ram Pai <linuxram@us.ibm.com>
> Reviewed-by: Thiago Jung Bauermann <bauerman@linux.ibm.com>

Applied to powerpc next, thanks.

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

cheers

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2018-06-05 15:19 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2018-05-04 20:01 [PATCH ] powerpc/pkeys: Detach execute_only key on !PROT_EXEC Ram Pai
2018-05-22  1:42 ` Thiago Jung Bauermann
2018-06-05 15:19 ` Michael Ellerman

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.