Products › lamco-dbus-tools › Docs
Enable the kernel part to stamp D-Bus messages at each socket
Enable the kernel part of lamco-dbus-tools to stamp D-Bus messages at every socket: Check the kernel, build it, run it as a unit, and refuse a connection.
Describes version 0.4.1.
The kernel part stamps each message at every socket it crosses, which is how dbustell timing --split
tells the bus's time from the service's. It's optional, and it costs every local stream socket on the
machine while it runs: About 0.3 to 0.9 µs added to each socket write and read on the machines measured
(docs/measurements/stage-11/). Since 2026-12-02 a socket bound to a path costs about what an unnamed one
does, as sockets whose address length no bus has are no longer looked up (docs/measurements/hooks-cost/). Run it while you need it.
Check the machine
$ ls /sys/kernel/btf/vmlinux # the kernel describes its own types: needed
/sys/kernel/btf/vmlinux
$ uname -r # x86_64 from 5.5, 64-bit ARM from 6.0
6.12.118+deb13-amd64
$ cat /sys/kernel/security/lsm # bpf here only for --refuse
lockdown,capability,landlock,yama,apparmor,tomoyo,bpf,ipe,ima,evm
The 64-bit ARM programs have run only under emulation.
Build it
The part is behind the kernel feature, which compiles the in-kernel programs with clang for the BPF target
and needs libbpf's headers (clang and libbpf-dev on Debian):
$ cargo build --release --features kernel
LAMCO_BPF_CLANG names another clang. One build serves every kernel: The programs' kernel types are
relocated against the running kernel's when they load.
Run it as a service
Install the binary as /usr/bin/dbuskeep and the unit from packaging/systemd/system:
# install -m 755 target/release/dbuskeep /usr/bin/dbuskeep
# install -m 644 packaging/systemd/system/dbuskeep-kernel.service /usr/lib/systemd/system/
# systemctl enable --now dbuskeep-kernel
$ dbuskeep kernel-status
The unit gives it exactly CAP_BPF and CAP_PERFMON and takes every other capability out of its bounding
set. It answers at /run/lamco-dbus-tools/keep/kernel.sock. The system bus's events go to root and the
group lamco-dbus-monitor, and a user's bus's to that user.
Run as this unit on Debian 13, Fedora 44 with SELinux enforcing and Ubuntu 24.04
(docs/measurements/kernel-unit/), it serves the system bus and each user's own session bus, split at every
socket. On Fedora, restorecon gives the two files their labels after install. It runs as root with only its two capabilities, so it can't look inside
/run/user/UID to see whose the bus socket is; it holds the asker to the user of the bus's own process instead.
Run it for a while, by hand
$ sudo setpriv --reuid="$(id -u)" --regid="$(id -g)" --init-groups \
--inh-caps=-all,+bpf,+perfmon --ambient-caps=-all,+bpf,+perfmon --bounding-set=-all,+bpf,+perfmon \
--no-new-privs dbuskeep kernel --socket /var/tmp/kernel.sock &
$ export LAMCO_DBUS_TOOLS_KERNEL_SOCKET=/var/tmp/kernel.sock
It runs as you with only the two capabilities, so the events of your own buses are yours. Stop it with
SIGTERM, and the hooks are gone with it. It keeps events for --window seconds, 600 unless told, and at most
--max-events, 2,000,000 unless told, the oldest let go first: A recording longer than the window, or on a bus
busy enough to pass the count, loses its start, and kernel-status counts what was let go. For a long run:
dbuskeep kernel --socket /var/tmp/kernel.sock --window 3600 --max-events 10000000
Use it
Record with --kernel, and split the calls dbusdo made:
$ dbussee --quiet record --all --kernel --duration 6 --out rec.json &
$ dbusdo --out acts.json call --repeat 300 com.example.Lookup /lookup com.example.Lookup.Find s x
$ wait
$ dbustell timing rec.json --caller acts.json --split
How to time a call reads the output.
Refuse a connection
To refuse every connection from a cgroup, and the cgroups under it, to one bus:
# systemctl edit dbuskeep-kernel
[Service]
ExecStart=
ExecStart=/usr/bin/dbuskeep kernel --refuse /user.slice/user-1000.slice/user@1000.service/app.slice/untrusted.slice=/run/user/1000/bus
A program in that slice then gets EPERM from connect, before the bus sees it
(a program kept off a bus). It needs bpf among the
kernel's active security modules; Ubuntu 24.04 hasn't it, and there the service won't start with --refuse.
What can go wrong
dbuskeep kernel: This build hasn't the kernel part: It was built without--features kernel.the kernel describes no types of its own: The kernel was built without BTF.--refuse needs bpf among the kernel's active security modules: It isn't, as on Ubuntu 24.04. Run without--refuse, or boot withbpfadded to thelsm=list.dbussee record --kernelwithout the service running records as usual, and its capture says the kernel part wasn't reached.dbustell timing --splitthen exits 1.kernel-statuscounts headers split across two buffers: Those messages aren't reported. Some per thousand is expected, and up to a few in a hundred on a busy desktop: Four in 480 once on Debian 13, none in a run of the same script before it, and 402 of 18,024 events on Fedora 44 while GNOME was still starting.- Calls to a service built on sd-bus weren't split on a build before 2026-12-02: sd-bus's sockets have an address of their own, which the hooks took for the socket's and so never looked at the bus's. Fixed then.