Skip to content

Commit aa72354

Browse files
committed
Merge branch 'for-linus' of git://git.kernel.org/pub/scm/linux/kernel/git/ebiederm/user-namespace
Pull ptrace fixes from Eric Biederman: "This is just two very minor fixes: - prevent ptrace from reading unitialized kernel memory found twice by syzkaller - restore a missing smp_rmb in ptrace_may_access and add comment tp it so it is not removed by accident again. Apologies for being a little slow about getting this to you, I am still figuring out how to develop with a little baby in the house" * 'for-linus' of git://git.kernel.org/pub/scm/linux/kernel/git/ebiederm/user-namespace: ptrace: restore smp_rmb() in __ptrace_may_access() signal/ptrace: Don't leak unitialized kernel memory with PTRACE_PEEK_SIGINFO
2 parents 4d8f5f9 + f6581f5 commit aa72354

File tree

2 files changed

+27
-2
lines changed

2 files changed

+27
-2
lines changed

kernel/cred.c

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -446,6 +446,15 @@ int commit_creds(struct cred *new)
446446
if (task->mm)
447447
set_dumpable(task->mm, suid_dumpable);
448448
task->pdeath_signal = 0;
449+
/*
450+
* If a task drops privileges and becomes nondumpable,
451+
* the dumpability change must become visible before
452+
* the credential change; otherwise, a __ptrace_may_access()
453+
* racing with this change may be able to attach to a task it
454+
* shouldn't be able to attach to (as if the task had dropped
455+
* privileges without becoming nondumpable).
456+
* Pairs with a read barrier in __ptrace_may_access().
457+
*/
449458
smp_wmb();
450459
}
451460

kernel/ptrace.c

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -324,6 +324,16 @@ static int __ptrace_may_access(struct task_struct *task, unsigned int mode)
324324
return -EPERM;
325325
ok:
326326
rcu_read_unlock();
327+
/*
328+
* If a task drops privileges and becomes nondumpable (through a syscall
329+
* like setresuid()) while we are trying to access it, we must ensure
330+
* that the dumpability is read after the credentials; otherwise,
331+
* we may be able to attach to a task that we shouldn't be able to
332+
* attach to (as if the task had dropped privileges without becoming
333+
* nondumpable).
334+
* Pairs with a write barrier in commit_creds().
335+
*/
336+
smp_rmb();
327337
mm = task->mm;
328338
if (mm &&
329339
((get_dumpable(mm) != SUID_DUMP_USER) &&
@@ -705,25 +715,31 @@ static int ptrace_peek_siginfo(struct task_struct *child,
705715
if (arg.nr < 0)
706716
return -EINVAL;
707717

718+
/* Ensure arg.off fits in an unsigned long */
719+
if (arg.off > ULONG_MAX)
720+
return 0;
721+
708722
if (arg.flags & PTRACE_PEEKSIGINFO_SHARED)
709723
pending = &child->signal->shared_pending;
710724
else
711725
pending = &child->pending;
712726

713727
for (i = 0; i < arg.nr; ) {
714728
kernel_siginfo_t info;
715-
s32 off = arg.off + i;
729+
unsigned long off = arg.off + i;
730+
bool found = false;
716731

717732
spin_lock_irq(&child->sighand->siglock);
718733
list_for_each_entry(q, &pending->list, list) {
719734
if (!off--) {
735+
found = true;
720736
copy_siginfo(&info, &q->info);
721737
break;
722738
}
723739
}
724740
spin_unlock_irq(&child->sighand->siglock);
725741

726-
if (off >= 0) /* beyond the end of the list */
742+
if (!found) /* beyond the end of the list */
727743
break;
728744

729745
#ifdef CONFIG_COMPAT

0 commit comments

Comments
 (0)