From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from out02.mta.xmission.com ([166.70.13.232]) by bombadil.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1nrSZW-004CCQ-R4 for linux-um@lists.infradead.org; Wed, 18 May 2022 22:55:16 +0000 From: "Eric W. Biederman" Date: Wed, 18 May 2022 17:53:52 -0500 Message-Id: <20220518225355.784371-13-ebiederm@xmission.com> In-Reply-To: <871qwq5ucx.fsf_-_@email.froward.int.ebiederm.org> References: <871qwq5ucx.fsf_-_@email.froward.int.ebiederm.org> MIME-Version: 1.0 Subject: [PATCH 13/16] ptrace: Document why ptrace_setoptions does not need a lock List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Sender: "linux-um" Errors-To: linux-um-bounces+geert=linux-m68k.org@lists.infradead.org To: linux-kernel@vger.kernel.org Cc: rjw@rjwysocki.net, Oleg Nesterov , mingo@kernel.org, vincent.guittot@linaro.org, dietmar.eggemann@arm.com, rostedt@goodmis.org, mgorman@suse.de, bigeasy@linutronix.de, Will Deacon , tj@kernel.org, linux-pm@vger.kernel.org, Peter Zijlstra , Richard Weinberger , Anton Ivanov , Johannes Berg , linux-um@lists.infradead.org, Chris Zankel , Max Filippov , linux-xtensa@linux-xtensa.org, Kees Cook , Jann Horn , linux-ia64@vger.kernel.org, Robert OCallahan , Kyle Huey , Richard Henderson , Ivan Kokshaysky , Matt Turner , Jason Wessel , Daniel Thompson , Douglas Anderson , Douglas Miller , Michael Ellerman , Benjamin Herrenschmidt , Paul Mackerras , "Eric W. Biederman" The functions that change ->ptrace are: ptrace_attach, ptrace_traceme, ptrace_init_task, __ptrace_unlink, ptrace_setoptions. Except for ptrace_setoptions all of the places where ->ptrace is modified hold tasklist_lock for write, and either the tracee or the tracer is modifies ->ptrace. When ptrace_setoptions is called the tracee has been frozen with ptrace_freeze_traced, and most be explicitly unfrozen by the tracer before it can do anything. As ptrace_setoption is run in the tracer there can be no contention by the simple fact that the tracee can't run. Signed-off-by: "Eric W. Biederman" --- kernel/ptrace.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/kernel/ptrace.c b/kernel/ptrace.c index d0527b6e2b29..fbadd2f21f09 100644 --- a/kernel/ptrace.c +++ b/kernel/ptrace.c @@ -689,7 +689,10 @@ static int ptrace_setoptions(struct task_struct *child, unsigned long data) if (ret) return ret; - /* Avoid intermediate state when all opts are cleared */ + /* + * With a frozen tracee, only the tracer modifies ->ptrace. + * Avoid intermediate state when all opts are cleared. + */ flags = child->ptrace; flags &= ~(PTRACE_O_MASK << PT_OPT_FLAG_SHIFT); flags |= (data << PT_OPT_FLAG_SHIFT); -- 2.35.3 _______________________________________________ linux-um mailing list linux-um@lists.infradead.org http://lists.infradead.org/mailman/listinfo/linux-um