2018-05-27 22:34:32

by Al Viro

[permalink] [raw]
Subject: [PATCH][RFC] [powerpc] arch_ptrace() uses of access_ok() are pointless

make it use copy_{from,to}_user(), rather than access_ok() +
__copy_...

Signed-off-by: Al Viro <[email protected]>
---
arch/powerpc/kernel/ptrace.c | 22 +++++++---------------
1 file changed, 7 insertions(+), 15 deletions(-)

diff --git a/arch/powerpc/kernel/ptrace.c b/arch/powerpc/kernel/ptrace.c
index d23cf632edf0..d8b0fd2fa3aa 100644
--- a/arch/powerpc/kernel/ptrace.c
+++ b/arch/powerpc/kernel/ptrace.c
@@ -3081,27 +3081,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 (unlikely(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)))
- 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;
+ if (unlikely(copy_from_user(&bp_info, datavp,
+ sizeof(struct ppc_hw_breakpoint)))
+ return -EFAULT;
+ return ppc_set_hwdebug(child, &bp_info);
}

case PPC_PTRACE_DELHWDEBUG: {
--
2.11.0



2018-05-29 03:50:33

by Mathieu Malaterre

[permalink] [raw]
Subject: Re: [PATCH][RFC] [powerpc] arch_ptrace() uses of access_ok() are pointless

On Mon, May 28, 2018 at 12:34 AM, Al Viro <[email protected]> wrote:
> make it use copy_{from,to}_user(), rather than access_ok() +
> __copy_...
>
> Signed-off-by: Al Viro <[email protected]>
> ---
> arch/powerpc/kernel/ptrace.c | 22 +++++++---------------
> 1 file changed, 7 insertions(+), 15 deletions(-)
>
> diff --git a/arch/powerpc/kernel/ptrace.c b/arch/powerpc/kernel/ptrace.c
> index d23cf632edf0..d8b0fd2fa3aa 100644
> --- a/arch/powerpc/kernel/ptrace.c
> +++ b/arch/powerpc/kernel/ptrace.c
> @@ -3081,27 +3081,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 (unlikely(copy_to_user(datavp, &dbginfo,
> + sizeof(struct ppc_debug_info)))


Maybe this is just an RFC, but:

CALL ../arch/powerpc/kernel/systbl_chk.sh
../arch/powerpc/kernel/ptrace.c: In function ‘arch_ptrace’:
../arch/powerpc/kernel/ptrace.c:3086:4: error: expected ‘)’ before ‘return’
return -EFAULT;
^~~~~~

Missing closing parenthesis.

> 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)))
> - 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;
> + if (unlikely(copy_from_user(&bp_info, datavp,
> + sizeof(struct ppc_hw_breakpoint)))
> + return -EFAULT;
> + return ppc_set_hwdebug(child, &bp_info);
> }
>
> case PPC_PTRACE_DELHWDEBUG: {
> --
> 2.11.0
>

2018-05-29 03:52:05

by Al Viro

[permalink] [raw]
Subject: Re: [PATCH][RFC] [powerpc] arch_ptrace() uses of access_ok() are pointless


> Maybe this is just an RFC, but:
>
> CALL ../arch/powerpc/kernel/systbl_chk.sh
> ../arch/powerpc/kernel/ptrace.c: In function ‘arch_ptrace’:
> ../arch/powerpc/kernel/ptrace.c:3086:4: error: expected ‘)’ before ‘return’
> return -EFAULT;
> ^~~~~~

and the same a few lines later. What's more, those 'unlikely' are pointless
there. Fixed variant follows; only build-tested, though.

make it use copy_{from,to}_user(), rather than access_ok() +
__copy_...

Signed-off-by: Al Viro <[email protected]>
---
arch/powerpc/kernel/ptrace.c | 22 +++++++---------------
1 file changed, 7 insertions(+), 15 deletions(-)

diff --git a/arch/powerpc/kernel/ptrace.c b/arch/powerpc/kernel/ptrace.c
index d23cf632edf0..f557322621e0 100644
--- a/arch/powerpc/kernel/ptrace.c
+++ b/arch/powerpc/kernel/ptrace.c
@@ -3081,27 +3081,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)))
- 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;
+ if (copy_from_user(&bp_info, datavp,
+ sizeof(struct ppc_hw_breakpoint)))
+ return -EFAULT;
+ return ppc_set_hwdebug(child, &bp_info);
}

case PPC_PTRACE_DELHWDEBUG: {
--
2.11.0