<feed xmlns='http://www.w3.org/2005/Atom'>
<title>kernel.git/kernel/ptrace.c, branch linux-2.6.33.y</title>
<subtitle>Hosts the 0x221E linux distro kernel.
</subtitle>
<id>https://git.0xinfinity.dev/distro/kernel.git/atom?h=linux-2.6.33.y</id>
<link rel='self' href='https://git.0xinfinity.dev/distro/kernel.git/atom?h=linux-2.6.33.y'/>
<link rel='alternate' type='text/html' href='https://git.0xinfinity.dev/distro/kernel.git/'/>
<updated>2011-05-23T18:22:56Z</updated>
<entry>
<title>ptrace: Prepare to fix racy accesses on task breakpoints</title>
<updated>2011-05-23T18:22:56Z</updated>
<author>
<name>Frederic Weisbecker</name>
</author>
<published>2011-04-07T14:53:20Z</published>
<link rel='alternate' type='text/html' href='https://git.0xinfinity.dev/distro/kernel.git/commit/?id=e12f87c3a2414e032610a0ff96402f2526983a76'/>
<id>urn:sha1:e12f87c3a2414e032610a0ff96402f2526983a76</id>
<content type='text'>
commit bf26c018490c2fce7fe9b629083b96ce0e6ad019 upstream.

When a task is traced and is in a stopped state, the tracer
may execute a ptrace request to examine the tracee state and
get its task struct. Right after, the tracee can be killed
and thus its breakpoints released.
This can happen concurrently when the tracer is in the middle
of reading or modifying these breakpoints, leading to dereferencing
a freed pointer.

Hence, to prepare the fix, create a generic breakpoint reference
holding API. When a reference on the breakpoints of a task is
held, the breakpoints won't be released until the last reference
is dropped. After that, no more ptrace request on the task's
breakpoints can be serviced for the tracer.

Reported-by: Oleg Nesterov &lt;oleg@redhat.com&gt;
Signed-off-by: Frederic Weisbecker &lt;fweisbec@gmail.com&gt;
Cc: Ingo Molnar &lt;mingo@elte.hu&gt;
Cc: Peter Zijlstra &lt;a.p.zijlstra@chello.nl&gt;
Cc: Will Deacon &lt;will.deacon@arm.com&gt;
Cc: Prasad &lt;prasad@linux.vnet.ibm.com&gt;
Cc: Paul Mundt &lt;lethal@linux-sh.org&gt;
Link: http://lkml.kernel.org/r/1302284067-7860-2-git-send-email-fweisbec@gmail.com
Signed-off-by: Greg Kroah-Hartman &lt;gregkh@suse.de&gt;

</content>
</entry>
<entry>
<title>ptrace: use safer wake up on ptrace_detach()</title>
<updated>2011-03-21T19:44:54Z</updated>
<author>
<name>Tejun Heo</name>
</author>
<published>2011-02-10T23:01:22Z</published>
<link rel='alternate' type='text/html' href='https://git.0xinfinity.dev/distro/kernel.git/commit/?id=edf07481f5a833b01bf23910834133fdac72fde1'/>
<id>urn:sha1:edf07481f5a833b01bf23910834133fdac72fde1</id>
<content type='text'>
commit 01e05e9a90b8f4c3997ae0537e87720eb475e532 upstream.

The wake_up_process() call in ptrace_detach() is spurious and not
interlocked with the tracee state.  IOW, the tracee could be running or
sleeping in any place in the kernel by the time wake_up_process() is
called.  This can lead to the tracee waking up unexpectedly which can be
dangerous.

The wake_up is spurious and should be removed but for now reduce its
toxicity by only waking up if the tracee is in TRACED or STOPPED state.

This bug can possibly be used as an attack vector.  I don't think it
will take too much effort to come up with an attack which triggers oops
somewhere.  Most sleeps are wrapped in condition test loops and should
be safe but we have quite a number of places where sleep and wakeup
conditions are expected to be interlocked.  Although the window of
opportunity is tiny, ptrace can be used by non-privileged users and with
some loading the window can definitely be extended and exploited.

Signed-off-by: Tejun Heo &lt;tj@kernel.org&gt;
Acked-by: Roland McGrath &lt;roland@redhat.com&gt;
Acked-by: Oleg Nesterov &lt;oleg@redhat.com&gt;
Signed-off-by: Andrew Morton &lt;akpm@linux-foundation.org&gt;
Signed-off-by: Linus Torvalds &lt;torvalds@linux-foundation.org&gt;
Signed-off-by: Greg Kroah-Hartman &lt;gregkh@suse.de&gt;

</content>
</entry>
<entry>
<title>ptrace: __ptrace_detach: do __wake_up_parent() if we reap the tracee</title>
<updated>2009-09-24T14:20:59Z</updated>
<author>
<name>Oleg Nesterov</name>
</author>
<published>2009-09-23T22:56:44Z</published>
<link rel='alternate' type='text/html' href='https://git.0xinfinity.dev/distro/kernel.git/commit/?id=a7f0765edfd53aed09cb7b0e15863688b39447de'/>
<id>urn:sha1:a7f0765edfd53aed09cb7b0e15863688b39447de</id>
<content type='text'>
The bug is old, it wasn't cause by recent changes.

