Received: by 2002:ac0:b08d:0:0:0:0:0 with SMTP id l13csp4609478imc; Mon, 25 Feb 2019 07:52:20 -0800 (PST) X-Google-Smtp-Source: AHgI3Iab63B8Vgu72YCCwTepHZD8kravyXZVmuBP20TB8aRUZwr3xv3jpjKnqSj4CBsymryWxZDz X-Received: by 2002:a17:902:2be8:: with SMTP id l95mr21279715plb.270.1551109940552; Mon, 25 Feb 2019 07:52:20 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1551109940; cv=none; d=google.com; s=arc-20160816; b=GbM3/NwzklZw2XtaRU9aMzrSEeZ62DG9JqUCtzpei4kSDTLz/hasYlsgVGSjBXnhM2 S4vEOMyoMeZDi4DRYI7VqF4CK0M6+sB6MA3XKwHlRKLUItlK6buF19Lm/x/eCVsOk+ZN ps9WJaCQdZ81loUFBbYfHNs9OOX37Ii2q38HhDMHDRqQ9kOeg1I02MJ3B+l+qtQ7Ulpa c/05poWkNse5OQ+QXDCq6vopX0B0aNP+EI8YYnigHhsu3bJtxwuWQNbYjVUrSj5UXyq8 lReEIdvj0ab2kwuQaz/wMHUpDBglxhl8mBYhO4Yola5k3mb3w43+y4hbTu+i8ULltoCi +iGg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:cc:to:subject :message-id:date:from:reply-to:in-reply-to:references:mime-version :dkim-signature; bh=kAhK+uBzcDW/sfrS4FAzFOMfe7UXUTrqFRB04jK+4xc=; b=kw3uDSvgeaNRkm8UTFYMFwQRlsjVjgqtSy4zm3UABEO+QAIesnUVG1I3zURWOkcHDZ YPdtbSYLgzXYZgixk6Gbe6uMXqjJlhsYt7azmNAWfJY40HxnnH79y2UeLT4pUFeCUsp+ ZhN1Sb1Yx/ikDXdNJTHUazTyOubVTRBZ+XQpFFx9OOGf8dQUntBrrIrkhvXjIJnaxvY6 VPQwvzzgOENKirassgK7TbuDiLsdNFVQJRjDBEWWh+6BmTd3Oc3BDofvIIYFmEYE+1Et 49e/g7MytI27TmrmZl5BbmCIMugYQMtUVs9VUQ2hIb9jcNWu4H49pqS8AIJXEIJt8bE2 Qv0w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=Z85Zr+st; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id j7si9726517pll.121.2019.02.25.07.52.04; Mon, 25 Feb 2019 07:52:20 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=Z85Zr+st; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727813AbfBYPv2 (ORCPT + 99 others); Mon, 25 Feb 2019 10:51:28 -0500 Received: from mail-ed1-f67.google.com ([209.85.208.67]:34509 "EHLO mail-ed1-f67.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727657AbfBYPvY (ORCPT ); Mon, 25 Feb 2019 10:51:24 -0500 Received: by mail-ed1-f67.google.com with SMTP id a16so7999219edn.1; Mon, 25 Feb 2019 07:51:22 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=mime-version:references:in-reply-to:reply-to:from:date:message-id :subject:to:cc:content-transfer-encoding; bh=kAhK+uBzcDW/sfrS4FAzFOMfe7UXUTrqFRB04jK+4xc=; b=Z85Zr+stosqySFWIW+KiE8rjr7jc/qqX6untjUDcxmFJdSLpIWzehVU5KfAnHCaBWV FUO6jqixtID0O7pOCZmQHDIPB2XjBOsqDSq3WxUnFYgNpX5t0xEafT/SR9IFbddhwPLV 8R7GwpLJfWtJT1agygEeK2FysYYfgsaQLJlHMc4cNcPW9TqDAuVFiTAeNTQsuqAzdvpl od/6nLobjB8yxIW4wJiAucZJ/ptXY4iaVxRm6rqVK9ctysng01dzRJUGRswzj1cMU9+R 5J/7Lu0QztPxYUQf31CKaYOIX8yxp7AY2qy3x1VdC0Xio5n7eHbPi86H6PV7edXuFXxV MyPw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:reply-to :from:date:message-id:subject:to:cc:content-transfer-encoding; bh=kAhK+uBzcDW/sfrS4FAzFOMfe7UXUTrqFRB04jK+4xc=; b=lPKwgCv0/SXAj+1UXNRsNGfxzqivtrVlrVYrhUgKpV46cqyqi55/Fqxc33ODeoOtQN 8X/MWzJ2jfVzKVkZBd8sclgDPXoRdOY6CnPKiXpV0fUiQhioRslVNvkFWQQiHDml0qPf b2lt8O6BOrTbbXe0ScR579w3+Tuhx3oMzVcefz0dDW7w//9Ulc8EnJV9XtWr/+PSkCfu DKX2f0FrdXKiOSkCp5BhO/w3OTqcOXVCN7O++ZqDDpLncSS+oYXfsu44r1rNGJkFbyw1 aX+7yJmiqC7B0vzax7/H1fUTHjfexIm8Hfy0sxZuT+bVbLE6jEoChf0J3NHUS/TgNV/o OAXA== X-Gm-Message-State: AHQUAuZ9A8qXpuSFhb35IzbQ4mWN0oYE4tjg8fmhmI6KXy83Fm5o1fvE DklHcMaLJOYZPB2MNpMjwAVgWmfBCFDgPQLSOZU= X-Received: by 2002:a17:906:28c7:: with SMTP id p7mr13737616ejd.235.1551109881805; Mon, 25 Feb 2019 07:51:21 -0800 (PST) MIME-Version: 1.0 References: <48bb7c89-abb9-1e88-fee3-fb42d4032d12@nh2.me> <20190217221523.GA9233@altlinux.org> In-Reply-To: <20190217221523.GA9233@altlinux.org> Reply-To: mtk.manpages@gmail.com From: "Michael Kerrisk (man-pages)" Date: Mon, 25 Feb 2019 16:51:10 +0100 Message-ID: Subject: Re: [PATCH] ptrace.2: Improve clarity for multi-threaded tracers To: =?UTF-8?Q?Niklas_Hamb=C3=BCchen?= Cc: "Dmitry V. Levin" , lkml , cleverca22@gmail.com, linux-man Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Hi Niklas, Do you plan to revise this patch in the light of Dmitry's comments? Thanks, Michael On Sun, 17 Feb 2019 at 23:15, Dmitry V. Levin wrote: > > Hi, > > On Sun, Feb 17, 2019 at 05:34:46PM +0100, Niklas Hamb=C3=BCchen wrote: > > Until now, the man page said: > > > > Attachment and subsequent commands are per thread: > > in a multi=E2=80=90 threaded process, every thread can be individua= lly attached to a > > (potentially different) tracer, or left not attached and thus not d= ebugged. > > Therefore, "tracee" always means "(one) thread", never "a (possibly > > multithreaded) process". > > > > While the first sentence "Attachment ... [is] per thread" might be inte= rpreted > > as holding for both tracer and tracee, the rest talks only about the > > multi-threadedness of the *tracee*, leaving some uncertainty in the rea= der on > > whether the tracer may issue `ptrace()` from different threads. > > > > This patch adds more explicitness, removing any doubt. > > Thanks for making an attempt to remove any doubt. > > Yes, ptrace'ing is per task_struct on both sides. > > > Relevant resources: > > > > * LKML thread https://marc.info/?l=3Dlinux-kernel&m=3D155036848808748&w= =3D2 > > "ptrace() with multithreaded tracer" > > where I asked about this behaviour, in case anybody disagrees with my > > understanding > > * https://stackoverflow.com/questions/18737866/can-a-thread-trace-a-pro= cess/ > > where the previous ambiguity of the man page confused some users, and= where > > and example program is given that confirms the behaviour I mention in= this > > patch > > * A program of mine, in which I have independently confirmed that using > > `ptrace()` from a thread that's not the tracer thread (a sibling thre= ad in > > the process is the tracer instead) results in `ESRCH` > > * https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/tr= ee/kernel/ptrace.c?id=3D96d4f267e40f9509e8a66e2b39e8b95655617693#n207 > > where the comment on `ptrace_check_attach()` talks about `%current`, = which > > is a thread > > > > Signed-off-by: Niklas Hamb=C3=BCchen > > --- > > man2/ptrace.2 | 14 ++++++++++---- > > 1 file changed, 10 insertions(+), 4 deletions(-) > > > > diff --git a/man2/ptrace.2 b/man2/ptrace.2 > > index 3b6b6ea84..4058abe94 100644 > > --- a/man2/ptrace.2 > > +++ b/man2/ptrace.2 > > @@ -122,12 +122,18 @@ It is primarily used to implement breakpoint debu= gging and system > > call tracing. > > .PP > > A tracee first needs to be attached to the tracer. > > -Attachment and subsequent commands are per thread: > > -in a multithreaded process, > > +Attachment and subsequent commands are per thread, > > +on both the tracer and tracee side. > > +Issuing a tracing command from a thread that is not the tracer of the = given > > +.I pid > > +will result in an > > +.B ESRCH > > +error. > > This is confusing. What do you mean by a tracing command? > Is PTRACE_TRACEME a tracing command? PTRACE_ATTACH? PTRACE_SEIZE? > > I suggest leaving the explanation of ptrace return code to "ERRORS" > section. > > > +In a multithreaded process to be traced, > > every thread can be individually attached to a > > (potentially different) tracer, > > or left not attached and thus not debugged. > > -Therefore, "tracee" always means "(one) thread", > > +Therefore, "tracer" or "tracee" always mean "(one) thread", > > never "a (possibly multithreaded) process". > > Ptrace commands are always sent to > > a specific tracee using a call of the form > > @@ -2259,7 +2265,7 @@ or (on kernels before 2.6.26) be > > .TP > > .B ESRCH > > The specified process does not exist, or is not currently being traced > > -by the caller, or is not stopped > > +by the calling thread, or is not stopped > > (for requests that require a stopped tracee). > > .SH CONFORMING TO > > SVr4, 4.3BSD. > > I agree the current text can be made more clear on the subject, > but, unfortunately, proposed change makes the description more confusing. > > > -- > ldv --=20 Michael Kerrisk Linux man-pages maintainer; http://www.kernel.org/doc/man-pages/ Linux/UNIX System Programming Training: http://man7.org/training/