linuxppc-dev.lists.ozlabs.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] powerpc/ptrace: Use copy_{from, to}_user() rather than open-coding
@ 2018-05-29 12:57 Michael Ellerman
  2018-05-30  6:48 ` Samuel Mendoza-Jonas
  2018-06-04 14:11 ` Michael Ellerman
  0 siblings, 2 replies; 3+ messages in thread
From: Michael Ellerman @ 2018-05-29 12:57 UTC (permalink / raw)
  To: linuxppc-dev, viro; +Cc: malat

From: Al Viro <viro@ZenIV.linux.org.uk>

In PPC_PTRACE_GETHWDBGINFO and PPC_PTRACE_SETHWDEBUG we do an
access_ok() check and then __copy_{from,to}_user().

Instead we should just use copy_{from,to}_user() which does all that
for us and is less error prone.

Signed-off-by: Al Viro <viro@zeniv.linux.org.uk>
Signed-off-by: Michael Ellerman <mpe@ellerman.id.au>
---
 arch/powerpc/kernel/ptrace.c | 20 ++++++--------------
 1 file changed, 6 insertions(+), 14 deletions(-)

diff --git a/arch/powerpc/kernel/ptrace.c b/arch/powerpc/kernel/ptrace.c
index 0f63dd5972e9..9667666eb18e 100644
--- a/arch/powerpc/kernel/ptrace.c
+++ b/arch/powerpc/kernel/ptrace.c
@@ -3082,27 +3082,19 @@ long arch_ptrace(struct task_struct *child, long request,
 #endif /* CONFIG_HAVE_HW_BREAKPOINT */
 #endif /* CONFIG_PPC_ADV_DEBUG_REGS */
 
-		if (!access_ok(VERIFY_WRITE, datavp,
-			       sizeof(struct ppc_debug_info)))
+		if (copy_to_user(datavp, &dbginfo,
+				 sizeof(struct ppc_debug_info)))
 			return -EFAULT;
-		ret = __copy_to_user(datavp, &dbginfo,
-				     sizeof(struct ppc_debug_info)) ?
-		      -EFAULT : 0;
-		break;
+		return 0;
 	}
 
 	case PPC_PTRACE_SETHWDEBUG: {
 		struct ppc_hw_breakpoint bp_info;
 
-		if (!access_ok(VERIFY_READ, datavp,
-			       sizeof(struct ppc_hw_breakpoint)))
+		if (copy_from_user(&bp_info, datavp,
+				   sizeof(struct ppc_hw_breakpoint)))
 			return -EFAULT;
-		ret = __copy_from_user(&bp_info, datavp,
-				       sizeof(struct ppc_hw_breakpoint)) ?
-		      -EFAULT : 0;
-		if (!ret)
-			ret = ppc_set_hwdebug(child, &bp_info);
-		break;
+		return ppc_set_hwdebug(child, &bp_info);
 	}
 
 	case PPC_PTRACE_DELHWDEBUG: {
-- 
2.14.1

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

* Re: [PATCH] powerpc/ptrace: Use copy_{from, to}_user() rather than open-coding
  2018-05-29 12:57 [PATCH] powerpc/ptrace: Use copy_{from, to}_user() rather than open-coding Michael Ellerman
@ 2018-05-30  6:48 ` Samuel Mendoza-Jonas
  2018-06-04 14:11 ` Michael Ellerman
  1 sibling, 0 replies; 3+ messages in thread
From: Samuel Mendoza-Jonas @ 2018-05-30  6:48 UTC (permalink / raw)
  To: Michael Ellerman, linuxppc-dev, viro; +Cc: malat

On Tue, 2018-05-29 at 22:57 +1000, Michael Ellerman wrote:
> From: Al Viro <viro@ZenIV.linux.org.uk>
> 
> In PPC_PTRACE_GETHWDBGINFO and PPC_PTRACE_SETHWDEBUG we do an
> access_ok() check and then __copy_{from,to}_user().
> 
> Instead we should just use copy_{from,to}_user() which does all that
> for us and is less error prone.
> 
> Signed-off-by: Al Viro <viro@zeniv.linux.org.uk>
> Signed-off-by: Michael Ellerman <mpe@ellerman.id.au>

Reviewed-by: Samuel Mendoza-Jonas <sam@mendozajonas.com>

> ---
>  arch/powerpc/kernel/ptrace.c | 20 ++++++--------------
>  1 file changed, 6 insertions(+), 14 deletions(-)
> 
> diff --git a/arch/powerpc/kernel/ptrace.c b/arch/powerpc/kernel/ptrace.c
> index 0f63dd5972e9..9667666eb18e 100644
> --- a/arch/powerpc/kernel/ptrace.c
> +++ b/arch/powerpc/kernel/ptrace.c
> @@ -3082,27 +3082,19 @@ long arch_ptrace(struct task_struct *child, long request,
>  #endif /* CONFIG_HAVE_HW_BREAKPOINT */
>  #endif /* CONFIG_PPC_ADV_DEBUG_REGS */
>  
> -		if (!access_ok(VERIFY_WRITE, datavp,
> -			       sizeof(struct ppc_debug_info)))
> +		if (copy_to_user(datavp, &dbginfo,
> +				 sizeof(struct ppc_debug_info)))
>  			return -EFAULT;
> -		ret = __copy_to_user(datavp, &dbginfo,
> -				     sizeof(struct ppc_debug_info)) ?
> -		      -EFAULT : 0;
> -		break;
> +		return 0;
>  	}
>  
>  	case PPC_PTRACE_SETHWDEBUG: {
>  		struct ppc_hw_breakpoint bp_info;
>  
> -		if (!access_ok(VERIFY_READ, datavp,
> -			       sizeof(struct ppc_hw_breakpoint)))
> +		if (copy_from_user(&bp_info, datavp,
> +				   sizeof(struct ppc_hw_breakpoint)))
>  			return -EFAULT;
> -		ret = __copy_from_user(&bp_info, datavp,
> -				       sizeof(struct ppc_hw_breakpoint)) ?
> -		      -EFAULT : 0;
> -		if (!ret)
> -			ret = ppc_set_hwdebug(child, &bp_info);
> -		break;
> +		return ppc_set_hwdebug(child, &bp_info);
>  	}
>  
>  	case PPC_PTRACE_DELHWDEBUG: {

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

* Re: powerpc/ptrace: Use copy_{from, to}_user() rather than open-coding
  2018-05-29 12:57 [PATCH] powerpc/ptrace: Use copy_{from, to}_user() rather than open-coding Michael Ellerman
  2018-05-30  6:48 ` Samuel Mendoza-Jonas
@ 2018-06-04 14:11 ` Michael Ellerman
  1 sibling, 0 replies; 3+ messages in thread
From: Michael Ellerman @ 2018-06-04 14:11 UTC (permalink / raw)
  To: Michael Ellerman, linuxppc-dev, viro; +Cc: malat

On Tue, 2018-05-29 at 12:57:38 UTC, Michael Ellerman wrote:
> From: Al Viro <viro@ZenIV.linux.org.uk>
> 
> In PPC_PTRACE_GETHWDBGINFO and PPC_PTRACE_SETHWDEBUG we do an
> access_ok() check and then __copy_{from,to}_user().
> 
> Instead we should just use copy_{from,to}_user() which does all that
> for us and is less error prone.
> 
> Signed-off-by: Al Viro <viro@zeniv.linux.org.uk>
> Signed-off-by: Michael Ellerman <mpe@ellerman.id.au>
> Reviewed-by: Samuel Mendoza-Jonas <sam@mendozajonas.com>

Applied to powerpc next.

https://git.kernel.org/powerpc/c/6bcdd2972b9f6ebda9ae5c7075e2d5

cheers

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

end of thread, other threads:[~2018-06-04 14:11 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2018-05-29 12:57 [PATCH] powerpc/ptrace: Use copy_{from, to}_user() rather than open-coding Michael Ellerman
2018-05-30  6:48 ` Samuel Mendoza-Jonas
2018-06-04 14:11 ` Michael Ellerman

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).