D-Bus mediation
the bus daemon decides for application developers for administrators for security researchers
The parser compiles dbus rules into the profile and the kernel has no D-Bus hook. The bus daemon reads the label of each connection and asks the kernel through the .access file what that label allows and then delivers or drops the message itself and writes the record. A daemon that does not ask enforces nothing. The mainline kernel since 6.17 answers yes to every dbus question for a profile compiled under abi/3.0 or abi/4.0 and Ubuntu kernels do not.
On the map: libapparmor
▶ Watch this deck — 9 scenes, ~7 min
Worth seeing first
- D-Bus rules — the dbus rule and its conditionals
- Reading a denial — how to read a record and where records go
Part of journeys
- Network, IPC and privileges, step 12 of 14 · previous: Mount rules · next: Upstream and Ubuntu kernels
01 A dbus rule, and no kernel hook to check it
dbus rules are compiled into the profile, but the kernel has no D-Bus hook. The bus daemon asks the kernel what the profile allows and enforces the answer itself. This deck is for application developers, administrators and security researchers.
Demo's profile has a dbus rule for one service, org.demo. So what happens when demo calls the login service instead? Access denied. But who said no? Not the kernel. To the kernel that call is bytes on a unix socket; it has no idea what a D-Bus message is. The bus daemon said no. It looked at the message, asked the kernel what demo's profile allows, and refused to pass it on. This deck follows that question, reads the line the daemon logs, and then looks at the cases where nobody asks, or the answer is always yes. The rule syntax has its own deck.
Details and sources
Details
- Seen on a Debian sid guest (kernel 7.3.4, a distribution kernel without Ubuntu's AppArmor patches; dbus-daemon 1.16.4), with profiles compiled by the parser of the AppArmor commit the map describes. The example uses the system bus, because the system bus daemon writes audit records; the D-Bus rules deck uses the session bus.
- The rule on the slide is one of four dbus rules in the profile
demoof the runs. The others allowHello,GetId,RequestName,ReleaseName,AddMatchandRemoveMatchon the bus daemon itself, owningorg.demo.client, and receiving the signalChanged. Without a send rule forHelloa program cannot use the bus at all. - The full command was
aa-exec -p demo -- busctl --system call org.freedesktop.login1 /org/freedesktop/login1 org.freedesktop.login1.Manager ListSessions; it printedCall failed: Access deniedand exited 1.org.freedesktop.login1is systemd-logind, which is unconfined on the guest. dbus-sendshows the daemon's full error:Error org.freedesktop.DBus.Error.AccessDenied: An AppArmor policy prevents this sender from sending this message to this recipient; type="method_call", sender=":1.61" (uid=0 pid=1701 comm="dbus-send --system --print-reply --dest=org.freede" label="demo (enforce)") interface="org.freedesktop.login1.Manager" member="ListSessions" error name="(unset)" requested_reply="0" destination="org.freedesktop.login1" (uid=0 pid=764 comm="/usr/lib/systemd/systemd-logind" label="unconfined").- The kernel's only code for the dbus class is the query file
/sys/kernel/security/apparmor/.access(apparmorfs.c:859-898), the feature filefeatures/dbus/mask(apparmorfs.c:2662-2664) and a class name for records. No hook looks at D-Bus messages. - The connection to the bus is a unix socket and needs its own rules:
/run/dbus/system_bus_socket rw,and a unix rule. See Unix socket rules. - The bus daemon is in neither source tree the map describes. Statements about it come from the source package dbus 1.16.4-1 of Debian sid (
bus/apparmor.c, named by function) and from the runs; they have no pinned link.
02 The bus daemon asks, the kernel answers
The daemon reads the peer's label from the socket when a program connects. For each check it writes a query to /sys/kernel/security/apparmor/.access and reads back allow, deny, audit and quiet. libapparmor wraps this as aa_query_label().
It takes two steps. When demo connects, the daemon asks the socket who is at the other end, and the kernel answers with a label: demo. The daemon keeps it for as long as the connection lives. Then, for each message, it writes a question into the .access file in apparmorfs: this label, this bus, this destination, this path, interface and member. The kernel runs that string through demo's compiled profile, much as it would a file name, and hands back four masks: allow, deny, audit and quiet. What to do with them is the daemon's business. In libapparmor the whole exchange is one call, aa_query_label.
Details and sources
Details
- Seen on a Debian sid guest (kernel 7.3.4, a distribution kernel without Ubuntu's AppArmor patches; dbus-daemon 1.16.4), with profiles compiled by the parser of the AppArmor commit the map describes. The reply on the slide is what the kernel returned for exactly this question when it was written to
.accessby a test script as root. - The label of a connection: dbus-daemon calls
aa_getpeercon()on the connection's socket once, when the connection is set up (bus_apparmor_init_connection_confinement).int aa_getpeercon(int fd, char **label, char **mode);reads the socket optionSO_PEERSECand splitsdemo (enforce)into the label and the mode (kernel.c:1300-1320, kernel.c:1363-1400). - The question:
int aa_query_label(uint32_t mask, char *query, size_t size, int *allowed, int *audited);(kernel.c:1425-1510). The caller leaves room at the start ofquery; the function putslabeland a zero byte there, opens.access, writes the query once and reads 67 bytes. - The fields on the slide are joined by zero bytes after the label and one class byte. Their order in the string is bus, name, peer label, path, interface, member; see the reference below and the scene "Compiled by the parser, asked for by the bus daemon" in D-Bus rules.
- The reply is four lines:
allow 0x%08x,deny 0x%08x,audit 0x%08x,quiet 0x%08x(apparmorfs.c:1068-1070). Permission bits: send0x2, receive0x4, eavesdrop0x20, bind0x40(apparmor.h:60-65). For demo's own rule the reply wasallow 0x00008002; bit0x8000is added by the kernel to every permission set of an older-format table and is not a dbus permission. - libapparmor's verdict: allowed when every asked bit is in
allowand not indeny; to be logged when the query is refused and the bit is not inquiet, or allowed and the bit is inaudit(kernel.c:1498-1501). .accesshas mode 0666 (apparmorfs.c:2704). The kernel finds the label in the namespace of the writing task, starts from "everything allowed" and lets each profile of the label narrow the answer (apparmorfs.c:1022-1071). A label the kernel does not know makes the write fail withENOENT; the daemon then refuses the message and logsinfo=.- The feature file
features/query/label/permscontainsallow deny audit quiet. - The bus daemon is in neither source tree the map describes. Statements about it come from the source package dbus 1.16.4-1 of Debian sid (
bus/apparmor.c, named by function) and from the runs; they have no pinned link.
03 One message, two questions
send is asked of the sender's profile and receive of the recipient's, each with the other side's label as the peer. An unconfined side is not asked, and neither is anyone for a reply that was requested.
For a message from demo to the service, the daemon asks twice. May demo send this, to a peer with the service's label? And may the service receive it, from a peer labelled demo? Both answers must be yes. Here demo's rule covers the whole interface, but the service accepts only the Status method. So a Reset call is stopped by the receiver's profile, and the record names the service, not demo. Two shortcuts. A side that's unconfined isn't asked at all. And the reply to a call that got through goes back with no questions. You write rules for requests, not for answers.
Details and sources
Details
- Seen on a Debian sid guest (kernel 7.3.4, a distribution kernel without Ubuntu's AppArmor patches; dbus-daemon 1.16.4), with profiles compiled by the parser of the AppArmor commit the map describes.
org.demowas owned bydbus-test-tool echo --system --name=org.demo(package dbus-tests) running under the profiledemo-service; it answers every method call with an empty reply. - Seen:
aa-exec -p demo -- busctl --system call org.demo /org/demo org.demo.Api Statusreturned with exit status 0 and no record. The same call withResetprintedCall failed: Access denied. The record on the slide is that denial, without its prefixaudit: type=1107 audit(1794836373.212:170): pid=755 uid=993 auid=4294967295 ses=4294967295 subj=unconfined msg='and broken over three lines. - In a receive record
name=is the sender's unique name (:1.14); in a send record it is the destination. - Seen: an unconfined
busctlcallingStatusonorg.demowas refused as well, by the service's rule, which namespeer=(label=demo); the record hasmask="receive" label="demo-service" peer_label="unconfined". The unconfined sender was not asked about; the confined recipient was. - The reply:
demohas no receive rule for it anddemo-serviceno send rule, and theStatuscall still returned. dbus-daemon allows a requested reply, one that the recipient had asked for, without a query (bus_apparmor_allows_send, therequested_replybranch); an unrequested reply is queried like any message, and method returns and errors are not logged. - Signals are checked the same way, per recipient: a confined
dbus-monitorunderdemoreceived the signalChangedand notOther; the record wasoperation="dbus_signal" ... mask="receive" ... label="demo" peer_pid=1551 peer_label="unconfined". - When the recipient is the bus daemon itself (
org.freedesktop.DBus), the peer label is the daemon's own label,unconfinedon the guest. When a message would start a service, only the sender is asked. - The message is delivered only if both answers allow it. A profile in complain mode is treated as allowing and the record says
ALLOWED: see the reference below. - The bus daemon is in neither source tree the map describes. Statements about it come from the source package dbus 1.16.4-1 of Debian sid (
bus/apparmor.c, named by function) and from the runs; they have no pinned link.
04 Owning a name, and listening in
A bind query carries the bus and the name; an eavesdrop query only the bus. In a message query the name is the destination as the caller wrote it, so peer=(name=org.demo) does not match a call addressed to :1.11.
Two more questions, both shorter. When a program asks to own a name, the daemon asks the kernel about bind, with only the bus and the name. Demo has a rule for one name and gets it. A second name is refused, before the bus's own policy file is even looked at. When a program asks to see messages meant for others, the question is eavesdrop, with the bus alone. One more thing about names. The daemon passes on the destination exactly as the caller wrote it. Address the service by its connection number instead, and a rule that names the peer org.demo doesn't match.
Details and sources
Details
- Seen on a Debian sid guest (kernel 7.3.4, a distribution kernel without Ubuntu's AppArmor patches; dbus-daemon 1.16.4), with profiles compiled by the parser of the AppArmor commit the map describes. Commands are shortened on the slide where
...stands: each of the first three wasaa-exec -p demo -- busctl --system call org.freedesktop.DBus /org/freedesktop/DBus org.freedesktop.DBus ...withRequestName su NAME 0orAddMatch s "eavesdrop=true,type='signal',interface='org.demo.Api'". Theaa-exec -p demo --in front matters: the samebusctlcall toorg.demofrom an unconfined shell was refused, by the service's profile (the scene "One message, two questions"). Records are shown without their prefix and withoutapparmor="DENIED". u 1is the bus daemon's answer "you are now the primary owner". The guest's bus policy allowed root to own names starting withorg.demo; dbus-daemon asks AppArmor before it looks at that policy (bus/services.c, beforebus_client_policy_check_can_own).- The profile's rule is
dbus bind bus=system name=org.demo.client,. The feature file calls this permissionacquire; the rule and the record saybind. - The eavesdrop record:
operation="dbus_eavesdrop" bus="system" mask="eavesdrop" pid=1540 label="demo". dbus-daemon asks this for a match rule witheavesdrop=trueand forBecomeMonitor.dbus-monitortriesBecomeMonitorfirst, then an eavesdropping match, then a plain match; underdemothat left one send denial (interfaceorg.freedesktop.DBus.Monitoring) and one eavesdrop denial before it received anything. - The name: dbus-daemon puts the message's destination field into the query, or
org.freedesktop.DBuswhen the message has none. Seen: the call addressed to:1.11was refused with the record on the slide, although:1.11was the connection that ownedorg.demo. - By the same code a
denyrule withpeer=(name=org.demo)does not cover a call addressed to the unique name. This was derived from the source, not run.peer=(label=...)does not depend on how the caller addressed the message. - dbus-broker, by its source, asks once for every name the peer owns and refuses if any is refused. It was not run for this deck.
- The bus daemon is in neither source tree the map describes. Statements about it come from the source package dbus 1.16.4-1 of Debian sid (
bus/apparmor.c, named by function) and from the runs; they have no pinned link.
05 The denial is written by the bus daemon
A D-Bus record has type=1107 and the bus daemon's pid; the AppArmor fields are inside msg='...'. mask is the permission asked, label the profile asked, peer_label the other side. A session bus writes the same text to the system log.
Here's the refusal in the log. The type is 1107, a record from a user-space program, and the process ID in front is the bus daemon's, because the daemon wrote it. The AppArmor part sits inside the message field. Operation says it was a method call. Bus, path, interface and member are the words of the rule you'd write. Mask says which question failed, send or receive. Label is the profile that was asked; peer label is the other side. Read it like a file denial, and you have the rule. A user's session bus can't write audit records, so the same text lands in the system log.
Details and sources
Details
- Seen on a Debian sid guest (kernel 7.3.4, a distribution kernel without Ubuntu's AppArmor patches; dbus-daemon 1.16.4), with profiles compiled by the parser of the AppArmor commit the map describes. The record is quoted in full up to
peer_label; in the kernel log it is two lines, because dbus-daemon ends its text with a newline and the audit library appendsexe="/usr/bin/dbus-daemon" sauid=993 hostname=? addr=? terminal=?'after it.journalctl -k | grep apparmor=shows only the first line. There are two spaces afteroperation="dbus_method_call"; the slide breaks the line there. type=1107isUSER_AVC, a record sent by a user-space program. The kernel's own AppArmor records aretype=1400: see Reading a denial. With the audit daemon running, both kinds go to/var/log/audit/audit.log; without it, to the kernel log (dmesg,journalctl -k). No audit daemon ran on the guests, so the audit.log form of this record was not seen.- Before
msg=:pid=755 uid=993 subj=unconfineddescribe the bus daemon (usermessagebus, its own label). Insidemsg=:pid=1671is the process of the profile that was asked andpeer_pid=764the other side;peer_pidis missing when the peer is the bus daemon itself. operationisdbus_and the message type (dbus_method_call,dbus_signal), ordbus_bind, ordbus_eavesdrop.maskis one ofsend,receive,bind,eavesdrop.name: in a send record the destination as the caller wrote it, in a receive record the sender's unique name, in a bind record the name asked for.- The rule on the slide uses
peer=(label=unconfined)frompeer_label;peer=(name=org.freedesktop.login1)fromnameis the other choice. Neither is a recommendation to add it. apparmor="ALLOWED"appears for a profile in complain mode. Seen underdemo-complain: the login call, the name and the eavesdropping match all succeeded, each with anALLOWEDrecord.- The session bus: a bus started by the user
testerwithdbus-run-sessionloggedNov 16 13:40:24 aamap dbus-daemon[1687]: apparmor="DENIED" operation="dbus_method_call" bus="session" path="/org/freedesktop/DBus" interface="org.freedesktop.DBus" member="Hello" mask="send" name="org.freedesktop.DBus" pid=1688 label="demo" peer_label="unconfined"in the journal and no type 1107 record. The system bus daemon keeps the capability to write audit records (CapEff: 0000000020000000); a user's daemon does not have it and uses syslog. - dbus-broker writes type 1107 records too. On an Ubuntu 26.10 guest (dbus-broker 37-5ubuntu5):
apparmor="DENIED" operation="dbus_method_call" bus="system" path="/" interface="org.freedesktop.DBus" member="ListNames" mask="send" name="org.freedesktop.DBus" label="demo-dbus" peer_label="unconfined" exe="/usr/bin/dbus-broker" sauid=0 hostname=? addr=? terminal=?': one line, one space afteroperation, nopid=. - The bus daemon is in neither source tree the map describes. Statements about it come from the source package dbus 1.16.4-1 of Debian sid (
bus/apparmor.c, named by function) and from the runs; they have no pinned link.
06 When the bus daemon doesn't ask
dbus-daemon mediates only when AppArmor is enabled and features/dbus/mask exists, which mainline has from 6.17. Otherwise everything is delivered and nothing is logged. Its Features property lists AppArmor when it mediates; <apparmor mode="required"/> makes it refuse to start without.
All of this assumes a daemon that asks. When it starts, the bus daemon checks two things: is AppArmor on, and does the kernel's feature directory have a dbus entry? If not, it starts anyway and mediates nothing. Every message is delivered and nothing is logged. A daemon built without AppArmor behaves the same. Mainline kernels before 6.17 had no such entry. On a test machine with one of those, demo called the login service, took a name it had no rule for, and eavesdropped. To check a running bus, read its Features property: with mediation on, the list includes AppArmor. The bus configuration can also require it.
Details and sources
Details
- dbus-daemon decides once, at startup (
bus_apparmor_pre_init,bus_apparmor_full_init): it mediates if it was built with AppArmor,aa_is_enabled()is true and it can openfeatures/dbus/maskunder apparmorfs. It does not look at the file's content. Debian and Ubuntu build it with AppArmor and the audit library on Linux. - The mainline kernel has the
dbusfeature entry from 6.17 (apparmorfs.c:2662-2664, apparmorfs.c:2697); Ubuntu kernels have had it since at least 6.8. See Upstream and Ubuntu kernels. - Seen on a Debian 13 guest (kernel 6.12.116, dbus-daemon 1.16.2, linked with libapparmor): no
features/dbus/mask;Featuresprinted the three entries on the slide; under the profiledemoevery attempt of this deck succeeded with no record: the call to the login service, aResetcall to the confined service, owningorg.demo.other, the eavesdropping match and both signals. - On that kernel the parser also leaves the dbus rules out of the compiled profile. It says so only when asked:
Warning from profile demo (demo.sd): dbus rules not enforcedwith--warn=allor--warn=rule-not-enforced(dbus.cc:203, dbus.cc:220-223). See Kernel features and the policy ABI. - Seen on Debian sid and Ubuntu 26.04:
Featuresprintedas 4 "ActivatableServicesChanged" "AppArmor" "HeaderFiltering" "SystemdActivation", and the journal had[system] AppArmor D-Bus mediation is enabled. - The bus configuration element is
<apparmor mode="enabled"/>(the default: mediate if possible),"disabled"or"required". Withrequiredand no mediation dbus-daemon fails to start withAppArmor mediation required but not present. The configuration files shipped on the guests have no such element. Therequiredcase was read in the source, not run. - dbus-broker, by its source: its launcher reads
/sys/module/apparmor/parameters/enabledand requires the wordsacquire,sendandreceiveinfeatures/dbus/mask; without them it printsKernel is missing AppArmor DBus support.and continues without mediation. - A side that is unconfined is not asked about on any kernel, and neither is anyone for a requested reply: see the scene "One message, two questions".
- The bus daemon is in neither source tree the map describes. Statements about it come from the source package dbus 1.16.4-1 of Debian sid (
bus/apparmor.c, named by function) and from the runs; they have no pinned link.
07 Old ABI, new kernel: every answer is yes
On mainline 6.17 and later the kernel leaves a profile out of dbus queries unless it mediates the v9 network class, which profiles compiled under abi/3.0 or abi/4.0 do not. Their dbus rules load and are not consulted. Ubuntu kernels consult them.
Now the quiet case: the daemon asks, and the kernel says yes to everything. Since 6.17, mainline skips a profile in a D-Bus question unless the profile also uses the newer network mediation. A profile gets that only when its feature set has it. abi/5.0 does. abi/4.0 and abi/3.0 don't. So we changed one line of demo's profile to abi/4.0. On a mainline-based kernel its dbus rules were loaded and not consulted: the login call went through, with no record and no word from the parser. Ubuntu's kernels don't have that test; there, the profile was enforced.
Details and sources
Details
- Known discrepancy: Kernel: dbus rules of a profile compiled without
network_v9unix support are not consulted, so profiles that pin abi/3.0 or abi/4.0 get no dbus mediation. It is on the map's bug list under that title; this deck's runs are the first to reproduce it. - The test in the kernel: when a query's class is dbus and the profile does not mediate network class 15, the profile adds nothing to the answer, and the answer starts as "everything allowed" (apparmorfs.c:882-889, apparmorfs.c:1056-1065). The comment there gives the reason: "old user space does not correctly detect dbus mediation support so we may get dbus policy and requests when the abi doesn't support it. This can cause mediation regressions, so explicitly test for this situation." The test is in mainline from 6.17. None of the Ubuntu kernel sources read (6.8, 6.11, 6.14, 6.17, 7.0, 7.3) has it: 6.8 to 6.14 are older than the test, and Ubuntu 6.17, 7.0 and 7.3 revert the patch.
- The parser side: the marker for network class 15 is added only when both the kernel and the policy feature set have
network_v9/af_unix(parser_regex.c:1424-1432); the dbus marker and the dbus rules are added whenever both havedbus(parser_regex.c:1406-1408). The tree'sabi/3.0andabi/4.0listdbusand nonetwork_v9. - Seen on Debian sid (kernel 7.3.4, dbus-daemon 1.16.4).
demoanddemo-abi4differ only in the abi line.
| Profile | Compiled by | Reply to "send ListSessions to login1" | The call |
|---|---|---|---|
demo, abi <abi/5.0>, | the tree's parser | allow 0x00000000 | Access denied, record |
demo-abi4, abi <abi/4.0>, | the tree's parser | allow 0xffffffff ... quiet 0xffffffff | answered, no record |
demo-abi3, abi <abi/3.0>, | the tree's parser | allow 0xffffffff | answered, no record |
abi <abi/4.0>, | Debian's parser 5.0.2 | allow 0xffffffff | answered, no record |
| no abi rule | the tree's parser, no parser.conf | allow 0xffffffff | answered, no record |
| no abi rule | Debian's parser with its parser.conf | allow 0x00000000 | Access denied, record |
- The same four profiles also acquired
org.demo.other, registered an eavesdropping match and received both signals, with no record. - A profile with no abi rule is compiled against the parser's built-in default feature set unless parser.conf sets
policy-features; that default hasdbusand nonetwork_v9(default_features.c:127-136). Debian's parser.conf points to a file that has both. - Seen on Ubuntu 26.04 (kernel 7.0.0-43, dbus-daemon 1.16.2): all six profiles were answered by their rules and every attempt was refused and logged.
- What the parser printed for
demo-abi4on Debian sid: nothing by default. With--warn=all: a note that an included abstraction declares another abi, and three timesdowngrading extended network unix socket rule to generic network rule. Nothing about dbus. - What pins what: every abi rule in the profiles of the AppArmor tree is
abi <abi/5.0>,. Profiles written for the 3.x and 4.x releases pin abi/3.0 and abi/4.0: the Debian 13 guest ships 97 profiles withabi <abi/4.0>,, four of them with dbus rules or dbus abstractions; the Ubuntu 26.04 guest ships three withabi <abi/3.0>,. - To check a loaded profile, ask the kernel directly: the reply
allow 0xffffffffto a dbus question about a confined label means the profile was skipped. A script that does it is in the research notes of this deck.
08 What you are trusting for security researchers
The enforcement point is the bus daemon. It takes the label at connect time, skips peers labelled unconfined, applies complain mode itself and believes the kernel's reply. .access has mode 0666. A name is a claim; peer=(label=...) names the confinement.
For an audit, be clear about what does the enforcing. It's a user-space process, and it trusts three things. The label, which it takes once, when the connection is made, not per message. The word unconfined: a peer with that label isn't asked about. And the kernel's answer, which on a mainline kernel allows everything for any profile compiled against an older feature set. Complain mode is the daemon's doing too; it reads the mode next to the label. And the .access file is open to everyone, so any process that can reach it can ask what any label may do. Bus names are claims. Prefer a peer label.
Details and sources
for security researchers
Details
- The label: dbus-daemon stores the result of
aa_getpeercon()when the connection is set up and uses it for every later check (bus_apparmor_init_connection_confinement; kernel.c:1363-1400). Derived, not run: a program that changes profile after connecting is still asked about under the label of the connection. - Unconfined: the daemon skips the query when the mode is
unconfined, or when there is no mode and the label is the stringunconfined(is_unconfined). The kernel does the same on its side: an unconfined profile leaves the answer at "everything allowed" (apparmorfs.c:867-868). - The kernel's answer: see the scene "Old ABI, new kernel: every answer is yes". Seen on Debian sid:
allow 0xffffffff deny 0x00000000 audit 0x00000000 quiet 0xfffffffffor every dbus question about a profile compiled under abi/3.0 or abi/4.0, the same reply as forunconfined. - Complain mode: the reply for a complain-mode profile is the same as for an enforcing one (
allow 0x00000000for the login call underdemo-complain); the daemon turns the refusal intoALLOWEDbecause the mode string that came with the label iscomplain. - A failed query (unknown label, no
.access) is a refusal withinfo=in the record, by the source; not run. .accessis-rw-rw-rw- 1 root rooton the guests (apparmorfs.c:2704). The kernel code has no check of the caller before it answers a permission query (apparmorfs.c:1204-1240); a confined task needs a file rule for the path. The answer reveals what a label may do, for any class the query names.- A label that nothing runs under and no profile has, such as the stack
demo//&demo-abi4, gotENOENT(seen). For a live stack the kernel intersects the profiles' answers (apparmorfs.c:1056-1065); not run. - Names:
peer=(name=...)is as strong as thebindrules of every other profile on the bus, and unconfined programs are not bound by them. With dbus-daemon the name is also the destination as the caller wrote it (the scene "Owning a name, and listening in"). - A session bus is started by the user it serves. Whether that daemon mediates, and with which configuration, is in that user's hands.
- The bus daemon is in neither source tree the map describes. Statements about it come from the source package dbus 1.16.4-1 of Debian sid (
bus/apparmor.c, named by function) and from the runs; they have no pinned link.
for security researchers
Read more
09 From the bus to the rule, the record and the kernel
Check that the bus's Features property lists AppArmor, that features/dbus/mask exists, and, on a mainline kernel, that the profile is compiled under abi/5.0. Roads: the rule syntax, reading records, upstream and Ubuntu kernels, the abi rule, kernel features, the query interface and unix socket rules.
So a dbus rule is only as good as the daemon that asks and the kernel that answers. On your own system, check three things. The bus's Features property lists AppArmor. The kernel's feature directory has a dbus entry. And on a mainline kernel, the profile pins abi/5.0. From here, the D-Bus rules deck is where you write the rules, and reading a denial covers records in general. Upstream and Ubuntu kernels lists what else differs, and the abi rule deck explains that one line. Kernel features lists what your kernel offers, the query interface sits underneath, and unix socket rules cover the hop to the bus.
Details and sources
Details
- A dbus rule is enforced when three things hold: the bus daemon mediates (its
Featuresproperty listsAppArmor), the kernel has thedbusfeature entry, and the kernel consults the profile, which on mainline 6.17 and later needs a profile compiled with the v9 network class (abi <abi/5.0>,). A profile with no abi rule is compiled with that class only ifpolicy-featuresin parser.conf names a feature file that hasnetwork_v9; see the scene "Old ABI, new kernel: every answer is yes". - The three checks of the slide, in full:
busctl --system get-property org.freedesktop.DBus /org/freedesktop/DBus org.freedesktop.DBus Features(seen:as 4 "ActivatableServicesChanged" "AppArmor" "HeaderFiltering" "SystemdActivation"when the daemon mediates);cat /sys/kernel/security/apparmor/features/dbus/mask(seen:acquire send receive); the abi line of the profile, anduname -rto know which kernel answers. For a session bus usebusctl --user. - Commits read for this deck: AppArmor 836052d21 (6.0.0~alpha2) and the kernel tree named on the page; Ubuntu kernel tags 6.8 to 7.3; the source packages dbus 1.16.4-1, dbus 1.16.2-2ubuntu4 and dbus-broker 37-5 and 37-5ubuntu5. Behaviour was observed on Debian sid (kernel 7.3.4), Ubuntu 26.04 (kernel 7.0.0-43) and Debian 13 (kernel 6.12.116) guests.
Read more
- apparmor.d(5), DBus rules, wiki: AppArmorDBus, aa_query_label(2), wiki: AppArmorTrustedHelpers.
- D-Bus rules, Reading a denial, Upstream and Ubuntu kernels, The abi rule and the abi files, Kernel features and the policy ABI, Querying the policy, Unix socket rules.
- Profile mode flags, Choosing abstractions, What is not mediated.
Read more
Basis of the statements on this page: "seen" means it happened on a running guest: Debian sid (kernel 7.3.4, a distribution kernel without Ubuntu's AppArmor patches, dbus-daemon 1.16.4), Ubuntu 26.04 (kernel 7.0.0-43, dbus-daemon 1.16.2) or Debian 13 (kernel 6.12.116, dbus-daemon 1.16.2), under profiles compiled by the parser of the AppArmor commit 836052d21 unless another parser is named. "source" means the code was read and not run: the kernel tree the map describes, the AppArmor tree, the Ubuntu kernel tags 6.8 to 7.3, and the source packages dbus 1.16.4-1 and dbus-broker 37-5 and 37-5ubuntu5. The bus daemons are in neither tree the map describes, so statements about them carry no pinned link. Records are quoted without the prefix audit: type=1107 audit(SECONDS:SERIAL): pid=755 uid=993 auid=4294967295 ses=4294967295 subj=unconfined msg='. The rule syntax is in D-Bus rules.
When a dbus rule is enforced
All three must hold.
| Condition | How to check | If not |
|---|---|---|
| the bus daemon mediates | busctl --system get-property org.freedesktop.DBus /org/freedesktop/DBus org.freedesktop.DBus Features lists AppArmor; the journal has AppArmor D-Bus mediation is enabled | every message is delivered, nothing is logged |
| the kernel has the dbus feature entry | /sys/kernel/security/apparmor/features/dbus/mask exists (acquire send receive) | the daemon does not mediate; the parser leaves dbus rules out (dbus rules not enforced, only with --warn=rule-not-enforced or --warn=all) |
| the kernel consults the profile | a dbus question about the label is not answered allow 0xffffffff | every question about that profile is answered "allowed", nothing is logged |
| Kernel | dbus feature entry | Profiles consulted in a dbus query |
|---|---|---|
| mainline before 6.17 (seen: Debian 13, 6.12) | no | none: no mediation |
| mainline 6.17 and later (seen: Debian sid, 7.3) | yes | only profiles that mediate the v9 network class |
| Ubuntu 6.8 to 7.3 (seen: Ubuntu 26.04, 7.0) | yes | every profile with the dbus class |
The bus daemon's switch
| dbus-daemon | Mediates |
|---|---|
| built without AppArmor | no |
AppArmor disabled in the kernel, or features/dbus/mask cannot be opened | no |
<apparmor mode="disabled"/> in the bus configuration | no |
<apparmor mode="enabled"/> or no such element (the default) | if the two conditions above allow |
<apparmor mode="required"/> | yes, or it fails to start: AppArmor mediation required but not present |
Source. The decision is made once, at startup. dbus-broker's launcher makes the same decision from /sys/module/apparmor/parameters/enabled and the words acquire, send and receive in features/dbus/mask, and prints Kernel is missing AppArmor DBus support. or AppArmor required, but not supported. Exiting.
The checks
| Event | Permission | Label asked | Fields in the question | Not asked when |
|---|---|---|---|---|
| a message is to be delivered | send | the sender's | bus, destination name, recipient's label, path, interface, member | the sender is unconfined; the message is a requested reply |
| the same message | receive | the recipient's | bus, sender's unique name, sender's label, path, interface, member | the recipient is unconfined; requested reply; the message would start a service |
RequestName | bind | the caller's | bus, name | the caller is unconfined |
AddMatch with eavesdrop=true, BecomeMonitor | eavesdrop | the caller's | bus | the caller is unconfined |
- The label is the one the socket reported when the program connected (
aa_getpeercon), with its mode. - The destination name is the message's destination field as written, or
org.freedesktop.DBuswhen there is none. When the recipient is the bus daemon, the recipient's label is the daemon's own. - A message is delivered only if both questions allow it. A profile in complain mode counts as allowing; the record then says
ALLOWED. - A question that fails (the kernel does not know the label,
.accessis missing) refuses the message; the record hasinfo=. Source. - A broadcast signal is checked once per recipient.
Seen: the attempts of this deck
Debian sid; Ubuntu 26.04 gave the same results.
| Attempt | Result | Record |
|---|---|---|
demo calls org.demo Status | empty reply | none |
demo calls org.demo Reset | Call failed: Access denied | operation="dbus_method_call" mask="receive" label="demo-service" peer_label="demo" |
unconfined caller, org.demo Status | denied | mask="receive" label="demo-service" peer_label="unconfined" |
demo calls :1.11, the owner of org.demo, Status | denied | mask="send" name=":1.11" label="demo" peer_label="demo-service" |
demo calls login1 ListSessions | denied | mask="send" name="org.freedesktop.login1" label="demo" peer_label="unconfined" |
demo RequestName org.demo.client | u 1 | none |
demo RequestName org.demo.other | denied | operation="dbus_bind" name="org.demo.other" mask="bind" label="demo" |
demo AddMatch "eavesdrop=true,..." | denied | operation="dbus_eavesdrop" mask="eavesdrop" label="demo" |
signal Changed to a dbus-monitor under demo | received | none |
signal Other to the same | not received | operation="dbus_signal" mask="receive" label="demo" peer_label="unconfined" |
demo-complain: login1, org.demo.other, eavesdrop | all succeed | the same records with apparmor="ALLOWED" |
The rules behind them:
# profile demo
dbus send bus=system path=/org/freedesktop/DBus interface=org.freedesktop.DBus
member={Hello,GetId,RequestName,ReleaseName,AddMatch,RemoveMatch}
peer=(name=org.freedesktop.DBus),
dbus send bus=system path=/org/demo interface=org.demo.Api peer=(name=org.demo),
dbus bind bus=system name=org.demo.client,
dbus receive bus=system path=/org/demo interface=org.demo.Api member=Changed,
# profile demo-service
dbus send bus=system path=/org/freedesktop/DBus interface=org.freedesktop.DBus
peer=(name=org.freedesktop.DBus),
dbus bind bus=system name=org.demo,
dbus receive bus=system path=/org/demo interface=org.demo.Api member=Status peer=(label=demo),What the client sees
| Refusal | D-Bus error org.freedesktop.DBus.Error.AccessDenied with the text |
|---|---|
| a message | An AppArmor policy prevents this sender from sending this message to this recipient; type="method_call", sender=":1.61" (uid=0 pid=1701 comm="..." label="demo (enforce)") interface="..." member="..." error name="(unset)" requested_reply="0" destination="org.freedesktop.login1" (uid=0 pid=764 comm="..." label="unconfined") (seen; the same text when the recipient's profile refuses) |
| a name | Connection "..." is not allowed to own the service "..." due to AppArmor policy (source) |
| eavesdropping | Connection "..." is not allowed to eavesdrop due to AppArmor policy (source) |
busctl prints only Call failed: Access denied.
Record fields
| Field | Meaning | Rule part |
|---|---|---|
type=1107 | USER_AVC: sent by a user-space program | |
pid=, uid=, subj= before msg= | the bus daemon's pid, user and own label | |
apparmor= | DENIED; ALLOWED for complain mode or an audited allowed access | |
operation= | dbus_method_call, dbus_signal, dbus_bind, dbus_eavesdrop | the kind of rule |
bus= | system or session | bus= |
path=, interface=, member= | the message's header fields; absent when the message has none | path=, interface=, member= |
mask= | send, receive, bind or eavesdrop | the permission |
name= | send: the destination as written; receive: the sender's unique name; bind: the name asked for | peer=(name=...); name= in a bind rule |
pid= inside msg= | the process of the label that was asked | |
label= | the label that was asked | the profile to edit |
peer_pid=, peer_label= | the other side; peer_pid is absent when it is the bus daemon | peer=(label=...) |
info=, peer_info= | the error text when the question itself failed | |
exe=, sauid=, hostname=, addr=, terminal= | added by the audit library |
- Seen: in the kernel log a dbus-daemon record is two lines; the second is
exe="/usr/bin/dbus-daemon" sauid=993 hostname=? addr=? terminal=?'. The first line has no closing quote. - Seen: a session bus started by an ordinary user logs
dbus-daemon[PID]: apparmor="DENIED" ...to the system log and no type 1107 record. - Not logged: an allowed access without
audit; method returns and errors; anything when the daemon does not mediate or the kernel skips the profile. - Source: a refusal is logged unless the profile's
quietmask has the bit (adenyrule); an allowed access is logged when theauditmask has it. Not run. - Where records go and how the tools read them: Reading a denial.
Which profiles the mainline kernel consults
Seen on Debian sid (kernel 7.3.4). The six profiles have the same dbus rules.
| Profile | abi rule | Compiled by | Reply to a dbus question | login1 call, org.demo.other, eavesdrop, signal Other |
|---|---|---|---|---|
demo | abi <abi/5.0>, | tree parser | by the rules | refused, logged |
demo-abi4 | abi <abi/4.0>, | tree parser | allow 0xffffffff deny 0x00000000 audit 0x00000000 quiet 0xffffffff | all succeed, no record |
demo-abi3 | abi <abi/3.0>, | tree parser | the same | all succeed, no record |
demo-distro4 | abi <abi/4.0>, | Debian's parser 5.0.2 | the same | all succeed, no record |
demo-noabi | none | tree parser, no parser.conf | the same | all succeed, no record |
demo-distro-noabi | none | Debian's parser, parser.conf with policy-features= | by the rules | refused, logged |
- Seen on Ubuntu 26.04 (kernel 7.0.0-43): all six were answered by the rules and refused.
- Known discrepancy: Kernel: dbus rules of a profile compiled without
network_v9unix support are not consulted, so profiles that pin abi/3.0 or abi/4.0 get no dbus mediation. - The kernel test: apparmorfs.c:882-889, in mainline from 6.17; absent from the Ubuntu kernel sources 6.8, 6.11, 6.14, 6.17, 7.0 and 7.3 (source): the first three are older than the test, the others revert it.
- Policy feature sets with
dbusand withoutnetwork_v9in the AppArmor tree:abi/3.0,abi/4.0,abi/4.0-ip,abi/kernel-5.4-outoftree-network, and the parser's built-in default for profiles without an abi rule (default_features.c:127-136). With it:abi/5.0,abi/5.0-interface. - The parser adds the class marker the kernel tests for only when the policy feature set has
network_v9/af_unix(parser_regex.c:1424-1432). It printed nothing about dbus fordemo-abi4, with or without--warn=all. - Shipped profiles (seen): AppArmor tree, every abi rule is 5.0; Debian sid, 141 files with 5.0 and 2 without an abi rule; Ubuntu 26.04, 147 with 5.0, 3 with 3.0 and 4 without; Debian 13, 97 with
abi <abi/4.0>,.
for application developers for security researchers
The query and the reply
write: "label" 00 LABEL 00 20 BUS 00 NAME 00 PEERLABEL 00 PATH 00 INTERFACE 00 MEMBER send, receive
"label" 00 LABEL 00 20 BUS 00 NAME bind
"label" 00 LABEL 00 20 BUS eavesdrop
read: allow 0x%08x\ndeny 0x%08x\naudit 0x%08x\nquiet 0x%08x\n
- File:
/sys/kernel/security/apparmor/.access, mode 0666, one write and one read per open (apparmorfs.c:1204-1240, apparmorfs.c:1022-1071).20is the dbus class, 32. int aa_query_label(uint32_t mask, char *query, size_t size, int *allowed, int *audited);(kernel.c:1425-1510). The firstAA_QUERY_CMD_LABEL_SIZEbytes ofqueryare overwritten withlabeland a zero byte.- Bits: send
0x2, receive0x4, eavesdrop0x20, bind0x40. Bit0x8000in a reply is added by the kernel and is not a dbus permission. allowed: every asked bit is inallowand none indeny.audited: refused and not inquiet, or allowed and inaudit(kernel.c:1498-1501).- Errors:
ENOENTthe kernel does not know the label;EPROTONOSUPPORTno.accessor an unexpected reply;EPROTOa short write or read. - Seen replies:
demo, sendStatustoorg.demo:allow 0x00008002; sendListSessionsto login1:allow 0x00000000; bindorg.demo.client:allow 0x00008040;demo-service, receiveStatusfrom labeldemo:allow 0x00008004, fromunconfined:allow 0x00000000; labelunconfined:allow 0xffffffff ... quiet 0xffffffff; an unknown label and the unused stackdemo//&demo-abi4:ENOENT. - A stacked label is answered with what every profile in it allows (source).
- More on the interface: Querying the policy.
dbus-broker
Source only (37-5 as packaged by Debian and Ubuntu 26.04, 37-5ubuntu5 of Ubuntu 26.10); not run for this deck.
- The same three kinds of question through
aa_query_label. - For a message it asks once for each name the peer owns and refuses if any is refused; a peer with no name is asked with its unique id. dbus-daemon asks with the one name the caller wrote.
- Records are type 1107. In 37-5 a message record has
method=where dbus-daemon hasmember=and noname=; 37-5ubuntu5 writesmember=,name=,label=andpeer_label=. A record of 37-5ubuntu5 seen on an Ubuntu 26.10 guest:apparmor="DENIED" operation="dbus_method_call" bus="system" path="/" interface="org.freedesktop.DBus" member="ListNames" mask="send" name="org.freedesktop.DBus" label="demo-dbus" peer_label="unconfined" exe="/usr/bin/dbus-broker" sauid=0 hostname=? addr=? terminal=?'.
Not determined
- The form of a type 1107 record in
/var/log/audit/audit.log; no guest ran the audit daemon. - A question about the stacked label of a running program, and a bus daemon inside a policy namespace.
- dbus-broker's handling of replies and signals.
Roads from here
START HERE
- Upstream and Ubuntu kernels — what else differs between mainline and Ubuntu kernels
PREAMBLE AND REUSE
- The abi rule and the abi files — the abi rule that decides whether dbus rules count on mainline
PROFILE HEAD
- Profile mode flags — complain mode which the bus daemon honours
RULE CLASSES
- D-Bus rules — the rule syntax this deck does not repeat
- Unix socket rules — the socket rule for reaching the bus at all
IN PRACTICE · general-purpose apps
- Choosing abstractions — the dbus abstractions shipped with AppArmor
SECURITY · threat model and limits
- What is not mediated — what nothing checks
RUNNING THE PARSER
- Reading a denial — reading records field by field
- Kernel features and the policy ABI — the feature directory the bus daemon looks at
LIBAPPARMOR
- Querying the policy (no slides yet) — the query interface the bus daemon uses