Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

DBus filtering enhancements #3406

Merged
merged 6 commits into from
Jun 1, 2020
Merged

DBus filtering enhancements #3406

merged 6 commits into from
Jun 1, 2020

Conversation

kris7t
Copy link
Collaborator

@kris7t kris7t commented May 7, 2020

This PR exposes additional functionalities from xdg-dbus-proxy:

  • --dbus-user.see and --dbus-system.see allow setting the SEE policy for DBus names.

  • --dbus-{user,system}.{call,broadcast} allows setting per interface and per object path policies. For example, we can set

    dbus-user.call org.freedesktop.Notifications=org.freedesktop.Notifications.*@/org/freedesktop/Notifications
    dbus-user.broadcast org.freedesktop.Notifications=org.freedesktop.Notifications.*@/org/freedesktop/Notifications
    

    to safely allow notifications without exposing additional objects (e.g. /org/gnome/Shell).

  • --dbus-{user,system}.log to turn on DBus proxy logging (implement xdg-dbus-proxy --log / log denied D-Bus access tries #3402). Unfortunately, this is not as useful as it may seem, because without --filer, xdg-dbus-proxy --log will not actually log anything. So we can use the options for debugging applications that fail due to DBus filters, but not for building DBus profiles from scratch.

In addition, this PR updates faudit so it won't report MAYBE when DBus filters are in effect (#3326 (comment)).

A next step would be to either find a better DBus logging option (maybe with dbus-monitor), or stay with this one, and create some contrib scripts to generate filter rules from (rejected) DBus communications.

kris7t and others added 5 commits May 7, 2020 01:56
The SEE policy of xdg-dbus-proxy allows clients to see objects and bus
names, but not interact with them. The --call and --broadcast can allow
interactions with objects that have the SEE policy set. Profile support
for these proxy options will be added in a future commit.
This allows setting per-member and per-object path policies for
xdg-dbus-proxy.
--dbus-user.log and --dbus-system.log instruct xdg-dbus-proxy to log
interactions with the session and system buses, respectively.
--dbus-log= can specify the location of the log file. If no location is
specified, log output is written to stdout.
D-Bus audit is now more in line with D-Bus filtering settings:
* Checks both the DBUS_SESSION_BUS_ADDRESS and DBUS_SYSTEM_BUS_ADDRESS
  environment variables.
* Also checks common paths for fallback sockets in /run.
* Will report GOOD when D-Bus filtering is enabled.
@kris7t kris7t requested a review from rusty-snake May 7, 2020 00:31
Copy link
Collaborator

@rusty-snake rusty-snake left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Becoming complex 🤯.

  1. dbus-{user,system}.see will be mostly to unbreak apps while still restricting those addresses. Right?
  2. dbus-{user,system}-log 🥇
  3. dbus-{user,system}.{call,broadcast} does dbus-user.call org.freedesktop.Notifications=org.freedesktop.Notifications.*@/org/freedesktop/Notifications imply dbus-user.talk org.freedesktop.Notifications (with restirction)? If so, we could provide a include dbus.inc(with a better name) that is included and restricts common addresses. Like
include dbus.inc
dbus-user filter
dbus-user.talk org.freedesktop.Notifications

which would allow o.f.N, but only as o.f.N.

@kris7t
Copy link
Collaborator Author

kris7t commented May 7, 2020

  1. Well, it means the app can find out that the bus name is being held by someone, and retrieve the objects from that bus name by introspection. So the app will know that it shouldn't take ownership of the name. However, if it tries to talk to objects exposed by the bus name, it will still fail, and may crash the application if it is not prepared for D-Bus errors.
  2. Yeah, it works to some extends, but not as useful as I'd hoped (no logging unless filtering is active).
  3. call and broadcast imply see (and potentially relax it). So if you have dbus-user.call org.freedesktop.Notifications=org.freedesktop.Notifications.*@/org/freedesktop/Notifications, that means the application can see the org.freedesktop.Notifications name, but only method calls of the interface org.freedesktop.Notifications to the object /org/freedesktop/Notifications will be successful. So it is pointless to combine this with talk, which would relax the policy even further (any method call succeeds and any signal can be received). call/broadcast should mostly be used in pairs, e.g., if you have call on org.freedesktop.Notifications, but not broadcast, you won't be called back if the user click the notification. So we could have something like dbus-notifications.inc with:
dbus-user.call org.freedesktop.Notifications=org.freedesktop.Notifications.*@/org/freedesktop/Notification
dbus-user.broadcast org.freedesktop.Notifications=org.freedesktop.Notifications.*@/org/freedesktop/Notification

and then

include dbus-notifications.inc

in any profile that needs access to the notification daemon.

@kris7t
Copy link
Collaborator Author

kris7t commented Jun 1, 2020

Sorry for not checking back earlier, I was unfortunately very busy with projects at uni.

Does this look good to merge?

@rusty-snake
Copy link
Collaborator

From the (low-level) profile interface standpoint, yes.

@kris7t kris7t merged commit 18f99d1 into netblue30:master Jun 1, 2020
@kris7t kris7t deleted the dbus-proxy branch June 1, 2020 16:22
@rusty-snake
Copy link
Collaborator

@kris7t xdg-dbus-proxy is started with arg0=3 which looks really strength in system-monitoing tools.

Screenshot_2020-06-02_00-17-31-fs8

@glitsj16
Copy link
Collaborator

glitsj16 commented Jun 1, 2020

Confirming @rusty-snake's observation. E.g. when running dconf-editor the xdg-dbus-proxy process shows up with process names 0 in gnome-system-monitor. Not sure if there is anything that can be done about it, but if that's the case we can add it to the wiki page to avoid confused users filing issues on it.

@kris7t
Copy link
Collaborator Author

kris7t commented Jun 2, 2020

@rusty-snake @glitsj16 That might be a side effect of using fexecve to start /usr/bin/xdg-dbus-proxy and gnome-system-monitor getting a bit confused. argv[0] should certainly be "/usr/bin/xdg-dbus-proxy", but this is a bit weird, because we are starting it from and fd and not a path (#3241). This is done so that there is TOCTOU bug when we refuse to execute binaries that are world-writable or not owned by root during sandbox setup (the sandboxed binary itself can have any permissions, but we try to be a bit more stringent during sandbox setup, when SECCOMP filters and AppArmor are not in full effect).

At least for me, the correct /usr/bin/xdg-dbus-proxy name shows up when I view the process tree in htop. So this behavior might be a bug in xdg-system-monitor.

@glitsj16
Copy link
Collaborator

glitsj16 commented Jun 2, 2020

@kris7t Thanks for explaining, very informative. Using htop does indeed show the correct name. Personally I don't think it's a high-priority issue, but I'll try to file a bug report somewhere nonetheless. Take care!

@rusty-snake
Copy link
Collaborator

@kris7t 👍 Just a question for my understanding, why we can not simply execute fexecve(3, ["xdg-dbus-proxy", "--filter", ...], ...)?

@kris7t
Copy link
Collaborator Author

kris7t commented Jun 2, 2020

@rusty-snake That's exactly what we are doing:

fexecve(fd, arg, new_environment);

Here arg is the argv passed to the binary we want to exec. First we fopen arg[0], fstat it to check permissions, and if there is no tampering, we fexecve the opened fd, and pass the full arg (including arg[0], which should be "/usr/bin/xdg-dbus-proxy" in our case now), as well as the sanitized environment.

@rusty-snake
Copy link
Collaborator

At least for me, the correct /usr/bin/xdg-dbus-proxy name shows up when I view the process tree in htop. So this behavior might be a bug in xdg-system-monitor.

Hmm, ps -eH shows me 3, ps -eFH /usr/bin/xdg-dbus-proxy --fd=9 --args=10.

kmk3 pushed a commit to glitsj16/firejail that referenced this pull request Sep 1, 2024
Sort commands and sections in firejail.1.in and sync the result with
firejail-profile.5.in.

* Commands: `--dbus-system.*`, `--dbus-user.*`, `--icmptrace`,
  `--ip=none`, `memory-deny-write-execute`, `--noinput`
* Sections: "LANDLOCK", "NAME VALIDATION"

Relates to netblue30#3190 netblue30#3406 netblue30#4209 netblue30#5856 netblue30#6078.
kmk3 pushed a commit that referenced this pull request Sep 10, 2024
Sort commands and sections in firejail.1.in and sync the result with
firejail-profile.5.in.

* Commands: `--dbus-system.*`, `--dbus-user.*`, `--icmptrace`,
  `--ip=none`, `memory-deny-write-execute`, `--noinput`
* Sections: "LANDLOCK", "NAME VALIDATION"

Relates to #3190 #3406 #4209 #5856 #6078.
kmk3 pushed a commit to glitsj16/firejail that referenced this pull request Sep 10, 2024
Sort commands in firejail.1.in and sync the result with
firejail-profile.5.in.

* Commands: `--dbus-system.*`, `--dbus-user.*`, `--icmptrace`,
  `--ip=none`, `memory-deny-write-execute`, `--noinput`

Relates to netblue30#3190 netblue30#3406 netblue30#4209.
kmk3 pushed a commit that referenced this pull request Sep 10, 2024
Sort commands in firejail.1.in and sync the result with
firejail-profile.5.in.

* Commands: `--dbus-system.*`, `--dbus-user.*`, `--icmptrace`,
  `--ip=none`, `memory-deny-write-execute`, `--noinput`

Relates to #3190 #3406 #4209.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Allow --dbus-user=none on the command line for profiles with dbus-user filter
3 participants