From nobody Tue Feb 11 18:57:08 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 4YsrKT71kLz5mWs5 for ; Tue, 11 Feb 2025 18:57:17 +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 4YsrKS5Q3zz43jN; Tue, 11 Feb 2025 18:57:16 +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 51BIv8F8052567; Tue, 11 Feb 2025 20:57:11 +0200 (EET) (envelope-from kostikbel@gmail.com) DKIM-Filter: OpenDKIM Filter v2.10.3 kib.kiev.ua 51BIv8F8052567 Received: (from kostik@localhost) by tom.home (8.18.1/8.18.1/Submit) id 51BIv8iD052566; Tue, 11 Feb 2025 20:57:08 +0200 (EET) (envelope-from kostikbel@gmail.com) X-Authentication-Warning: tom.home: kostik set sender to kostikbel@gmail.com using -f Date: Tue, 11 Feb 2025 20:57:08 +0200 From: Konstantin Belousov To: Gleb Popov Cc: 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=us-ascii Content-Disposition: inline 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-Queue-Id: 4YsrKS5Q3zz43jN X-Spamd-Bar: ---- 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] On Tue, Feb 11, 2025 at 09:03:20PM +0300, Gleb Popov wrote: > Hey hackers. > > D-Bus services can obtain PIDs of their clients via the sendmsg(2) > mechanism over unix sockets (or getsockopt(SO_PEERCRED)). But > operating on PIDs is racy, so to make sure the process has not been > terminated a service would need to call getsockopt(SO_PEERCRED) again. > It isn't immediately possible with D-Bus API and would require hacking > on its code. > > However, Linux has a better alternative for this case - > getsockopt(SO_PEERPIDFD) [1]. The call returns a pidfd (see > procdesc(4)), which is pinned to the caller process. DBus already > supports this [2], so if FreeBSD implements SO_PEERPIDFD the feature > will work for us out of the box. > > My question is - would it be possible for FreeBSD to support > SO_PEERPIDFD or I'd be better off to hack on D-Bus internals? > > Thanks in advance. > > [1] https://blog.sebastianwick.net/posts/so-peerpidfd-usefulness/ > [2] https://gitlab.freedesktop.org/dbus/dbus/-/merge_requests/398#b9391b9a8a6c8fb67b48b03b25e8893befbeff87 The semantic of the Linux' fd returned by pidfd_open() is not compatible with our pidfd. And it cannot be fixed/changed.