* [PATCH] ptrace: clear TIF_SYSCALL_TRACE on ptrace detach
@ 2016-09-01 13:54 Ales Novak
2016-09-01 16:46 ` Oleg Nesterov
0 siblings, 1 reply; 5+ messages in thread
From: Ales Novak @ 2016-09-01 13:54 UTC (permalink / raw)
To: linux-kernel; +Cc: Oleg Nesterov, Andrew Morton, Ales Novak, Jiri Kosina
On ptrace_detach(), the TIF_SYSCALL_TRACE in thread->flags of the tracee
is not cleared up. This results in the tracehook_report_syscall_* being
called (though there's no longer a tracer listening to that) upon its
further syscalls.
Example scenario - attach "strace" to a running process and kill it (the
strace) with SIGKILL. You'll see that the syscall trace hooks are still
being called.
Signed-off-by: Ales Novak <alnovak@suse.cz>
Cc: Jiri Kosina <jkosina@suse.cz>
---
kernel/ptrace.c | 1 +
1 file changed, 1 insertion(+)
diff --git a/kernel/ptrace.c b/kernel/ptrace.c
index 1d3b766..634740f 100644
--- a/kernel/ptrace.c
+++ b/kernel/ptrace.c
@@ -85,6 +85,7 @@ void __ptrace_unlink(struct task_struct *child)
task_clear_jobctl_pending(child, JOBCTL_TRAP_MASK);
task_clear_jobctl_trapping(child);
+ clear_tsk_thread_flag(child, TIF_SYSCALL_TRACE);
/*
* Reinstate JOBCTL_STOP_PENDING if group stop is in effect and
* @child isn't dead.
--
2.7.0
^ permalink raw reply related [flat|nested] 5+ messages in thread
* Re: [PATCH] ptrace: clear TIF_SYSCALL_TRACE on ptrace detach
2016-09-01 13:54 [PATCH] ptrace: clear TIF_SYSCALL_TRACE on ptrace detach Ales Novak
@ 2016-09-01 16:46 ` Oleg Nesterov
2016-09-01 19:50 ` Ales Novak
2016-09-01 19:51 ` Ales Novak
0 siblings, 2 replies; 5+ messages in thread
From: Oleg Nesterov @ 2016-09-01 16:46 UTC (permalink / raw)
To: Ales Novak; +Cc: linux-kernel, Andrew Morton, Jiri Kosina
On 09/01, Ales Novak wrote:
>
> On ptrace_detach(), the TIF_SYSCALL_TRACE in thread->flags of the tracee
> is not cleared up. This results in the tracehook_report_syscall_* being
> called (though there's no longer a tracer listening to that) upon its
> further syscalls.
>
> Example scenario - attach "strace" to a running process and kill it (the
> strace) with SIGKILL. You'll see that the syscall trace hooks are still
> being called.
We do not really care, if the tracer dies the tracee can be in the
inconsistent state anyway.
> --- a/kernel/ptrace.c
> +++ b/kernel/ptrace.c
> @@ -85,6 +85,7 @@ void __ptrace_unlink(struct task_struct *child)
> task_clear_jobctl_pending(child, JOBCTL_TRAP_MASK);
> task_clear_jobctl_trapping(child);
>
> + clear_tsk_thread_flag(child, TIF_SYSCALL_TRACE);
OK, probably this change makes sense anyway, but then you should
remove another clear_tsk_thread_flag(TIF_SYSCALL_TRACE) in ptrace_detach?
And I'd suggest to move this clear_tsk_thread_flag() up, before
spin_lock(siglock). Otherwise it looks as if we should clear this flag
with ->siglock held.
Oleg.
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH] ptrace: clear TIF_SYSCALL_TRACE on ptrace detach
2016-09-01 16:46 ` Oleg Nesterov
@ 2016-09-01 19:50 ` Ales Novak
2016-09-01 19:51 ` Ales Novak
1 sibling, 0 replies; 5+ messages in thread
From: Ales Novak @ 2016-09-01 19:50 UTC (permalink / raw)
To: Oleg Nesterov; +Cc: linux-kernel, Andrew Morton, Jiri Kosina
[-- Attachment #1: Type: text/plain, Size: 1419 bytes --]
On Thu, Sep 01, 2016 at 06:46:13PM +0200, Oleg Nesterov wrote:
> On 09/01, Ales Novak wrote:
> >
> > On ptrace_detach(), the TIF_SYSCALL_TRACE in thread->flags of the tracee
> > is not cleared up. This results in the tracehook_report_syscall_* being
> > called (though there's no longer a tracer listening to that) upon its
> > further syscalls.
> >
> > Example scenario - attach "strace" to a running process and kill it (the
> > strace) with SIGKILL. You'll see that the syscall trace hooks are still
> > being called.
>
> We do not really care, if the tracer dies the tracee can be in the
> inconsistent state anyway.
>
> > --- a/kernel/ptrace.c
> > +++ b/kernel/ptrace.c
> > @@ -85,6 +85,7 @@ void __ptrace_unlink(struct task_struct *child)
> > task_clear_jobctl_pending(child, JOBCTL_TRAP_MASK);
> > task_clear_jobctl_trapping(child);
> >
> > + clear_tsk_thread_flag(child, TIF_SYSCALL_TRACE);
>
> OK, probably this change makes sense anyway, but then you should
> remove another clear_tsk_thread_flag(TIF_SYSCALL_TRACE) in ptrace_detach?
You're right, sorry for not noticing that. Also my changelog was
misleading, I've tried to fix that.
>
> And I'd suggest to move this clear_tsk_thread_flag() up, before
> spin_lock(siglock). Otherwise it looks as if we should clear this flag
> with ->siglock held.
Good point also.
>
> Oleg.
>
--
Ales Novak
SUSE L3
[-- Attachment #2: Digital signature --]
[-- Type: application/pgp-signature, Size: 473 bytes --]
^ permalink raw reply [flat|nested] 5+ messages in thread
* [PATCH] ptrace: clear TIF_SYSCALL_TRACE on ptrace detach
2016-09-01 16:46 ` Oleg Nesterov
2016-09-01 19:50 ` Ales Novak
@ 2016-09-01 19:51 ` Ales Novak
2016-09-02 12:25 ` Oleg Nesterov
1 sibling, 1 reply; 5+ messages in thread
From: Ales Novak @ 2016-09-01 19:51 UTC (permalink / raw)
To: Oleg Nesterov; +Cc: linux-kernel, Andrew Morton, Jiri Kosina, Ales Novak
On __ptrace_detach(), called from do_exit()->exit_notify()->
forget_original_parent()->exit_ptrace(), the TIF_SYSCALL_TRACE in
thread->flags of the tracee is not cleared up. This results in the
tracehook_report_syscall_* being called (though there's no longer a
tracer listening to that) upon its further syscalls.
Example scenario - attach "strace" to a running process and kill it (the
strace) with SIGKILL. You'll see that the syscall trace hooks are still
being called.
The clearing of this flag should be moved from ptrace_detach() to
__ptrace_detach().
Signed-off-by: Ales Novak <alnovak@suse.cz>
Cc: Jiri Kosina <jkosina@suse.cz>
---
kernel/ptrace.c | 3 ++-
1 file changed, 2 insertions(+), 1 deletion(-)
diff --git a/kernel/ptrace.c b/kernel/ptrace.c
index 1d3b766..2a99027 100644
--- a/kernel/ptrace.c
+++ b/kernel/ptrace.c
@@ -73,6 +73,8 @@ void __ptrace_unlink(struct task_struct *child)
{
BUG_ON(!child->ptrace);
+ clear_tsk_thread_flag(child, TIF_SYSCALL_TRACE);
+
child->parent = child->real_parent;
list_del_init(&child->ptrace_entry);
@@ -489,7 +491,6 @@ static int ptrace_detach(struct task_struct *child, unsigned int data)
/* Architecture-specific hardware disable .. */
ptrace_disable(child);
- clear_tsk_thread_flag(child, TIF_SYSCALL_TRACE);
write_lock_irq(&tasklist_lock);
/*
--
2.7.0
^ permalink raw reply related [flat|nested] 5+ messages in thread
* Re: [PATCH] ptrace: clear TIF_SYSCALL_TRACE on ptrace detach
2016-09-01 19:51 ` Ales Novak
@ 2016-09-02 12:25 ` Oleg Nesterov
0 siblings, 0 replies; 5+ messages in thread
From: Oleg Nesterov @ 2016-09-02 12:25 UTC (permalink / raw)
To: Ales Novak; +Cc: linux-kernel, Andrew Morton, Jiri Kosina
On 09/01, Ales Novak wrote:
>
> On __ptrace_detach(), called from do_exit()->exit_notify()->
> forget_original_parent()->exit_ptrace(), the TIF_SYSCALL_TRACE in
> thread->flags of the tracee is not cleared up. This results in the
> tracehook_report_syscall_* being called (though there's no longer a
> tracer listening to that) upon its further syscalls.
>
> Example scenario - attach "strace" to a running process and kill it (the
> strace) with SIGKILL. You'll see that the syscall trace hooks are still
> being called.
To clarify, this patch can't really fix the problem(s), The tracee can
be killed by SIGTRAP in this case. Again, we do not care too much, a lot
of bad things can happen if the tracer dies.
But I agree, this patch makes the things better for free,
Acked-by: Oleg Nesterov <oleg@redhat.com>
^ permalink raw reply [flat|nested] 5+ messages in thread
end of thread, other threads:[~2016-09-02 12:26 UTC | newest]
Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2016-09-01 13:54 [PATCH] ptrace: clear TIF_SYSCALL_TRACE on ptrace detach Ales Novak
2016-09-01 16:46 ` Oleg Nesterov
2016-09-01 19:50 ` Ales Novak
2016-09-01 19:51 ` Ales Novak
2016-09-02 12:25 ` Oleg Nesterov
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).