CRED: Guard the setprocattr security hook against ptrace
authorDavid Howells <dhowells@redhat.com>
Fri, 8 May 2009 12:55:27 +0000 (13:55 +0100)
committerJames Morris <jmorris@namei.org>
Sun, 10 May 2009 22:15:39 +0000 (08:15 +1000)
Guard the setprocattr security hook against ptrace by taking the target task's
cred_guard_mutex around it.  The problem is that setprocattr() may otherwise
note the lack of a debugger, and then perform an action on that basis whilst
letting a debugger attach between the two points.  Holding cred_guard_mutex
across the test and the action prevents ptrace_attach() from doing that.

Signed-off-by: David Howells <dhowells@redhat.com>
Signed-off-by: James Morris <jmorris@namei.org>
fs/proc/base.c

index fb45615943c2adba5e630fd1ea14a1d9e1c31fff..23342e188a6666819b01a19679f6693e18cbddc0 100644 (file)
@@ -2128,9 +2128,15 @@ static ssize_t proc_pid_attr_write(struct file * file, const char __user * buf,
        if (copy_from_user(page, buf, count))
                goto out_free;
 
+       /* Guard against adverse ptrace interaction */
+       length = mutex_lock_interruptible(&task->cred_guard_mutex);
+       if (length < 0)
+               goto out_free;
+
        length = security_setprocattr(task,
                                      (char*)file->f_path.dentry->d_name.name,
                                      (void*)page, count);
+       mutex_unlock(&task->cred_guard_mutex);
 out_free:
        free_page((unsigned long) page);
 out: