summaryrefslogtreecommitdiff
path: root/bus
AgeCommit message (Collapse)AuthorFilesLines
2016-08-12dbus-daemon, dbus-launch: cope with callers having closed standard fdsSimon McVittie1-0/+25
In Debian bug <https://bugs.debian.org/829348>, lightdm appears to have been starting dbus-launch with at least one of the three standard fds 0, 1, 2 (stdin, stdout, stderr) closed. This resulted in the dbus-daemon's epoll_create1() returning a fd less than 3. Later, _dbus_become_daemon() replaces fds 0-2 with /dev/null. As a result, a subsequent call to _dbus_loop_add_watch() for the reload pipe resulted in calling epoll_ctl on the non-epoll fd pointing to /dev/null, which fails with EINVAL, resulting in the dbus-daemon exiting unsuccessfully. Unix programs are not normally expected to behave correctly when launched with the standard fds not already open; but at the same time, X11 autolaunching means that dbus-launch (and hence the dbus-daemon) can get started from an arbitrarily precarious situation. Bug: https://bugs.freedesktop.org/show_bug.cgi?id=97008 Signed-off-by: Simon McVittie <smcv@debian.org> Reviewed-by: Thiago Macieira <thiago@kde.org> (cherry picked from commit c8f73a2a3a9d9d10587f596a62ebb64e8963197e)
2015-12-02Do not require systemd to have a service file if using it for activationSimon McVittie1-12/+31
With --systemd-activation we special-case the name org.freedesktop.systemd1 by assuming that it will eventually connect to the bus. With that in mind, we can ignore whether it has a .service file, and let it be "activated" regardless. This fixes a regression test failure on non-systemd systems such as the Ubuntu 14.04 OS on travis-ci.org: UpdateActivationEnvironment failed, because it tried to update the (fake) systemd environment, but because systemd was not actually installed, there was no service file for it in the system's search paths. We could address this by placing a dummy service file with Exec=/bin/false in our search path like the real systemd does, but it seems cleaner to not require this; this would eventually enable the real systemd to stop installing that dummy service file. This would not happen outside the regression tests, because there is no sense in using --systemd-activation without systemd installed. Bug: https://bugs.freedesktop.org/show_bug.cgi?id=93194 Reviewed-by: Ralf Habacker <ralf.habacker@freenet.de>
2015-12-02embedded tests: accept and ignore --tap argumentSimon McVittie3-3/+3
This makes them semi-command-line-compatible with a way we can invoke the GLib-based tests to get more useful debug logs. These tests still do not actually produce TAP output yet; I tried implementing that, but it requires changing a lot of noise on stdout to come out of stderr, and there was something weird going on with subprocesses restarting the test numbering which will need further investigation before making that change. Bug: https://bugs.freedesktop.org/show_bug.cgi?id=93194 Reviewed-by: Ralf Habacker <ralf.habacker@freenet.de>
2015-12-02Avoid -Wunused-label when compiling with libselinux but no libauditSimon McVittie1-0/+2
Bug: https://bugs.freedesktop.org/show_bug.cgi?id=93194 Reviewed-by: Ralf Habacker <ralf.habacker@freenet.de>
2015-11-17bus-driver: Support returning org.freedesktop.DBus UID and PIDJan Alexander Steffens (heftig)1-55/+115
Attempting to call SetEnvironment on systemd causes it to inquire about the caller's connection UID and PID. If this check fails, the call is rejected. Bug: https://bugs.freedesktop.org/show_bug.cgi?id=92857 Reviewed-by: Simon McVittie <simon.mcvittie@collabora.co.uk> [smcv: go back to DBUS_ERROR_UNIX_PROCESS_ID_UNKNOWN as the error code for failure to determine the pid]
2015-11-17bus_driver_handle_update_activation_environment: Forward to systemdJan Alexander Steffens (heftig)1-3/+152
If we use systemd activation, forward all UpdateActivationEnvironment requests to org.freedesktop.systemd1.Manager.SetEnvironment, in order to ensure variables needed by D-Bus services are available when these services are launched by systemd. Since UpdateActivationEnvironment is not available on the system bus, this only applies to user buses. Bug: https://bugs.freedesktop.org/show_bug.cgi?id=92857 Reviewed-by: Simon McVittie <simon.mcvittie@collabora.co.uk>
2015-11-17bus_driver_handle_update_activation_environment: Error on system busesJan Alexander Steffens (heftig)1-0/+11
The default policy already disallows calls on system buses. Since any bus with a service helper cleans the environment anyway, there's no point in allowing this to be called. Bug: https://bugs.freedesktop.org/show_bug.cgi?id=92857 Reviewed-by: Simon McVittie <simon.mcvittie@collabora.co.uk>
2015-11-13Do not fail with fatal message skipping GetConnectionUnixProcessID test-bus ↵Ralf Habacker1-1/+1
test on windows. Bug: https://bugs.freedesktop.org/show_bug.cgi?id=92721 Reviewed-by: Simon McVittie <simon.mcvittie@collabora.co.uk>
2015-11-13Fix test-bus test for GetConnectionUnixUser driver method on windows.Ralf Habacker1-4/+9
Because GetConnectionUnixUser is not supported on windows it fails with DBUS_ERROR_FAIL. Bug: https://bugs.freedesktop.org/show_bug.cgi?id=92721 Reviewed-by: Simon McVittie <simon.mcvittie@collabora.co.uk>
2015-11-12Skip launch helper activation tests on windows silently.Ralf Habacker1-3/+1
The system bus is unsupported there and Windows does not have any concept of setuid binaries, so it can't ever actually work. Bug: https://bugs.freedesktop.org/show_bug.cgi?id=92721 Reviewed-by: Simon McVittie <simon.mcvittie@collabora.co.uk>
2015-11-11Fix memory leaks in bus_activation_service_reload_test() in case of errors.Ralf Habacker1-8/+9
Bug: https://bugs.freedesktop.org/show_bug.cgi?id=92721 Reviewed-by: Simon McVittie <simon.mcvittie@collabora.co.uk>
2015-11-11Revert "Fix memory leaks in bus_activation_service_reload_test() in case of ↵Ralf Habacker1-9/+8
errors." This reverts commit d8569ac647da4d62c7a251d8e809f2d545a77837.
2015-11-11Fix memory leaks in bus_activation_service_reload_test() in case of errors.Ralf Habacker1-8/+9
Bug: https://bugs.freedesktop.org/show_bug.cgi?id=92721 Reviewed-by: https://bugs.freedesktop.org/show_bug.cgi?id=92721
2015-11-11Fix test-bus segfault_service_no_auto_start test on windows.Ralf Habacker1-11/+16
Windows returns unhandled exceptions from a running child by specific exit codes and not by signals as on UNIX. Therefore we use DBUS_ERROR_SPAWN_CHILD_EXITED for propagating unhandled exceptions to the parent too. Bug: https://bugs.freedesktop.org/show_bug.cgi?id=92721 Reviewed-by: Simon McVittie <simon.mcvittie@collabora.co.uk>
2015-11-06Fix test cases running client and server dispatch design issue.Ralf Habacker1-5/+34
DBus test cases running the server *and* client loop in the same process assumed that all messages send from the server has to be received in one client dispatch, which is not the case in all environments. Bug: https://bugs.freedesktop.org/show_bug.cgi?id=92721 Reviewed-by: Simon McVittie <simon.mcvittie@collabora.co.uk>
2015-11-06Fix bug unrefing connection too early in check_hello_message().Ralf Habacker1-2/+2
Bug: https://bugs.freedesktop.org/show_bug.cgi?id=92721 Reviewed-by: Simon McVittie <simon.mcvittie@collabora.co.uk>
2015-11-03Test system bus config files on Unix onlyRalf Habacker2-1/+15
Previously, we didn't consistently test parsing of every file in valid-config-files-system/ everywhere that we tested valid-config-files/. We now test it on Unix. The system bus is not supported on Windows, so we do not test valid-config-files-system/ there. valid-config-files/many-rules.conf contains <user> and <group> rules which are not applicable to Windows. Copy the original many-rules.conf to valid-config-files-system/ so that it will be tested on Unix, and remove the non-portable rules from valid-config-files/many-rules.conf. Bug: https://bugs.freedesktop.org/show_bug.cgi?id=92721 Reviewed-by: Simon McVittie <simon.mcvittie@collabora.co.uk> [rh:base patch came from Simon]
2015-11-02test_default_session_servicedirs: use the intended data directorySimon McVittie1-13/+22
If D-Bus was configured for /usr/local and built in Z:/build, the previous code would use Z:/build/dbus/.libs/usr/local/share/dbus-1/services whereas the intention was to replace the configured prefix /usr/local with the detected location, more like Z:/build/dbus/.libs/share/dbus-1/services Bug: https://bugs.freedesktop.org/show_bug.cgi?id=92721 Reviewed-by: Ralf Habacker <ralf.habacker@freenet.de>
2015-11-02test_default_session_servicedirs: simplify to a single exit code-pathSimon McVittie1-25/+20
A similar simplification was already done on master as part of commit f830e14, Bug #83539. Bug: https://bugs.freedesktop.org/show_bug.cgi?id=92721 Reviewed-by: Ralf Habacker <ralf.habacker@freenet.de>
2015-10-26user dbus.socket: Set DBUS_SESSION_BUS_ADDRESSJan Alexander Steffens (heftig)1-0/+1
As discussed in <https://github.com/systemd/systemd/issues/1600>. See also <https://bugs.archlinux.org/task/46721>, <https://bugzilla.gnome.org/show_bug.cgi?id=756420> Bug: https://bugs.freedesktop.org/show_bug.cgi?id=92612 [smcv: use AC_PATH_PROG to find systemctl; ignore systemctl failure] Signed-off-by: Simon McVittie <simon.mcvittie@collabora.co.uk> Reviewed-by: David Herrmann <dh.herrmann@gmail.com> [smcv: add links to earlier bug reports elsewhere]
2015-10-19BecomeMonitor: do not overwrite error with another errorSimon McVittie1-4/+1
If the user gave us a syntactically invalid error name, we'd overwrite the MatchRuleInvalid error with NoMemory, causing an assertion failure (crash) in the dbus-daemon. This is not a denial-of-service vulnerability on the system bus, because monitoring is a privileged action, and root privilege is checked before this code is reached. However, it's an annoying bug on the session bus. Bug: https://bugs.freedesktop.org/show_bug.cgi?id=92298 Reviewed-by: Philip Withnall <philip.withnall@collabora.co.uk> Reviewed-by: Ralf Habacker <ralf.habacker@freenet.de> Signed-off-by: Simon McVittie <simon.mcvittie@collabora.co.uk>
2015-10-02On Windows, load local configuration relative to bus setupSimon McVittie4-18/+16
This makes an installed tree with /some-prefix/ etc/ dbus-1/ session-local.conf share/ dbus-1/ session.conf relocatable to any location. Bug: https://bugs.freedesktop.org/show_bug.cgi?id=92028 Reviewed-by: Ralf Habacker <ralf.habacker@freenet.de> Tested-by: Ralf Habacker <ralf.habacker@freenet.de>
2015-10-02Cancel pending activation on any activation errorSimon McVittie1-25/+23
This fixes the error reporting if you make two attempts to activate a service that cannot be activated due to an error that is reported synchronously, such as a system service with no User= line in its .service file. This is easy to reproduce with the gdbus(1) tool, which sends an Introspect call in addition to the one you asked it to. If you try to activate a service using gdbus call --session -d com.example.FailToActivate \ -o / -m org.freedesktop.DBus.Peer.Ping then gdbus will actually send two method calls: one Introspect, and one Ping. The Introspect gets the correct error reply, but when dbus-daemon enters bus_activation_activate_service() for the Ping call, it sees that there is a pending activation and does an early-return. The pending activation does not finish until the timeout is reached. A couple of error cases handled this correctly, but the majority did not; make them all go into the same code path. Bug: https://bugs.freedesktop.org/show_bug.cgi?id=92200 Reviewed-by: Thiago Macieira <thiago@kde.org>
2015-08-25audit: make the first few fds close-on-execSimon McVittie1-0/+7
libcap-ng < 0.7.7 leaks one non-close-on-exec fd during initialization. test-bus asserts that all fds beyond 2 passed to an executed subprocess have the close-on-exec flag set, which will fail at that leaked fd. This was unnoticed until commit 517c4685, because libaudit was previously only initialized if we were configured to switch uid, which the regression tests do not do; the system bus is normally the only place that happens, but the system bus is not normally run with the "embedded tests" enabled (since they are bad for performance and security). Bug: https://bugs.freedesktop.org/show_bug.cgi?id=91684 Reviewed-by: Philip Withnall <philip.withnall@collabora.co.uk>
2015-08-06Throw a warning if we cannot open the audit socket as a session busLaurent Bigonville1-4/+0
This will effectively print a warning when failing to open the audit socket running as a session bus. The call to audit_open() should succeed even if the dbus-daemon doesn't have the CAP_AUDIT_WRITE capability. Bug: https://bugs.freedesktop.org/show_bug.cgi?id=83856 Reviewed-by: Simon McVittie <simon.mcvittie@collabora.co.uk>
2015-08-06Initialize audit subsystem even for the session busLaurent Bigonville1-2/+2
If SELinux is enabled on the system, dbus will check the permissions but no audit trails will be generated in case of denial as the audit subsystem is not initialized. Same should apply for apparmor. [smcv: without audit, the equivalent of the audit trail goes to stderr where it can be picked up by systemd-journald] A unprivileged user should be able to open the audit socket (audit_open()) but should not have the permissions to log an audit trail. The CAP_AUDIT_WRITE file capability could be set on the dbus-daemon executable in order to allow the session bus to log an AVC denial. Bug: https://bugs.freedesktop.org/show_bug.cgi?id=83856 [smcv: s/should/could/ in commit message to reflect lack of consensus that "setcap cap_audit_write+ep dbus-daemon" is desirable in general] Reviewed-by: Simon McVittie <simon.mcvittie@collabora.co.uk>
2015-08-06audit: only check for CAP_AUDIT_WRITE once, during initializationSimon McVittie1-5/+5
Bug: https://bugs.freedesktop.org/show_bug.cgi?id=89225 Reviewed-by: Colin Walters <walters@verbum.org> Signed-off-by: Simon McVittie <simon.mcvittie@collabora.co.uk>
2015-08-06audit: use DBUS_SYSTEM_LOG_WARNING if we cannot open the audit fdSimon McVittie3-6/+14
Bug: https://bugs.freedesktop.org/show_bug.cgi?id=89225 Signed-off-by: Simon McVittie <simon.mcvittie@collabora.co.uk>
2015-08-06bus: move shared libaudit code to a new audit.[ch]Simon McVittie9-162/+241
This fixes various duplicated libaudit interactions in both SELinux and AppArmor code paths, including opening two audit sockets if both SELinux and AppArmor were enabled at compile time. In particular, audit.c is now the only user of libcap-ng. This commit is not intended to introduce any functional changes, except for the de-duplication. The actual audit_log_user_avc_message() call is still duplicated, because the SELinux and AppArmor code paths use different mechanisms to compose the audit message: the SELinux path uses a statically-sized buffer on the stack which might be subject to truncation, whereas the AppArmor path uses malloc() (via DBusString) and falls back to using syslog on a memory allocation failure. Bug: https://bugs.freedesktop.org/show_bug.cgi?id=89225 Reviewed-by: Colin Walters <walters@verbum.org> [smcv: minor issues raised during review are subsequently fixed] Signed-off-by: Simon McVittie <simon.mcvittie@collabora.co.uk>
2015-07-13bus_registry_new: Assert in case of not valid context parameter to avoid ↵Ralf Habacker1-2/+2
potiental crashes (CID 54764). Because the context parameter is dereferenced several times in related code without a null check, we need to make sure to have a valid context. Reported by Coverity: CID 54764: Dereference after null check (FORWARD_NULL) Bug: https://bugs.freedesktop.org/show_bug.cgi?id=90021 Reviewed-by: Simon McVittie <simon.mcvittie@collabora.co.uk>
2015-06-17Merge branch 'dbus-1.8'Simon McVittie1-0/+2
Conflicts: NEWS
2015-06-17Fix memleak in GetConnectionCredentials handlerJacek Bukarewicz1-0/+2
Reply message was not unreferenced when GetConnectionCredentials handler was successful. Signed-off-by: Jacek Bukarewicz <j.bukarewicz@samsung.com> [smcv: changed bus_message_unref() to dbus_message_unref()] Reviewed-by: Simon McVittie <simon.mcvittie@collabora.co.uk> Bug: https://bugs.freedesktop.org/show_bug.cgi?id=91008
2015-05-27Move session & system bus configuration to datadir, by default.Dimitri John Ledkov5-10/+65
Bug: https://bugs.freedesktop.org/show_bug.cgi?id=89280 Reviewed-by: Simon McVittie <simon.mcvittie@collabora.co.uk>
2015-05-14Fail to generate random bytes instead of falling back to rand()Simon McVittie1-1/+1
This is more robust against broken setups where we run out of memory or cannot read /dev/urandom. Bug: https://bugs.freedesktop.org/show_bug.cgi?id=90414 Reviewed-by: Ralf Habacker <ralf.habacker@freenet.de> [smcv: document @error] Signed-off-by: Simon McVittie <simon.mcvittie@collabora.co.uk>
2015-05-14Make UUID generation failableSimon McVittie1-1/+2
Previously, this would always succeed, but might use weak random numbers in rare failure cases. I don't think these UUIDs are security-sensitive, but if they're generated by a PRNG as weak as rand() (<= 32 bits of entropy), we certainly can't claim that they're universally unique. Bug: https://bugs.freedesktop.org/show_bug.cgi?id=90414 Reviewed-by: Ralf Habacker <ralf.habacker@freenet.de> [smcv: document @error] Signed-off-by: Simon McVittie <simon.mcvittie@collabora.co.uk>
2015-05-14Security hardening: force EXTERNAL auth in session.conf on UnixSimon McVittie1-0/+10
DBUS_COOKIE_SHA1 is dependent on unguessable strings, i.e. indirectly dependent on high-quality pseudo-random numbers whereas EXTERNAL authentication (credentials-passing) is mediated by the kernel and cannot be faked. On Windows, EXTERNAL authentication is not available, so we continue to use the hard-coded default (all authentication mechanisms are tried). Users of tcp: or nonce-tcp: on Unix will have to comment this out, but they would have had to use a special configuration anyway (to set the listening address), and the tcp: and nonce-tcp: transports are inherently insecure unless special steps are taken to have them restricted to a VPN or SSH tunnelling. Users of obscure Unix platforms (those that trigger the warning "Socket credentials not supported on this Unix OS" when compiling dbus-sysdeps-unix.c) might also have to comment this out, or preferably provide a tested patch to enable credentials-passing on that OS. Bug: https://bugs.freedesktop.org/show_bug.cgi?id=90414 Reviewed-by: Ralf Habacker <ralf.habacker@freenet.de>
2015-05-12Convert mostly DBUS_SOCKET_... and DBUS_POLLABLE_.. macros for more type safety.Ralf Habacker1-3/+3
Bug: https://bugs.freedesktop.org/show_bug.cgi?id=89444 Reviewed-by: Simon McVittie <simon.mcvittie@collabora.co.uk>
2015-05-12Turn DBusSocket into a type-safe struct, preventing inappropriate conversionSimon McVittie2-6/+6
Fix the remaining platform-specific code to look at the struct's appropriate platform-specific member. Bug: https://bugs.freedesktop.org/show_bug.cgi?id=89444
2015-05-12main: reload_pipe is (despite its name) a socket pairSimon McVittie1-3/+5
Bug: https://bugs.freedesktop.org/show_bug.cgi?id=89444 Reviewed-by: Ralf Habacker <ralf.habacker@freenet.de>
2015-05-12DBusMainLoop, DBusSocketSet: work in terms of DBusPollableSimon McVittie1-3/+3
This requires generic support for keying hash tables by DBusPollable: there are already implementations for int and uintptr_t keys, but not for "int or uintptr_t depending on platform", which is what DBusPollable now means. Bug: https://bugs.freedesktop.org/show_bug.cgi?id=89444
2015-05-12bus_unix_fds_passing_test: the results of _dbus_socketpair are socketsSimon McVittie1-5/+6
Bug: https://bugs.freedesktop.org/show_bug.cgi?id=89444 Reviewed-by: Ralf Habacker <ralf.habacker@freenet.de>
2015-05-12Security hardening: force EXTERNAL auth in session.conf on UnixSimon McVittie1-0/+10
DBUS_COOKIE_SHA1 is dependent on unguessable strings, i.e. indirectly dependent on high-quality pseudo-random numbers whereas EXTERNAL authentication (credentials-passing) is mediated by the kernel and cannot be faked. On Windows, EXTERNAL authentication is not available, so we continue to use the hard-coded default (all authentication mechanisms are tried). Users of tcp: or nonce-tcp: on Unix will have to comment this out, but they would have had to use a special configuration anyway (to set the listening address), and the tcp: and nonce-tcp: transports are inherently insecure unless special steps are taken to have them restricted to a VPN or SSH tunnelling. Users of obscure Unix platforms (those that trigger the warning "Socket credentials not supported on this Unix OS" when compiling dbus-sysdeps-unix.c) might also have to comment this out, or preferably provide a tested patch to enable credentials-passing on that OS. Bug: https://bugs.freedesktop.org/show_bug.cgi?id=90414
2015-05-01test_remove_directory: Fix 'variable iter going out of scope leaks the ↵Ralf Habacker1-0/+1
storage it points to' (CID 54729) Reported by Coverity: CID 54729: Resource leak (RESOURCE_LEAK) Bug: https://bugs.freedesktop.org/show_bug.cgi?id=90021 Reviewed-by: Simon McVittie <simon.mcvittie@collabora.co.uk>
2015-04-17Always assert that BUS_CONNECTION_DATA() returns non-NULLRalf Habacker1-3/+15
Every DBusConnection in the dbus-daemon should have been through bus_connections_setup_connection(), so we can assert that the BusConnectionData has been attached to it. Having this assertion is enough to hint to Coverity that it does not need to worry about whether this pointer might be NULL. In regression tests, we do work with a few fake client-side DBusConnection instances in the same process; but it would be a serious bug if we mixed those up with the ones processed by dbus-daemon's real code, so the assertion is still valid. This patch has been inspired by (and fixes) the following coverity scan issues: CID 54846: Dereference null return value (NULL_RETURNS). CID 54854: Dereference null return value (NULL_RETURNS). Bug: https://bugs.freedesktop.org/show_bug.cgi?id=90021 Reviewed-by: Simon McVittie <simon.mcvittie@collabora.co.uk> [smcv: fixed -Wdeclaration-after-statement; more informative commit message] Reviewed-by: Ralf Habacker <ralf.habacker@freenet.de>
2015-04-16include_dir: skip processing on error (CID 54744)Ralf Habacker1-0/+2
We already skipped processing for DBUS_ERROR_FILE_NOT_FOUND; but if the error was something else, we would pass the NULL pointer dir to _dbus_directory_get_next_file(), which dereferences it. Reported by Coverity: CID 54744: Dereference after null check (FORWARD_NULL) Bug: https://bugs.freedesktop.org/show_bug.cgi?id=90021 [smcv: re-worded commit message] Reviewed-by: Simon McVittie <simon.mcvittie@collabora.co.uk>
2015-03-24Fix assorted compiler warnings on Windows.Simon McVittie1-0/+2
Bug: https://bugs.freedesktop.org/show_bug.cgi?id=89444 Reviewed-by: Ralf Habacker <ralf.habacker@freenet.de> [rh: rebased because a few hunks have already been applied with commit 92c39d1d8a30110c5760bd8d5e695e26a8538d1a]
2015-03-24Rename _dbus_full_duplex_pipe() to more descriptive name _dbus_socketpair().Ralf Habacker2-4/+4
Bug: https://bugs.freedesktop.org/show_bug.cgi?id=89444 Reviewed-by: Simon McVittie <simon.mcvittie@collabora.co.uk>
2015-03-11Revert "Rename _dbus_full_duplex_pipe() to more descriptive name ↵Ralf Habacker2-4/+4
_dbus_socketpair()." This reverts commit ee0e15366c8b1ea196ad63a8376c8b5299279386.
2015-03-11Rename _dbus_full_duplex_pipe() to more descriptive name _dbus_socketpair().Ralf Habacker2-4/+4
Bug: https://bugs.freedesktop.org/show_bug.cgi?id=89444
2015-03-05Improve diagnostics when UpdateActivationEnvironment calls are rejectedSimon McVittie1-2/+15
Bug: https://bugs.freedesktop.org/show_bug.cgi?id=88812 Reviewed-by: Colin Walters <walters@verbum.org> [smcv: rebased to not require the extra code initially on that bug]