Test case:

	static void *tfunc(void *arg)
	{
		int pid = (long)arg;

		assert(ptrace(PTRACE_ATTACH, pid, NULL, NULL) == 0);
		kill(pid, SIGKILL);

		sleep(1);
		return NULL;
	}

	int main(void)
	{
		pthread_t th;
		long pid = fork();

		if (!pid)
			pause();

		signal(SIGCHLD, SIG_IGN);
		assert(pthread_create(&amp;th, NULL, tfunc, (void*)pid) == 0);

		int r = waitpid(-1, NULL, __WNOTHREAD);
		printf("waitpid: %d %m\n", r);

		return 0;
	}

Before the patch this program hangs, after this patch waitpid() correctly
fails with errno == -ECHILD.

The problem is, __ptrace_detach() reaps the EXIT_ZOMBIE tracee if its
-&gt;real_parent is our sub-thread and we ignore SIGCHLD.  But in this case
we should wake up other threads which can sleep in do_wait().

Signed-off-by: Oleg Nesterov &lt;oleg@redhat.com&gt;
Cc: Roland McGrath &lt;roland@redhat.com&gt;
Cc: Vitaly Mayatskikh &lt;vmayatsk@redhat.com&gt;
Signed-off-by: Andrew Morton &lt;akpm@linux-foundation.org&gt;
Signed-off-by: Linus Torvalds &lt;torvalds@linux-foundation.org&gt;
</content>
</entry>
<entry>
<title>Merge branch 'master' into next</title>
<updated>2009-07-13T14:30:40Z</updated>
<author>
<name>James Morris</name>
</author>
<published>2009-07-13T14:30:40Z</published>
<link rel='alternate' type='text/html' href='https://git.0xinfinity.dev/distro/kernel.git/commit/?id=7d45ecafb6792ca68da9517969d37d910601845f'/>
<id>urn:sha1:7d45ecafb6792ca68da9517969d37d910601845f</id>
<content type='text'>
Conflicts:
	include/linux/personality.h

Use Linus' version.

Signed-off-by: James Morris &lt;jmorris@namei.org&gt;
</content>
</entry>
<entry>
<title>cred_guard_mutex: do not return -EINTR to user-space</title>
<updated>2009-07-06T20:57:04Z</updated>
<author>
<name>Oleg Nesterov</name>
</author>
<published>2009-07-05T19:08:26Z</published>
<link rel='alternate' type='text/html' href='https://git.0xinfinity.dev/distro/kernel.git/commit/?id=793285fcafce4719a05e0c99fa74b188157fe7fe'/>
<id>urn:sha1:793285fcafce4719a05e0c99fa74b188157fe7fe</id>
<content type='text'>
do_execve() and ptrace_attach() return -EINTR if
mutex_lock_interruptible(-&gt;cred_guard_mutex) fails.

This is not right, change the code to return ERESTARTNOINTR.

Perhaps we should also change proc_pid_attr_write().

Signed-off-by: Oleg Nesterov &lt;oleg@redhat.com&gt;
Cc: David Howells &lt;dhowells@redhat.com&gt;
Acked-by: Roland McGrath &lt;roland@redhat.com&gt;
Cc: James Morris &lt;jmorris@namei.org&gt;
Signed-off-by: Andrew Morton &lt;akpm@linux-foundation.org&gt;
Signed-off-by: Linus Torvalds &lt;torvalds@linux-foundation.org&gt;
</content>
</entry>
<entry>
<title>security: rename ptrace_may_access =&gt; ptrace_access_check</title>
<updated>2009-06-24T14:18:05Z</updated>
<author>
<name>Ingo Molnar</name>
</author>
<published>2009-05-07T09:26:19Z</published>
<link rel='alternate' type='text/html' href='https://git.0xinfinity.dev/distro/kernel.git/commit/?id=9e48858f7d36a6a3849f1d1b40c3bf5624b4ee7c'/>
<id>urn:sha1:9e48858f7d36a6a3849f1d1b40c3bf5624b4ee7c</id>
<content type='text'>
The -&gt;ptrace_may_access() methods are named confusingly - the real
ptrace_may_access() returns a bool, while these security checks have
a retval convention.

Rename it to ptrace_access_check, to reduce the confusion factor.

[ Impact: cleanup, no code changed ]

Signed-off-by: Ingo Molnar &lt;mingo@elte.hu&gt;
Signed-off-by: James Morris &lt;jmorris@namei.org&gt;
</content>
</entry>
<entry>
<title>ptrace: don't take tasklist to get/set -&gt;last_siginfo</title>
<updated>2009-06-18T20:03:52Z</updated>
<author>
<name>Oleg Nesterov</name>
</author>
<published>2009-06-17T23:27:36Z</published>
<link rel='alternate' type='text/html' href='https://git.0xinfinity.dev/distro/kernel.git/commit/?id=e49612544c695117644af48bb4625264a3d2918f'/>
<id>urn:sha1:e49612544c695117644af48bb4625264a3d2918f</id>
<content type='text'>
Change ptrace_getsiginfo/ptrace_setsiginfo to use lock_task_sighand()
without tasklist_lock.  Perhaps it makes sense to make a single helper
with "bool rw" argument.

