Skip to content

(Was: ptrace: prevent PTRACE_SETREGS from corrupting stack)

Oleg Nesterov lkml 1 version In review

Get series with b4
b4 am [email protected]

Versions newest first

  1. v1 Latest4 patches 6 repliesIn review

Patches in v1 No applies recorded yet

#Subject and filesSizeRepliesApplied
1/4ptrace: introduce signal_wake_up_state() and ptrace_signal_wake_up()include/linux/sched.h kernel/ptrace.c kernel/signal.c+18 -150 replies
2/4ptrace: ensure arch_ptrace/ptrace_request can never race with SIGKILLarch/x86/kernel/step.c kernel/ptrace.c kernel/signal.c+55 -1313 replies
3/4ia64: kill thread_matches(), unexport ptrace_check_attach()arch/ia64/kernel/ptrace.c include/linux/ptrace.h kernel/ptrace.c+1 -291 reply
4/4wake_up_process() should be never used to wakeup a TASK_STOPPED/TRACED taskkernel/sched/core.c+2 -10 replies

Reviews trailers per patch

No Reviewed-by, Acked-by or Tested-by trailers for v1 yet.

Read the v1 thread

Cover letter [PATCH 0/4] (Was: ptrace: prevent PTRACE_SETREGS from corrupting stack)

add lkml/cc's.

Quoted 9 lines · Linus Torvalds
Quoted 3 lines · Oleg Nesterov

Or we can do this after wait_task_inactive() but then we need to take ->siglock again.

Yes. We absolutely need siglock, since that would be exactly what would protect us against signal_wake_up() (which is, I *think* the only thing that can ever wake up the TASK_TRACED/WAKEKILL cases).

Yes. And thus 4/4 probably should be 1/4.

Quoted 4 lines

And we'd need to make sure to re-set the WAKEKILL flag not just in all the callers of ptrace_check_attach(), but also in the failure case of wait_task_inactive(). I'm not sure it can actually fail if we cleared WAKEKILL, but it's all pretty subtle.

Afaics it can't fail if we clear WAKEKILL... So 2/4 assumes it should always succeed and adds the warning.

Quoted 2 lines

And when we *do* set the WAKEKILL bit again, we should make sure to wake the task in case the killable signal happened while it was clear.

Yes, yes, this is clear. And we need to ensure we can not race with attach-after-detach...

Quoted 3 lines

And I agree that this is all pretty scary and generally playing with another process' 'flags' field is some really nasty business. So I'm a bit worried about it.

Oh yes. And I was going to argue that (a much simpler) change which doesn't allow the tracee to return from ptrace_stop() is better. But then I recalled about set_task_blockstep() and changed my mind (see the changelog in 2/4).

Greg, this doesn't look like -stable material. But please let me know if you think 2/4 should be backported. With a couple of simple hacks in PTRACE_DETACH/LISTEN paths we can do this without 1/4 and without changes outside of ptrace.c. But again, probably we shouldn't do this.

Please review.

Oleg.