From nobody Tue Mar 25 09:49:26 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 4ZMQBD3Dv4z5sHcl for ; Tue, 25 Mar 2025 09:49:40 +0000 (UTC) (envelope-from theraven@FreeBSD.org) Received: from smtp.freebsd.org (smtp.freebsd.org [96.47.72.83]) (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 "smtp.freebsd.org", Issuer "R11" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 4ZMQBD1hb3z469f; Tue, 25 Mar 2025 09:49:40 +0000 (UTC) (envelope-from theraven@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1742896180; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=VBgiV4OYooxkx0C/fmvfrnNBca6EaA6ccV3a9CfU3zI=; b=aeYo652ottLnWaNRusvUEeSCtiZTd2DioQG77/pOCKIzOMxV1aO2q0EPEW2xeD5j7fvLn0 5Hr0JDNuzk1fjE0NQ6HFoeQ1oQv/D/y6WvFrboiXT4VzrzmK0etH454vSfdRMtoByPW1fX RifosaRl13MI9Fla42pjJR8QGols9gor6BUQPw5AN0F+ZC+13uAE6sev06ZIvDqhfcR1zR sk+puIds1dVpFgdKttgYfuFByITUSccmoY2RpTW9cYE2oP6T+d9zB5PwlFmlqMpv8n23T+ tCZjxS3RAIpSxAu2ovPQ7BTrdGb0Tnq/Ankl/tEnZJfnkXBXsnm0M04TLPho+Q== ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1742896180; a=rsa-sha256; cv=none; b=qm6wwbdKzUp1OYioI7nZjNfsRBtFzvUL34J7OYDCUyOhdn09mNVr2sWXBCPF7mp3+k3N1m LtkznenA231eGeZB0URXrMXA7goHkeK1c7zNtn93UYyEu5Ie8rzc5z/4al8crfyUB+xHDp YsE7exEMF7kS4svVSe0/2nGNS94QaYX/v6I7vzTB9G+TwSl+QBdASir13Dy9nbPRpZLAAC TzZuvp1tCfDTZK2UIGkPlIsFX7EVt4PhS1e9UIA/q3yB1k8uYYeAT1dFF6PpqXXdH612zU bWJwWOe0ol03HEn9X7oJzsQ2N5QG9UtzhRw9yOhQHB9Rew6/er5lMt1qfyo9dg== 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=1742896180; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=VBgiV4OYooxkx0C/fmvfrnNBca6EaA6ccV3a9CfU3zI=; b=uOsCK2ZI3XGE0+ILkd4N+jpCsF1aN3+R960vyDLUOb4QFcBnOQob510l+enqLc6t3NXjdU hm83Vdh4R2KJCVoFrDGowAezV8QFne8SL1cWweJosKirz+yFCtVLr8eHtnh5VKTShuPPWS DkViuDQwJMloBmfSOwTDvtmT+IsNizpEilYi+iyYg8mIkJyMSDNwCpuWRmHtcKRH+ihJxm NJtBrNQnIBhmY1HsYgukZmBiJsNX8VtQcfesDAwB5lc/vHNmHMatTzEpSFQ7KlrWejYfUV nNEMNArQZBxvEfOaauqaMp2ICj/mmZ4Al47uvXQ/QroRMEVrnw0YnzsGhBFOtQ== Received: from smtp.theravensnest.org (smtp.theravensnest.org [45.77.103.195]) (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) (Authenticated sender: theraven) by smtp.freebsd.org (Postfix) with ESMTPSA id 4ZMQBD0xdszsQw; Tue, 25 Mar 2025 09:49:40 +0000 (UTC) (envelope-from theraven@FreeBSD.org) Received: from smtpclient.apple (host109-151-111-3.range109-151.btcentralplus.com [109.151.111.3]) by smtp.theravensnest.org (Postfix) with ESMTPSA id 64FB8520; Tue, 25 Mar 2025 09:49:39 +0000 (GMT) Content-Type: text/plain; charset=utf-8 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 (Mac OS X Mail 16.0 \(3776.700.51.11.1\)) Subject: Re: Would we want pidfd_open(2) & SO_PEERPIDFD? From: David Chisnall In-Reply-To: Date: Tue, 25 Mar 2025 09:49:26 +0000 Cc: Konstantin Belousov , freebsd-hackers Content-Transfer-Encoding: quoted-printable Message-Id: References: To: Gleb Popov X-Mailer: Apple Mail (2.3776.700.51.11.1) On 25 Mar 2025, at 05:27, Gleb Popov wrote: >=20 > On Tue, Mar 25, 2025 at 8:04=E2=80=AFAM Konstantin Belousov = wrote: >>=20 >> Can this be summarized as just a use of pidfd to >> - get the pid of the peer >> - ensure the peer liveness? >>=20 >> I do not see much need of pidfd for this functionality. >=20 > 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. >=20 > 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=E2=80=99s 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). =20 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