From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1756274AbcIAVDs (ORCPT ); Thu, 1 Sep 2016 17:03:48 -0400 Received: from mx2.suse.de ([195.135.220.15]:44431 "EHLO mx2.suse.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753154AbcIAVDo (ORCPT ); Thu, 1 Sep 2016 17:03:44 -0400 From: Ales Novak To: Oleg Nesterov Cc: linux-kernel@vger.kernel.org, Andrew Morton , Jiri Kosina , Ales Novak Subject: [PATCH] ptrace: clear TIF_SYSCALL_TRACE on ptrace detach Date: Thu, 1 Sep 2016 21:51:33 +0200 Message-Id: <1472759493-20554-1-git-send-email-alnovak@suse.cz> X-Mailer: git-send-email 2.7.0 In-Reply-To: <20160901164613.GA13138@redhat.com> References: <20160901164613.GA13138@redhat.com> Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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 Cc: Jiri Kosina --- 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