Re: [PATCH consolidate sys_ptrace

Norbert Kiesel
2005-11-01T10:11:28Z

On Tue, 01 Nov 2005 06:12:21 +0100, Christoph Hellwig wrote:

<snip>

> Index: linux-2.6/kernel/ptrace.c
> ===================================================================
> --- linux-2.6.orig/kernel/ptrace.c 2005-10-31 13:15:52.000000000 +0100
> +++ linux-2.6/kernel/ptrace.c 2005-10-31 17:30:43.000000000 +0100
> @@ -406,3 +406,85 @@
>
> return ret;
> }
> +
> +#ifndef __ARCH_SYS_PTRACE
> +static int ptrace_get_task_struct(long request, long pid,
> + struct task_struct **childp)
> +{
> + struct task_struct *child;
> + int ret;
This "ret" is basically unused and should go away

> +
> + /*
> + * Callers use child == NULL as an indication to exit early even
> + * when the return value is 0, so make sure it is non-NULL here.
> + */
> + *childp = NULL;
> +
> + if (request == PTRACE_TRACEME) {
> + /*
> + * Are we already being traced?
> + */
> + if (current->ptrace & PT_PTRACED)
> + return -EPERM;
> + ret = security_ptrace(current->parent, current);
> + if (ret)
if (security_ptrace(current->parent, current))

> + return -EPERM;
> + /*
> + * Set the ptrace bit in the process ptrace flags.
> + */
> + current->ptrace |= PT_PTRACED;
> + return 0;
> + }
> +
> + /*
> + * You may not mess with init
> + */
> + if (pid == 1)
> + return -EPERM;
> +
> + ret = -ESRCH;
Not needed (anymore)

> + read_lock(&tasklist_lock);
> + child = find_task_by_pid(pid);
> + if (child)
> + get_task_struct(child);
> + read_unlock(&tasklist_lock);
> + if (!child)
> + return -ESRCH;
> +
> + *childp = child;
> + return 0;
> +}
> +

Best,
Norbert