Package: dbus-broker
Version: 37-5
Severity: important
Tags: patch upstream
User: [email protected]
Usertags: origin-ubuntu tenacious ubuntu-patch

Dear Maintainer,

The fix for #1123876 skips `interface` in `build_message_query()` when it is 
NULL, which also drops its NUL field separator. When a D-Bus method call has no 
interface (such as KDE Solid's `passphraseReply` when unlocking a LUKS drive), 
the kernel AppArmor DFA gets 5 fields instead of 6 and denies the call even if 
the profile has `dbus,`.

The attached patch defaults NULL `path`, `interface`, and `method` to `""` so 
their NUL separators are always written, matching `dbus-daemon`.

Upstream PR: https://github.com/bus1/dbus-broker/pull/477
Description: Keep NUL separators for NULL fields in AppArmor message queries
Author: Viktor Pashaiev <[email protected]>
Forwarded: https://github.com/bus1/dbus-broker/pull/477
---
diff --git a/src/util/apparmor.c b/src/util/apparmor.c
index cb2fd53..c18511f 100644
--- a/src/util/apparmor.c
+++ b/src/util/apparmor.c
@@ -251,18 +251,19 @@ static int build_message_query(
         char *qstr;
         int i = 0, len;
 
+        path = path ?: "";
+        interface = interface ?: "";
+        method = method ?: "";
+
         len = AA_QUERY_CMD_LABEL_SIZE;
         len += strlen(security_label) + 1;
         len += 1; /* AA_CLASS_DBUS */
         len += strlen(bustype) + 1;
         len += strlen(receiver_context) + 1;
         len += strlen(name) + 1;
-        if (path)
-                len += strlen(path) + 1;
-        if (interface)
-                len += strlen(interface) + 1;
-        if (method)
-                len += strlen(method) + 1;
+        len += strlen(path) + 1;
+        len += strlen(interface) + 1;
+        len += strlen(method) + 1;
 
         qstr = malloc(len);
         if (!qstr)
@@ -278,18 +279,12 @@ static int build_message_query(
         i += strlen(receiver_context) + 1;
         strcpy(qstr+i, name);
         i += strlen(name) + 1;
-        if (path) {
-                strcpy(qstr+i, path);
-                i += strlen(path) + 1;
-        }
-        if (interface) {
-                strcpy(qstr+i, interface);
-                i += strlen(interface) + 1;
-        }
-        if (method) {
-                strcpy(qstr+i, method);
-                i += strlen(method) + 1;
-        }
+        strcpy(qstr+i, path);
+        i += strlen(path) + 1;
+        strcpy(qstr+i, interface);
+        i += strlen(interface) + 1;
+        strcpy(qstr+i, method);
+        i += strlen(method) + 1;
 
         *queryp = qstr;
         *n_queryp = i - 1;

Reply via email to