Skip site navigation (1)Skip section navigation (2)
Date:      Tue, 11 Feb 2025 21:03:20 +0300
From:      Gleb Popov <arrowd@freebsd.org>
To:        freebsd-hackers <freebsd-hackers@freebsd.org>
Subject:   Would we want pidfd_open(2) & SO_PEERPIDFD?
Message-ID:  <CALH631mgztNmngL1Hffbbcf0n-kLZP-2YmsMLJ8Xi33HV8uuvw@mail.gmail.com>

next in thread | raw e-mail | index | archive | help

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



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?CALH631mgztNmngL1Hffbbcf0n-kLZP-2YmsMLJ8Xi33HV8uuvw>