Files
finit/test/dbus-authz.sh
T
Joachim Wiberg 3231ade38a dbus: fixes from a code review of the branch
A pass over the whole branch before merge, mostly in libink since
that is the new code and the part exposed to the wire.  Grouped here
rather than scattered so the review is easy to read in one place.

libink parser and dispatch:

 - Bound reader lengths so a 32-bit size_t can't wrap a wire length
   past the guard and read out of bounds.  Reachable pre-auth on any
   bus, so it matters on the 32-bit targets Finit runs on.
 - Drop a peer when a reply send fails instead of limping on with a
   half-written frame; a built-in whose send failed used to fall
   through and put a second frame on the wire.

initctl:

 - Copy a D-Bus error name out of the reply before closing the client;
   the reply points into memory the close frees.  Both error paths now
   share one helper so this can't creep back.

Authorization:

 - Take the caller's groups from the kernel (SO_PEERCRED plus
   SO_PEERGROUPS) rather than getpwuid()/getgrouplist(), which go
   through NSS and can block PID 1 on a slow LDAP or SSSD backend.
   The check is now a lookup against the group resolved once at init,
   with no NSS and no 256 KiB array on the stack.  A caller reaching
   us through a broker carries no group set, so system-bus privileged
   methods are root-only; the local bus keeps group support.  See
   libink/README.md for the note on lifting that.

Shutdown:

 - Call dbus_exit() from the shutdown path so the server, its peers,
   and the socket are let go cleanly.  The teardown existed but nobody
   called it.

Tests, CI, docs:

 - A fuzz target for the message parser, run as a quick sweep in the
   suite and properly under libFuzzer in CI, with the corpus carried
   between runs.  The -as-uid tests drop groups the way a login does
   so SO_PEERGROUPS sees the right set, and widen the test socket to
   reach the per-method check behind the 0660 gate.  Bring the GitHub
   actions up to versions that run on Node 24, and tidy a few small
   things a /simplify pass turned up.

Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
2026-08-16 08:57:38 +02:00

57 lines
2.0 KiB
Bash
Executable File

#!/bin/sh
# Who may invoke a privileged method. Root always, and anyone in the
# group the bus socket is owned by, which is DEFGROUP from
# --with-group, 'root' in a test build. Everyone else is refused.
#
# A caller that gets past the check still has to name a service that
# exists, so NoSuchService is how we tell "allowed, then failed" apart
# from "not allowed at all".
set -eu
TEST_DIR=$(dirname "$0")
# shellcheck source=/dev/null
. "$TEST_DIR/lib/setup.sh"
# shellcheck source=/dev/null
. "$TEST_DIR/lib/dbus-setup.sh"
# uid 1000 is 'wheelie', a member of group root in the test sysroot.
# uid 2 is 'bin', a member of nothing that matters here.
say "A member of the group may call a privileged method"
set +e
allowed=$(texec "$CLIENT" call-s-as-uid 1000 "$BUS" /org/finit/manager \
org.finit.Manager1 Restart nosuchservice 2>&1)
set -e
case "$allowed" in
*AccessDenied*) fail "Group member was refused: $allowed" ;;
*NoSuchService*) assert "Group member passed authorization" 0 -eq 0 ;;
*) fail "Unexpected reply for group member: $allowed" ;;
esac
# uid 2 is outside the group, so 0660 would stop it at connect; widen
# the test socket so the refusal comes from the method, which is the
# layer under test here.
bus_open_to_all
say "A caller outside the group may not"
set +e
denied=$(texec "$CLIENT" call-s-as-uid 2 "$BUS" /org/finit/manager \
org.finit.Manager1 Restart nosuchservice 2>&1)
set -e
case "$denied" in
*AccessDenied*) assert "Non-member refused" 0 -eq 0 ;;
*NoSuchService*) fail "Non-member passed authorization: $denied" ;;
*) fail "Unexpected reply for non-member: $denied" ;;
esac
say "Root is still allowed"
set +e
asroot=$(texec "$CLIENT" call-s "$BUS" /org/finit/manager \
org.finit.Manager1 Restart nosuchservice 2>&1)
set -e
case "$asroot" in
*AccessDenied*) fail "Root was refused: $asroot" ;;
*NoSuchService*) assert "Root passed authorization" 0 -eq 0 ;;
*) fail "Unexpected reply for root: $asroot" ;;
esac