From nobody Tue Mar 25 10:53:21 2025 X-Original-To: freebsd-hackers@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 4ZMRc00CDPz5sLh5 for ; Tue, 25 Mar 2025 10:53:36 +0000 (UTC) (envelope-from kostikbel@gmail.com) Received: from kib.kiev.ua (kib.kiev.ua [IPv6:2001:470:d5e7:1::1]) (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 did not present a certificate) by mx1.freebsd.org (Postfix) with ESMTPS id 4ZMRbz3Zzgz4JmW; Tue, 25 Mar 2025 10:53:35 +0000 (UTC) (envelope-from kostikbel@gmail.com) Authentication-Results: mx1.freebsd.org; none Received: from tom.home (kib@localhost [127.0.0.1] (may be forged)) by kib.kiev.ua (8.18.1/8.18.1) with ESMTP id 52PArLjn029565; Tue, 25 Mar 2025 12:53:24 +0200 (EET) (envelope-from kostikbel@gmail.com) DKIM-Filter: OpenDKIM Filter v2.10.3 kib.kiev.ua 52PArLjn029565 Received: (from kostik@localhost) by tom.home (8.18.1/8.18.1/Submit) id 52PArLNv029564; Tue, 25 Mar 2025 12:53:21 +0200 (EET) (envelope-from kostikbel@gmail.com) X-Authentication-Warning: tom.home: kostik set sender to kostikbel@gmail.com using -f Date: Tue, 25 Mar 2025 12:53:21 +0200 From: Konstantin Belousov To: David Chisnall Cc: Gleb Popov , freebsd-hackers Subject: Re: Would we want pidfd_open(2) & SO_PEERPIDFD? Message-ID: References: List-Id: Technical discussions relating to FreeBSD List-Archive: https://lists.freebsd.org/archives/freebsd-hackers List-Help: List-Post: List-Subscribe: List-Unsubscribe: Sender: owner-freebsd-hackers@FreeBSD.org MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: X-Spam-Status: No, score=-1.0 required=5.0 tests=ALL_TRUSTED,BAYES_00, DKIM_ADSP_CUSTOM_MED,FORGED_GMAIL_RCVD,FREEMAIL_FROM, NML_ADSP_CUSTOM_MED autolearn=no autolearn_force=no version=4.0.1 X-Spam-Checker-Version: SpamAssassin 4.0.1 (2024-03-26) on tom.home X-Rspamd-Pre-Result: action=no action; module=replies; Message is reply to one we originated X-Spamd-Result: default: False [-4.00 / 15.00]; REPLY(-4.00)[]; ASN(0.00)[asn:6939, ipnet:2001:470::/32, country:US] X-Rspamd-Queue-Id: 4ZMRbz3Zzgz4JmW X-Spamd-Bar: ---- On Tue, Mar 25, 2025 at 09:49:26AM +0000, David Chisnall wrote: > On 25 Mar 2025, at 05:27, Gleb Popov wrote: > > > > On Tue, Mar 25, 2025 at 8:04 AM Konstantin Belousov wrote: > >> > >> Can this be summarized as just a use of pidfd to > >> - get the pid of the peer > >> - ensure the peer liveness? > >> > >> I do not see much need of pidfd for this functionality. > > > > What's the alternative? Tapping into a socket with > > getsockopt(LOCAL_PEERCRED) to obtain a PID via xucred is not an option > > because a client is not required to maintain an established connection > > to a D-Bus socket. > > > > The high level code expects a descriptor with some properties, so we > > either provide it or have to patch large parts of the code using it. > > Emulating pidfd somehow is also fine to me, but I have no idea how to > > do that. libinotify-kqueue example shows that emulating a descriptor > > with certain properties is quite a non-trivial task. > > It’s worth noting that DBUS is not the only thing that wants a race-free way of naming a process. Debuggers also have this problem. On XNU, the debugger uses the Mach task port, which is not completely like a process descriptor. When the target process exits, the task port will report errors. This eliminates the races that are intrinsic to the ptrace APIs. Extending process descriptors to subsume ptrace behaviour (and adding thread descriptors that avoid the same races on threads) and avoid these races has been on my wishlist for a long time. Doing this would require some Capsicum permissions on process descriptors (not every holder of a process descriptor should be able to ptrace it). > There is no races with ptrace(2). Attached debuggee pid is not worse than a handle, it cannot go away. > It would probably be good to collect the desired behaviours for process descriptors and do a proper implementation of the desired feature set. Currently, process descriptors serve precisely one need: Capsicum processes can use them to wait for process termination without needing access to the global PID namespace. > > David >