Received: by 2002:ac0:946b:0:0:0:0:0 with SMTP id j40csp1556286imj; Sun, 17 Feb 2019 08:35:23 -0800 (PST) X-Google-Smtp-Source: AHgI3IYb4mu6OISlnAsmyUawtrmB1Y55dyk9Vfbftga5lufSvmP/ue7yEY0OR7ZhQLE4GQa8szlY X-Received: by 2002:aa7:92da:: with SMTP id k26mr4966782pfa.216.1550421323183; Sun, 17 Feb 2019 08:35:23 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1550421323; cv=none; d=google.com; s=arc-20160816; b=OO/iG8hjuwB65v9wMsfdWJpZTaqNf+0oM3k50BQ7G+zDw+x/4HOiEpG0WsvGQgcdYE JRDstW+ayRtwSQeueFlyowdtcVNbRIy8E217AiPm0z0cbcN+ilZ9Lby1n3/qE45EMR2D JtVyQBZUzc1ttOkOcmDG4J7GXF9YnV78WMVpM04vzKFc8WQ8MN3OeUorjeOE7AjkOGju SRdurgf2MYpUfvReaZcya69sx9RRgeegyxlgQbo/Xsqi7aaqsGmUMBjRNvu1IJdgoUK2 BWDG1vILvas1xY36Ss4FEgv3GqS0LAFdP+rPQ0Oc6GfY+QuyaCS5G0MOh7XzPuxldnHB b9UQ== 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 :content-language:in-reply-to:mime-version:user-agent:date :message-id:autocrypt:openpgp:references:cc:to:from:subject; bh=yz8/6LCunReTwEbHR1N1TW6YNDs3AhrDxCn0NE4atro=; b=Sakbezx0+bCLYHsmhg1AEkAZ3LitdXRxdSfowMwzdG2CkBIa2kdBzstSoh+HB/ZAba ohJaB3R23RZOvL+k1MXd79Z+Xs3zBCUm6olf2RvtKRh4AEMsErEWuKHrxQSIxQ5NRfPy 4c5PubFlSVgdPadh5v01iy2bAHm7nZUuJtVM0QoM0loTHivTKv8egBNGV7MStYuHJGP7 8vCORqmnCdNHoNNyLFvzTqa3HZFKQRZz5Xzeq9daAb5ZdB8u+4/XUobQsUufuoq49KqC /JRel3thQAJGV48QO5scESUzBRq+KAifjQ2RYn2rajtgXgQD0HMfnoTmz21YSLOvUZz9 Mthg== ARC-Authentication-Results: i=1; mx.google.com; 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 Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id j132si10940860pfc.84.2019.02.17.08.35.06; Sun, 17 Feb 2019 08:35:23 -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; 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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726768AbfBQQeu (ORCPT + 99 others); Sun, 17 Feb 2019 11:34:50 -0500 Received: from mail.grenz-bonn.de ([178.33.37.38]:35374 "EHLO mail.grenz-bonn.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725810AbfBQQeu (ORCPT ); Sun, 17 Feb 2019 11:34:50 -0500 Received: from [192.168.1.100] (212-51-139-180.fiber7.init7.net [212.51.139.180]) by ks357529.kimsufi.com (Postfix) with ESMTPSA id 9F7FE7928D; Sun, 17 Feb 2019 17:34:47 +0100 (CET) Subject: [PATCH] ptrace.2: Improve clarity for multi-threaded tracers From: =?UTF-8?Q?Niklas_Hamb=c3=bcchen?= To: mtk.manpages@gmail.com Cc: linux-kernel@vger.kernel.org, cleverca22@gmail.com, linux-man@vger.kernel.org References: <48bb7c89-abb9-1e88-fee3-fb42d4032d12@nh2.me> Openpgp: preference=signencrypt Autocrypt: addr=mail@nh2.me; keydata= mQINBFZQegIBEADD2C+ODuFxK9XAQQqbP84M7y6gRDMIaFxqeT56g/pbe/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qOYPtbtKu3hqLgKf4FUVtUvOSA5aO0cWGUrWcyDrFOylvWLqTcd6 Srcvds4SgNok5ZqSPm4uFokPIXtnnnfS625chKyQpEjG2nvY7v26k5bnZe1fMWQ/1lKcTKNE sittu+pUu0QAouxvf58uLCyJMWGalw//Zqlmjeo4d4XlAYhZXVcxC3clHfGUYTDv/rbIFnvR b+Uf28TpEOtud14JK6+zDqili1YU1Ij9gRe+/1uSUs0wRi5MY96MM0bvJnKiX5/SAtHcuxw9 Kz+lJxN5L9sMpVPAwoe6JIqUTPpye/Jue831SZfRn3mfzcYb/SF5Hwdgywu4e1eRpVjNQBH1 MSUX/8GzZ+V4LhfZ40sxCwx5Z9YVaV2cSqgYqxUvIF5+vu6r40zWvrWP027+TpVL18cKjvMK VF/608uTmzmBHom5bQMcxJSdFMTngJg/Nln7XGuTJqtO1L6GqBq0MQHldRJKwkzlVrVkz+Z8 bN+kQkhVCW5H8i7uiFRUEk7Pz3Gx2MLyiPjuTBTc0VRPH1WRzW6R4Ictrf1fz6CT4/M4dFWt hUV84M6gI8jgK4pbW+bY4+8jObdduY4usqleR6y7mm31VV+dJLVqLOT7j4xhXfdojXXo9c9y wEPK29lwsDGETZvU8Om84L091W3W/+PEKEfAF9d3/Y2D6Xa49/Aj6cVJkSJu1cuAsEw8tWBu jWF7tAn11z6SXVw9OfK60nT5mG+3Tf0cL5npuWcAqpZRlOyN/0HGlW135QK8VzG6y7mnHmwv J1QPfRaxBQjCJ2JnQdFcfQIxI0nfqF64vNzenQrtZSGNDLgEvg1cdLOrXVoRHubYarA= Message-ID: Date: Sun, 17 Feb 2019 17:34:46 +0100 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:60.0) Gecko/20100101 Thunderbird/60.4.0 MIME-Version: 1.0 In-Reply-To: <48bb7c89-abb9-1e88-fee3-fb42d4032d12@nh2.me> Content-Type: text/plain; charset=utf-8 Content-Language: en-US Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Until now, the man page said: Attachment and subsequent commands are per thread: in a multi‐ threaded process, 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", never "a (possibly multithreaded) process". While the first sentence "Attachment ... [is] per thread" might be interpreted as holding for both tracer and tracee, the rest talks only about the multi-threadedness of the *tracee*, leaving some uncertainty in the reader on whether the tracer may issue `ptrace()` from different threads. This patch adds more explicitness, removing any doubt. Relevant resources: * LKML thread https://marc.info/?l=linux-kernel&m=155036848808748&w=2 "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-process/ 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 thread in the process is the tracer instead) results in `ESRCH` * https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/tree/kernel/ptrace.c?id=96d4f267e40f9509e8a66e2b39e8b95655617693#n207 where the comment on `ptrace_check_attach()` talks about `%current`, which is a thread Signed-off-by: Niklas Hambüchen --- 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 debugging 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. +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. -- 2.17.1