Bug 8414

Summary: D-Bus policies are not properly applied
Product: [Build System, Metadata & Runtime] OE-Core Reporter: Jussi Kukkonen <jku>
Component: configurationAssignee: Jussi Kukkonen <jku>
Status: VERIFIED FIXED QA Contact: Cristian Iorga <cristian.iorga>
Severity: normal    
Priority: High CC: alexandru.c.georgescu, cristian.iorga, ross.burton
Version: unspecified   
Target Milestone: 2.0   
Hardware: x86   
OS: Multiple   
Whiteboard:
OS type for building Yocto: --- Type of Regression: ---
Verified: Documentation change: No (bug/feature does not impact docs)

Description Jussi Kukkonen 2015-09-29 08:36:47 UTC
It seems our D-Bus policies are not being correctly applied, at least not on sysvinit. My test case is connman (because I was fixing the policy): currently the policy has a "allow" policy to let everyone send messages to the service, but I modified /etc/dbus-1/system.d/connman.conf to look like this: 

<!DOCTYPE busconfig PUBLIC "-//freedesktop//DTD D-BUS Bus Configuration 1.0//EN"
 "http://www.freedesktop.org/standards/dbus/1.0/busconfig.dtd">
<busconfig>
    <policy user="root">
        <allow own="net.connman"/>
        <allow send_destination="net.connman"/>
        <allow send_interface="net.connman.Agent"/>
        <allow send_interface="net.connman.Counter"/>
        <allow send_interface="net.connman.Notification"/>
    </policy>
    <policy user="xuser">
        <allow send_destination="net.connman"/>
    </policy>
    <policy context="default">
        <deny send_destination="net.connman"/>
    </policy>
</busconfig>

System bus should have a default "deny send_destination", but I left one there anyway: only root and xuser should be allowed to send to net.connman.

Then I restarted dbus and connman, created a new user "tester", and as that user ran
    dbus-send --system --print-reply \
        --dest=net.connman \
        /net/connman/technology/wifi \
        net.connman.Technology.GetProperties

And got a real reply from the service. This also happens on fido. I expected to get a D-Bus access violation error, and that is indeed what happened with systemd (although I can't tell how that could affect things).


This issue is really only relevant to systems that use non-root users. I have not tested whether the "allow own" policies are applied or not.


I'm still thinking I might be doing something wrong here: advice is welcome.
Comment 1 Jussi Kukkonen 2015-09-29 08:45:56 UTC
A more useful test command (with actual results on qemu as well): 
    dbus-send --system --print-reply \
        --dest=net.connman \
        /net/connman/technology/ethernet \
        net.connman.Technology.GetProperties
Comment 2 Jussi Kukkonen 2015-09-29 13:48:01 UTC
I think it's bluetooth.conf.

  <policy context="default">
    <allow own="org.bluez"/>
    <allow send_destination="org.bluez"/>
    <allow send_interface="org.bluez.Agent1"/>
    <allow send_type="method_call"/>
  </policy>

I think the person writing this thought the allow rules are somehow combined: they are not, so this is ... not optimal: It allows anyone to own org.bluez on system bus and it allows anyone to send messages to anyone on system bus.


I'm not sure but I think the reason it happened to work once with systemd is that the order of applying rules seems non-deterministic: sometimes, connmans rule seems to override this one. This feels like dbus-daemon bug (even if the service-specific configuration files aren't supposed to do things like the example here).
Comment 3 Ross Burton 2015-09-29 18:07:03 UTC
Jussi has been digging into this, so reassigning back to him.
Comment 4 Jussi Kukkonen 2015-10-02 12:09:57 UTC
commit cdaa8fd9608d1c34a2e6c9f6d0c9dc6ced706859
Author: Jussi Kukkonen <jussi.kukkonen@intel.com>
Date:   Thu Oct 1 11:04:35 2015 +0300

    bluez5: Use upstream D-Bus policy
    
    The Bluez D-Bus policy is much too open and affects not just bluez but
    all system services: Use upstream policy configuration instead.
    
    This change has a chance of affecting other D-Bus services: the bug
    that is fixed here may have hidden problems in other policies.
    
    [YOCTO #8414]
    
    (From OE-Core rev: 0f6f87c60a6ffeff6b3f53d25f4023749103e262)
    
    Signed-off-by: Jussi Kukkonen <jussi.kukkonen@intel.com>
    Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
Comment 5 Cristian Iorga 2015-10-23 13:32:37 UTC
Tested by adding a user named ubik and by executing:

ubik@qemux86-64:~$ dbus-send --system --print-reply --dest=net.connman /net/connman/technology/ethernet net.connman.Technology.GetProperties
Error org.freedesktop.DBus.Error.AccessDenied: Rejected send message, 2 matched rules; type="method_call", sender=":1.13" (uid=1001 pid=934 comm="dbus-send --system --print-reply --dest=net.connma") interface="net.connman.Technology" member="GetProperties" error name="(unset)" requested_reply="0" destination="net.connman" (uid=0 pid=697 comm="/usr/sbin/connmand ")
ubik@qemux86-64:~$ exit
exit
root@qemux86-64:~# dbus-send --system --print-reply --dest=net.connman /net/connman/technology/ethernet net.connman.Technology.GetProperties
method return sender=:1.0 -> dest=:1.14 reply_serial=2
   array [
      dict entry(
         string "Name"
         variant             string "Wired"
      )
      dict entry(
         string "Type"
         variant             string "ethernet"
      )
      dict entry(
         string "Powered"
         variant             boolean true
      )
      dict entry(
         string "Connected"
         variant             boolean false
      )
      dict entry(
         string "Tethering"
         variant             boolean false
      )
   ]
root@qemux86-64:~#

For non-root ubik user, the system errors out a denied access.