From nobody Fri Aug 28 12:05:11 2026 X-Original-To: dev-commits-src-all@mlmmj.nyi.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mlmmj.nyi.freebsd.org (Postfix) with ESMTP id 4hWcX81dgNz6qH44 for ; Fri, 28 Aug 2026 12:05:12 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from mxrelay.nyi.freebsd.org (mxrelay.nyi.freebsd.org [IPv6:2610:1c1:1:606c::19:3]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256 client-signature RSA-PSS (4096 bits) client-digest SHA256) (Client CN "mxrelay.nyi.freebsd.org", Issuer "YR2" (not verified)) by mx1.freebsd.org (Postfix) with ESMTPS id 4hWcX746Qbz3Bmk for ; Fri, 28 Aug 2026 12:05:11 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1787918711; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=qoFnrfCRzbKrFMsHF45hJNkfmMyRycnTHWepljPGVlo=; b=ZtUmRDpT3gXgIhfBuswSjREqttE5fiH9DliJ/+RpikiuhvpnCHsnJTboFmRBHJNve3mefV qm6aFDzNjixT7cyXtHkn1m/T4CB6t/khvSa/3SYPMOHatteai5GRa/hy2ssZFWoeHuDoOD lCjI26vlCrnIrcQrfceW+rfCMmZRInyarwofL1lBJGKJ4tivu578bsoMwokn5zLSWNsBO5 oZysYHVCVatDg6MbD0wKacNfA7EZA6gQqFhuc4QKXsQeP+IqeS3Sb/sDu4fU0KoEJwbX3n IOaDPuF8zyRpagdh7V5Jg6lv5Ohpi88RIdvmTGnwW2/Mpjk+1FIYG+Jr5J5LSA== ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1787918711; a=rsa-sha256; cv=none; b=p2U07ITipTARYmxmB/jjvypZ91I1lond+0eUxahwP4YfyLX00jFn/YghmtUHL9NdVCLapy 2eDxxHWJMtCTS16ip9a4oFROiMjxgnBEE3QWqKkZ1XZJ+oqfzCE7TmxkPGDcOhryG8Hp4g mTtreiDM5iliLJgiyudw98MKkdR+As/up7FfKLdrMQZP1TwRPZA6PNn4fTYVYHipObqOLY cJjFLOeskz2hSn/VquYTPLA/x0OX+yaADWoOH3U9EaYtVHDuaQQJ6rpxhrtIDaWauZsVQt EJGZIEngwLRruvcOKU+MNYhwNlFtIf3pRagSdyjxMvbjOZw9Ndv3GhHmAHfJeQ== ARC-Authentication-Results: i=1; mx1.freebsd.org; none ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1787918711; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=qoFnrfCRzbKrFMsHF45hJNkfmMyRycnTHWepljPGVlo=; b=tJA2QBp1h2LcqV9a8F8b1orFbEgFvtyJnbiAWdPzIjYOxu2QqBXKkpJNU91Md2L6NHwY2f BJaqeQnqQRwH3l18dXsB0eur9yhFVEaaX4u4MjB1rSiFinIGBl7Kx3d8Y3Mn/+NAutY6mw 4wiCB5vwfhyUjXI3O/3lC2MiPoVJ+VbaKG4iAN2MjkrT/hBhSaI2fK4SgTnyCj3URfnkAi HUfIOgAjjfX16NEAp0zqA3gr8XwmLl1IWl02v/s1fupMICzeXmOKhIl2O0IB5EqMeMjyUf EtYuEFYsueN6cybGUAof6xedAvOc7fhbqOMnSnY+p590ApESlj9rAzyYadRSgw== Received: from gitrepo.freebsd.org (gitrepo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:5]) by mxrelay.nyi.freebsd.org (Postfix) with ESMTP id 4hWcX72lhTz18CD for ; Fri, 28 Aug 2026 12:05:11 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from git (uid 1279) (envelope-from git@FreeBSD.org) id 25e92 by gitrepo.freebsd.org (DragonFly Mail Agent v0.13+ on gitrepo.freebsd.org); Fri, 28 Aug 2026 12:05:11 +0000 To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-main@FreeBSD.org From: Konstantin Belousov Subject: git: 45633600acad - main - pdfork.2, rights.4: document pdptrace(2), CAP_PTRACE, and pdfork(PD_PTRACE_CAP) List-Id: Commit messages for all branches of the src repository List-Archive: https://lists.freebsd.org/archives/dev-commits-src-all List-Help: List-Post: List-Subscribe: List-Unsubscribe: X-BeenThere: dev-commits-src-all@freebsd.org Sender: owner-dev-commits-src-all@FreeBSD.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Git-Committer: kib X-Git-Repository: src X-Git-Refname: refs/heads/main X-Git-Reftype: branch X-Git-Commit: 45633600acade39cccc3b8daace7b3aeeb1f5b07 Auto-Submitted: auto-generated Date: Fri, 28 Aug 2026 12:05:11 +0000 Message-Id: <6a917977.25e92.128542b6@gitrepo.freebsd.org> The branch main has been updated by kib: URL: https://cgit.FreeBSD.org/src/commit/?id=45633600acade39cccc3b8daace7b3aeeb1f5b07 commit 45633600acade39cccc3b8daace7b3aeeb1f5b07 Author: Konstantin Belousov AuthorDate: 2026-07-19 22:56:32 +0000 Commit: Konstantin Belousov CommitDate: 2026-08-28 11:52:32 +0000 pdfork.2, rights.4: document pdptrace(2), CAP_PTRACE, and pdfork(PD_PTRACE_CAP) Reviewed by: markj Sponsored by: The FreeBSD Foundation MFC after: 1 week Differential revision: https://reviews.freebsd.org/D58586 --- lib/libsys/pdfork.2 | 51 ++++++++++++++++++++++++++++++++++++++++++++++--- lib/libsys/ptrace.2 | 1 + share/man/man4/rights.4 | 3 +++ 3 files changed, 52 insertions(+), 3 deletions(-) diff --git a/lib/libsys/pdfork.2 b/lib/libsys/pdfork.2 index 3c18a0f4130c..6ac85f717d01 100644 --- a/lib/libsys/pdfork.2 +++ b/lib/libsys/pdfork.2 @@ -66,6 +66,14 @@ .Fc .Ft int .Fn pddupfd "int fd" "int remotefd" "int flags" +.Ft int +.Fo pdptrace +.Fa "int req" +.Fa "int fd" +.Fa "int lwpid" +.Fa "void *addr" +.Fa "int data" +.Fc .Sh DESCRIPTION Process descriptors are special file descriptors that represent processes, and are created using @@ -83,7 +91,7 @@ on termination. .Fn pdfork can accept the .Fa pdflags: -.Bl -tag -width PD_CLOEXEC +.Bl -tag -width PD_PTRACE_CAP .It Dv PD_DAEMON Instead of the default terminate-on-close behaviour, allow the process to live until it is explicitly killed with @@ -106,6 +114,16 @@ Set close-on-exec on process descriptor. .It Dv PD_NOWAITPID The parent cannot obtain the child's status with .Xr waitpid 2 . +.It Dv PD_PTRACE_CAP +Enable +.Xr pdptrace 2 +requests on the resulting file descriptor. +Otherwise the descriptor cannot be used to debug the child process. +See +.Xr rights 4 +for the description of the +.Dv CAP_PTRACE +capability. .El .Pp The @@ -197,6 +215,32 @@ The argument is reserved and must be zero. Certain file descriptor types cannot be copied this way, namely kqueues. +.Pp +The +.Fn pdptrace +function enables execution of +.Xr ptrace 2 +requests on the process specified by the process descriptor +.Fa fd . +.Pp +In addition to the arguments taken by the +.Xr ptrace 2 , +system call, the +.Fa lwpid +thread identifier can designate the thread on which the request +must operate. +The +.Fa lwpid +argument can be specified as \-1 if the call is not thread-specific, +or kernel is allowed to select some thread on its own. +.Pp +Unlike the +.Xr ptrace 2 +implementation, +.Fn pdptrace +does not clear the +.Dv errno +variable before executing the system call. .Sh INTERACTION OF PROCESS DESCRIPTORS AND Xr WAITPID 2 .Pp The @@ -461,8 +505,9 @@ functions were developed by with input from .An Alan Somers Aq Mt asomers@FreeBSD.org . The -.Fn pdopenpid +.Fn pdopenpid , +.Fn pddupfd , and -.Fn pddupfd +.Fn pdptrace functions were developed by .An Konstantin Belousov Aq Mt kib@FreeBSD.org . diff --git a/lib/libsys/ptrace.2 b/lib/libsys/ptrace.2 index cedcf92cbef1..c8513c7ba12d 100644 --- a/lib/libsys/ptrace.2 +++ b/lib/libsys/ptrace.2 @@ -1514,6 +1514,7 @@ holds the minimum buffer size required on return. .El .Sh SEE ALSO .Xr execve 2 , +.Xr pdptrace 2 , .Xr sigaction 2 , .Xr wait 2 , .Xr execv 3 , diff --git a/share/man/man4/rights.4 b/share/man/man4/rights.4 index 396222a84579..93489300d161 100644 --- a/share/man/man4/rights.4 +++ b/share/man/man4/rights.4 @@ -484,6 +484,9 @@ Permit .It Dv CAP_PDKILL Permit .Xr pdkill 2 . +.It Dv CAP_PTRACE +Permit debugging using +.Xr pdptrace 2 . .It Dv CAP_PDWAIT Permit .Xr pdwait 2 .