Signed-off-by: Oleg Nesterov &lt;oleg@redhat.com&gt;
Acked-by: Roland McGrath &lt;roland@redhat.com&gt;
Signed-off-by: Andrew Morton &lt;akpm@linux-foundation.org&gt;
Signed-off-by: Linus Torvalds &lt;torvalds@linux-foundation.org&gt;
</content>
</entry>
<entry>
<title>ptrace_get_task_struct: s/tasklist/rcu/, make it static</title>
<updated>2009-06-18T20:03:51Z</updated>
<author>
<name>Oleg Nesterov</name>
</author>
<published>2009-06-17T23:27:34Z</published>
<link rel='alternate' type='text/html' href='https://git.0xinfinity.dev/distro/kernel.git/commit/?id=8053bdd5ce15dcf043d41a4dd6cac4a5567effdc'/>
<id>urn:sha1:8053bdd5ce15dcf043d41a4dd6cac4a5567effdc</id>
<content type='text'>
- Use rcu_read_lock() instead of tasklist_lock to find/get the task
  in ptrace_get_task_struct().

- Make it static, it has no callers outside of ptrace.c.

- The comment doesn't match the reality, this helper does not do
  any checks. Beacuse it is really trivial and static I removed the
  whole comment.

Signed-off-by: Oleg Nesterov &lt;oleg@redhat.com&gt;
Acked-by: Roland McGrath &lt;roland@redhat.com&gt;
Signed-off-by: Andrew Morton &lt;akpm@linux-foundation.org&gt;
Signed-off-by: Linus Torvalds &lt;torvalds@linux-foundation.org&gt;
</content>
</entry>
<entry>
<title>ptrace: do not use task_lock() for attach</title>
<updated>2009-06-18T20:03:51Z</updated>
<author>
<name>Oleg Nesterov</name>
</author>
<published>2009-06-17T23:27:33Z</published>
<link rel='alternate' type='text/html' href='https://git.0xinfinity.dev/distro/kernel.git/commit/?id=4b105cbbaf7c06e01c27391957dc3c446328d087'/>
<id>urn:sha1:4b105cbbaf7c06e01c27391957dc3c446328d087</id>
<content type='text'>
Remove the "Nasty, nasty" lock dance in ptrace_attach()/ptrace_traceme() -
from now task_lock() has nothing to do with ptrace at all.

With the recent changes nobody uses task_lock() to serialize with ptrace,
but in fact it was never needed and it was never used consistently.

However ptrace_attach() calls __ptrace_may_access() and needs task_lock()
to pin task-&gt;mm for get_dumpable().  But we can call __ptrace_may_access()
before we take tasklist_lock, -&gt;cred_exec_mutex protects us against
do_execve() path which can change creds and MMF_DUMP* flags.

(ugly, but we can't use ptrace_may_access() because it hides the error
code, so we have to take task_lock() and use __ptrace_may_access()).

NOTE: this change assumes that LSM hooks, security_ptrace_may_access() and
security_ptrace_traceme(), can be called without task_lock() held.

Signed-off-by: Oleg Nesterov &lt;oleg@redhat.com&gt;
Cc: Chris Wright &lt;chrisw@sous-sol.org&gt;
Acked-by: Roland McGrath &lt;roland@redhat.com&gt;
Signed-off-by: Andrew Morton &lt;akpm@linux-foundation.org&gt;
Signed-off-by: Linus Torvalds &lt;torvalds@linux-foundation.org&gt;
</content>
</entry>
<entry>
<title>ptrace: cleanup check/set of PT_PTRACED during attach</title>
<updated>2009-06-18T20:03:51Z</updated>
<author>
<name>Oleg Nesterov</name>
</author>
<published>2009-06-17T23:27:32Z</published>
<link rel='alternate' type='text/html' href='https://git.0xinfinity.dev/distro/kernel.git/commit/?id=f2f0b00ad61d53adfecb8bdf8f3cf8f05f6ed548'/>
<id>urn:sha1:f2f0b00ad61d53adfecb8bdf8f3cf8f05f6ed548</id>
<content type='text'>
ptrace_attach() and ptrace_traceme() are the last functions which look as
if the untraced task can have task-&gt;ptrace != 0, this must not be
possible.  Change the code to just check -&gt;ptrace != 0 and s/|=/=/ to set
PT_PTRACED.

Also, a couple of trivial whitespace cleanups in ptrace_attach().

And move ptrace_traceme() up near ptrace_attach() to keep them close to
each other.

Signed-off-by: Oleg Nesterov &lt;oleg@redhat.com&gt;
Cc: Chris Wright &lt;chrisw@sous-sol.org&gt;
Acked-by: Roland McGrath &lt;roland@redhat.com&gt;
Signed-off-by: Andrew Morton &lt;akpm@linux-foundation.org&gt;
Signed-off-by: Linus Torvalds &lt;torvalds@linux-foundation.org&gt;
</content>
</entry>
</feed>
