Commit graph

4417 commits

Author SHA1 Message Date
Simon McVittie
dbd731491b tests: always use libdbus-internal for main loop, never dbus-glib
This gets rid of a potential circular dependency, which is annoying
when bootstrapping. It is nice to have the regression tests use
the shared libdbus, but we're about to make it possible to
do that anyway, even though some of them use internal symbols.

Bug: https://bugs.freedesktop.org/show_bug.cgi?id=83115
Reviewed-by: Ralf Habacker <ralf.habacker@freenet.de>
2015-02-20 20:49:32 +00:00
Simon McVittie
267c69ac90 sysdeps: try to avoid re-including config.h
Re-including config.h after we have already included glib.h breaks
the GLIB_VERSION_MAX_ALLOWED macro, and every .c file should be
including config.h anyway.

Bug: https://bugs.freedesktop.org/show_bug.cgi?id=83115
Reviewed-by: Ralf Habacker <ralf.habacker@freenet.de>
2015-02-20 20:49:29 +00:00
Simon McVittie
21162d7de6 Remove some redundant inclusions
Both these files included dbus-test.h already.

Bug: https://bugs.freedesktop.org/show_bug.cgi?id=83115
Reviewed-by: Ralf Habacker <ralf.habacker@freenet.de>
2015-02-20 20:49:01 +00:00
Simon McVittie
17f12d8725 Remove <apparmor/> from default system.conf, session.conf
The AppArmor and SELinux modes both default to "enabled" (i.e.
enable it if and only if it is supported), so there is no need to
add their element to system.conf unless a system integrator wants
to set them to either required or disabled.

However, if we add <apparmor/> on upgrade from 1.9.10 to 1.9.12,
any subsequent attempts to reload bus configuration before the
next reboot will fail, because the dbus-daemon that is already
running does not support that element.

Bug: https://bugs.freedesktop.org/show_bug.cgi?id=89231
Reviewed-by: Tyler Hicks <tyhicks@canonical.com>
2015-02-19 16:46:21 +00:00
Simon McVittie
65a84fd56d clarify NEWS 2015-02-19 14:47:30 +00:00
Simon McVittie
2d38407312 1.9.13 2015-02-19 14:46:35 +00:00
Simon McVittie
87fe648a5c 1.9.12 2015-02-19 13:29:31 +00:00
Tyler Hicks
5872c6f7ff apparmor: Fix build failure with --disable-apparmor
The bus_apparmor_confinement_unref() function definition must exist even
when building with --disable-apparmor.

Bug: https://bugs.freedesktop.org/show_bug.cgi?id=75113
Signed-off-by: Tyler Hicks <tyhicks@canonical.com>
Reviewed-by: Simon McVittie <simon.mcvittie@collabora.co.uk>
2015-02-19 10:22:17 +00:00
Simon McVittie
3a10304a2d Revert "Add DBus method to return the AA context of a connection"
This reverts commit 24f1502e42,
which wasn't meant to go upstream (it's backwards compatibility
with older versions of this patchset).
2015-02-18 20:57:08 +00:00
Tyler Hicks
24f1502e42 Add DBus method to return the AA context of a connection
This is not intended for upstream inclusion. It implements a bus method
(GetConnectionAppArmorSecurityContext) to get a connection's AppArmor
security context but upstream D-Bus has recently added a generic way of
getting a connection's security credentials (GetConnectionCredentials).
Ubuntu should carry this patch until packages in the archive are moved
over to the new, generic method of getting a connection's credentials.

[Altered by Simon McVittie: survive non-UTF-8 contexts which
would otherwise be a local denial of service, except that Ubuntu
inherits a non-fatal warnings patch from Debian; new commit message
taken from the Ubuntu changelog; do not emit unreachable code if
AppArmor is disabled.]
2015-02-18 20:42:05 +00:00
Simon McVittie
eac45c0484 apparmor: tighten up terminology for context vs. label vs. profile
The thing returned by SO_PEERSEC (which we're calling LinuxSecurityLabel
within D-Bus) can have a different meaning for each LSM. In AppArmor
it's the AppArmor context, which is made up of an AppArmor label and an
optional confinement mode; the label further subdivides into one
or more profiles. See
https://bazaar.launchpad.net/~apparmor-dev/apparmor/master/revision/2862
and subsequent commits for recent clarification of this terminology.

In practice, the part that dbus-daemon deals with is the label,
and occasionally also the mode.

Bug: https://bugs.freedesktop.org/show_bug.cgi?id=75113
Reviewed-by: Tyler Hicks <tyhicks@canonical.com>
2015-02-18 20:41:56 +00:00
Tyler Hicks
439723610e Mediation of processes becoming a monitor
When an AppArmor confined process wants to become a monitor, a check is
performed to see if eavesdropping should be allowed.

The check is based on the connection's label and the bus type.

This patch reuses the bus_apparmor_allows_eavesdropping() hook.

An example AppArmor rule that would allow a process to become a monitor
on the system bus would be:

  dbus eavesdrop bus=system,

Bug: https://bugs.freedesktop.org/show_bug.cgi?id=75113
Signed-off-by: Tyler Hicks <tyhicks@canonical.com>
Reviewed-by: Simon McVittie <simon.mcvittie@collabora.co.uk>
2015-02-18 18:59:46 +00:00
Tyler Hicks
66979aae61 Mediation of processes eavesdropping
When an AppArmor confined process wants to eavesdrop on a bus, a check
is performed to see if the action should be allowed.

The check is based on the connection's label and the bus type.

This patch adds a new hook, which was not previously included in the
SELinux mediation, to mediate eavesdropping from
bus_driver_handle_add_match().

A new function is added to bus/signals.c to see if a match rule is an
eavesdropping rule since the rule flags field is private to signals.c.

An example AppArmor rule that would allow a process to eavesdrop on the
session bus would be:

  dbus eavesdrop bus=session,

Bug: https://bugs.freedesktop.org/show_bug.cgi?id=75113
Signed-off-by: Tyler Hicks <tyhicks@canonical.com>
Reviewed-by: Simon McVittie <simon.mcvittie@collabora.co.uk>
2015-02-18 18:59:46 +00:00
John Johansen
d9a2fdb96a Mediation of processes sending and receiving messages
When an AppArmor confined process wants to send or receive a message, a
check is performed to see if the action should be allowed.

When a message is going through dbus-daemon, there are two checks
performed at once. One for the sending process and one for the receiving
process.

The checks are based on the process's label, the bus type, destination,
path, interface, and member, as well as the peer's label and/or
destination name.

This allows for the traditional connection-based enforcement, as well as
any fine-grained filtering desired by the system administrator.

It is important to note that error and method_return messages are
allowed to cut down on the amount of rules needed. If a process was
allowed to send a message, it can receive error and method_return
messages.

An example AppArmor rule that would be needed to allow a process to call
the UpdateActivationEnvironment method of the session bus itself would be:

  dbus send bus=session path=/org/freedesktop/DBus
       interface=org.freedesktop.DBus member=UpdateActivationEnvironment
       peer=(name=org.freedesktop.DBus),

To receive any message on the system bus from a process confined by
the "confined-client" AppArmor profile:

  dbus receive bus=system peer=(label=confined-client),

Bug: https://bugs.freedesktop.org/show_bug.cgi?id=75113
Signed-off-by: John Johansen <john.johansen@canonical.com>
[tyhicks: Use BusAppArmorConfinement, bug fixes, cleanup, commit msg]
[tyhicks: Pass the message type to the AppArmor hook]
[tyhicks: Don't audit unrequested reply message denials]
Signed-off-by: Tyler Hicks <tyhicks@canonical.com>
[smcv: when AA denies sending, don't label requested_reply as "matched rules"]
Reviewed-by: Simon McVittie <simon.mcvittie@collabora.co.uk>
Reviewed-by: Tyler Hicks <tyhicks@canonical.com>
2015-02-18 18:59:23 +00:00
Tyler Hicks
ad209bd090 Do LSM checks after determining if the message is a requested reply
Move the call to bus_selinux_allows_send() after the call to
bus_connections_check_reply().

This allows LSMs to know if the message is a reply and whether or not it
was requested.

Bug: https://bugs.freedesktop.org/show_bug.cgi?id=75113
Signed-off-by: Tyler Hicks <tyhicks@canonical.com>
Reviewed-by: Simon McVittie <simon.mcvittie@collabora.co.uk>
2015-02-18 17:29:00 +00:00
John Johansen
c2686d53f3 Mediation of processes that acquire well-known names
When an AppArmor confined process wants to acquire a well-known name, a
check is performed to see if the action should be allowed.

The check is based on the connection's label, the bus type, and the name
being requested.

An example AppArmor rule that would allow the name
"com.example.ExampleName" to be acquired on the system bus would be:

  dbus bind bus=system name=com.example.ExampleName,

To let a process acquire any name on any bus, the rule would be:

  dbus bind,

Bug: https://bugs.freedesktop.org/show_bug.cgi?id=75113
Signed-off-by: John Johansen <john.johansen@canonical.com>
[tyhicks: Use BusAppArmorConfinement, bug fixes, cleanup, commit msg]
[tyhicks: initialize reserved area at the start of the query string]
[tyhicks: Use empty string for NULL bustypes when building queries]
Signed-off-by: Tyler Hicks <tyhicks@canonical.com>
Reviewed-by: Simon McVittie <simon.mcvittie@collabora.co.uk>
2015-02-18 17:28:42 +00:00
Tyler Hicks
cd23a5df10 Store AppArmor label of connecting processes
When processes connect the bus, the AppArmor confinement context should
be stored for later use when checks are to be done during message
sending/receiving, acquire a name, and eavesdropping.

Code outside of apparmor.c will need to initialize and unreference the
confinement context, so bus_apparmor_confinement_unref() can no longer
be a static function.

[Move bus_apparmor_confinement_unref back to its old location for
a more reasonable diff -smcv]

Bug: https://bugs.freedesktop.org/show_bug.cgi?id=75113
Reviewed-by: Simon McVittie <simon.mcvittie@collabora.co.uk>
2015-02-18 17:04:05 +00:00
Tyler Hicks
e8b0248eef Store AppArmor label of bus during initialization
During dbus-daemon initialization, the AppArmor confinement context
should be stored for later use when checks are to be done on messages
to/from the bus itself.

AppArmor confinement contexts are documented in aa_getcon(2). They
contain a confinement string and a mode string. The confinement string
is typically the name of the AppArmor profile confining a given process.
The mode string gives the current enforcement mode of the process
confinement. For example, it may indicate that the confinement should be
enforced or it may indicate that the confinement should allow all
actions with the caveat that actions which would be denied should be
audited.

It is important to note that libapparmor mallocs a single buffer to
store the con and mode strings and separates them with a NUL terminator.
Because of this, only con should be freed.

Bug: https://bugs.freedesktop.org/show_bug.cgi?id=75113
Signed-off-by: Tyler Hicks <tyhicks@canonical.com>
[smcv: use BUS_SET_OOM]
[smcv: dbus_set_error doesn't need extra newlines]
Reviewed-by: Simon McVittie <simon.mcvittie@collabora.co.uk>
Reviewed-by: Tyler Hicks <tyhicks@canonical.com>
2015-02-18 17:04:04 +00:00
John Johansen
2a881a9e75 Initialize AppArmor mediation
When starting dbus-daemon, autodetect AppArmor kernel support and use
the results from parsing the busconfig to determine if mediation should
be enabled.

In the busconfig, "enabled" means that kernel support is autodetected
and, if available, AppArmor mediation occurs in dbus-daemon. In
"enabled" mode, if kernel support is not detected, mediation is
disabled. "disabled" means that mediation does not occur. "required"
means that kernel support must be detected for dbus-daemon to start.

Additionally, when libaudit support is built into dbus-daemon, the
AppArmor initialization routines set up the audit connection.

Bug: https://bugs.freedesktop.org/show_bug.cgi?id=75113
Signed-off-by: John Johansen <john.johansen@canonical.com>
[tyhicks: Honor enforcement modes and detect AppArmor dbus rule support]
[tyhicks: fix unreachable return when AppArmor support is built]
[tyhicks: make bus_apparmor_full_init() able to raise a DBusError]
Signed-off-by: Tyler Hicks <tyhicks@canonical.com>
[smcv: _bus_apparmor_aa_supports_dbus: document necessary kernel API guarantee]
[smcv: bus_apparmor_pre_init: distinguish between OOM and AppArmor not enabled]
[smcv: document why we open() and not just stat()]
Reviewed-by: Simon McVittie <simon.mcvittie@collabora.co.uk>
Reviewed-by: Tyler Hicks <tyhicks@canonical.com>
2015-02-18 17:04:02 +00:00
Tyler Hicks
06033cb20f Add apparmor element support to bus config parsing
The <apparmor> element can contain a single mode attribute that has one
of three values:

 "enabled"
 "disabled"
 "required"

"enabled" means that kernel support is autodetected and, if available,
AppArmor mediation occurs in dbus-daemon. If kernel support is not
detected, mediation is disabled. "disabled" means that mediation does
not occur. "required" means that kernel support must be detected for
dbus-daemon to start.

Bug: https://bugs.freedesktop.org/show_bug.cgi?id=75113
Signed-off-by: Tyler Hicks <tyhicks@canonical.com>
Reviewed-by: Simon McVittie <simon.mcvittie@collabora.co.uk>
2015-02-18 17:04:00 +00:00
Tyler Hicks
f62bff5bca Update autoconf file to build against libapparmor
AppArmor support can be configured at build time with --enable-apparmor
and --disable-apparmor. By default, the build time decision is
automatically decided by checking if a sufficient libapparmor is
available.

A minimum required libapparmor is version 2.8.95.

Bug: https://bugs.freedesktop.org/show_bug.cgi?id=75113
Signed-off-by: Tyler Hicks <tyhicks@canonical.com>
[smcv: avoid potential non-portability from "test EXPR -a EXPR"]
Reviewed-by: Simon McVittie <simon.mcvittie@collabora.co.uk>
Reviewed-by: Tyler Hicks <tyhicks@canonical.com>
2015-02-18 17:03:58 +00:00
Tyler Hicks
e6b90976c8 Add apparmor element and attributes to the bus config dtd
Bug: https://bugs.freedesktop.org/show_bug.cgi?id=75113
Signed-off-by: Tyler Hicks <tyhicks@canonical.com>
Reviewed-by: Simon McVittie <simon.mcvittie@collabora.co.uk>
2015-02-18 17:03:56 +00:00
Tyler Hicks
7e142554d3 Document AppArmor enforcement in the dbus-daemon man page
Bug: https://bugs.freedesktop.org/show_bug.cgi?id=75113
Signed-off-by: Tyler Hicks <tyhicks@canonical.com>
Reviewed-by: Simon McVittie <simon.mcvittie@collabora.co.uk>
2015-02-18 17:03:42 +00:00
Simon McVittie
82f9f6423a Add LinuxSecurityLabel to specification
Bug: https://bugs.freedesktop.org/show_bug.cgi?id=89041
Reviewed-by: Philip Withnall <philip.withnall@collabora.co.uk>
2015-02-18 10:35:05 +00:00
Simon McVittie
2e6879bc1b Add regression test for LinuxSecurityLabel credential
Bug: https://bugs.freedesktop.org/show_bug.cgi?id=89041
Reviewed-by: Philip Withnall <philip.withnall@collabora.co.uk>
2015-02-18 10:35:05 +00:00
Simon McVittie
96c3bcec77 Add LSM-agnostic support for LinuxSecurityLabel credential
Bug: https://bugs.freedesktop.org/show_bug.cgi?id=89041
Reviewed-by: Philip Withnall <philip.withnall@collabora.co.uk>
Acked-by: Stephen Smalley <sds@tycho.nsa.gov> (for SELinux)
Acked-by: John Johansen <john.johansen@canonical.com> (for AppArmor)
Acked-by: Casey Schaufler <casey@schaufler-ca.com> (for Smack)
Tested-by: Tyler Hicks <tyhicks@canonical.com>
2015-02-18 10:35:05 +00:00
Tyler Hicks
c966d90374 New a{sv} helper for using byte arrays as the variant
Create a new helper for using a byte array as the value in the mapping
from string to variant.

Bug: https://bugs.freedesktop.org/show_bug.cgi?id=75113
Bug: https://bugs.freedesktop.org/show_bug.cgi?id=89041
Signed-off-by: Tyler Hicks <tyhicks@canonical.com>
Reviewed-by: Simon McVittie <simon.mcvittie@collabora.co.uk>
Reviewed-by: Philip Withnall <philip.withnall@collabora.co.uk>
2015-02-18 10:35:05 +00:00
Ralf Habacker
387c1a5b91 dbus-monitor: Remove empty column in --profile mode.
Bug: https://bugs.freedesktop.org/show_bug.cgi?id=89165
Reviewed-by: Simon McVittie <simon.mcvittie@collabora.co.uk>
2015-02-16 15:12:06 +01:00
Ralf Habacker
450c7067de dbus-monitor: Combine sec and usec columns into one timestamp column and unify platform related format string.
Bug: https://bugs.freedesktop.org/show_bug.cgi?id=89165
Reviewed-by: Simon McVittie <simon.mcvittie@collabora.co.uk>
2015-02-16 15:12:06 +01:00
Ralf Habacker
1e2395f25d dbus-send: Keep cmake build system in sync with autotools.
Bug: https://bugs.freedesktop.org/show_bug.cgi?id=89109
Reviewed-by: Simon McVittie <simon.mcvittie@collabora.co.uk>
2015-02-16 14:00:04 +00:00
Philip Withnall
bd707406a4 doc: Add a guide to designing D-Bus APIs
This guide gives some pointers on how to write D-Bus APIs which are nice
to use.

It adds an optional dependency on Ducktype and yelp-build from
yelp-tools. These are used when available, but are not required unless
--enable-ducktype-docs is passed to configure. They are required for
uploading the docs, however.

Bug: https://bugs.freedesktop.org/show_bug.cgi?id=88994
Reviewed-by: Simon McVittie <simon.mcvittie@collabora.co.uk>
2015-02-16 13:45:37 +00:00
Simon McVittie
4453665b17 dbus-monitor: whitespace 2015-02-16 12:53:57 +00:00
Simon McVittie
bb950952e6 dbus-monitor: clarify column headers
- change "ref serial" to "in_reply_to" (avoiding whitespace for easy
  visual parsing)
- prefix with # to clarify that these are not part of the data

Bug: https://bugs.freedesktop.org/show_bug.cgi?id=89165
Reviewed-by: Ralf Habacker <ralf.habacker@freenet.de>
2015-02-16 12:53:18 +00:00
Ralf Habacker
a52ef07c80 dbus-monitor.c: unify columns format in --profile mode and display column header.
[rebase onto correctly indented version -smcv]
Bug: https://bugs.freedesktop.org/show_bug.cgi?id=89165
Reviewed-by: Ralf Habacker <ralf.habacker@freenet.de>
2015-02-16 12:53:16 +00:00
Simon McVittie
1ddaffffb8 dbus-monitor: convert remaining hard tabs to 8 spaces
Bug: https://bugs.freedesktop.org/show_bug.cgi?id=89165
Reviewed-by: Ralf Habacker <ralf.habacker@freenet.de>
2015-02-16 12:52:53 +00:00
Simon McVittie
3ca9aa9cc0 dbus-send: pretty-print GVariant-style bytestrings
dbus-send could already pretty-print bytestrings that do not have
\0 termination, but those are awkward to work with (they need copying),
so they are now discouraged. Teach it to print bytestrings that
do have \0 termination as well.

In the process, rewrite this part of the message parser
to use dbus_message_iter_get_fixed_array(), which is the Right way
to get arrays of numbers out of a message.

Bug: https://bugs.freedesktop.org/show_bug.cgi?id=89109
Reviewed-by: Philip Withnall <philip.withnall@collabora.co.uk>
2015-02-16 11:44:16 +00:00
Simon McVittie
890b1dd5c5 Add manual-paths test to the Autotools (mingw) build too
As in CMake, it is restricted to Windows builds, since the
functionality that it tests is not present in Unix builds.
2015-02-16 11:43:57 +00:00
Ralf Habacker
a5e5f391a1 Add org.freedesktop.DBus.Verbose interface to dbus-daemon when compiled with DBUS_ENABLE_VERBOSE_MODE.
This interface contains methods 'EnableVerbose' and 'DisableVerbose'
to control verbose mode on daemon runtime.

Bug: https://bugs.freedesktop.org/show_bug.cgi?id=88896
Reviewed-by: Simon McVittie <simon.mcvittie@collabora.co.uk>
2015-02-13 11:20:21 +01:00
Ralf Habacker
53d3914946 Add manual-paths test executable with cmake build support.
Bug: https://bugs.freedesktop.org/show_bug.cgi?id=83539
Reviewed-by: Simon McVittie <simon.mcvittie@collabora.co.uk>
2015-02-12 23:22:18 +01:00
Simon McVittie
e4d03537b6 Add dbus-test-tool and its man page to the CMake build system
Bug: https://bugs.freedesktop.org/show_bug.cgi?id=89086
Reviewed-by: Philip Withnall <philip.withnall@collabora.co.uk>
2015-02-12 14:13:24 +00:00
Simon McVittie
15506779a7 Document dbus-test-tool
Bug: https://bugs.freedesktop.org/show_bug.cgi?id=89086
Reviewed-by: Philip Withnall <philip.withnall@collabora.co.uk>
2015-02-12 14:13:03 +00:00
Simon McVittie
e161ec7214 bus_driver_handle_get_connection_credentials: do not assert on OOM
dbus_connection_get_windows_user is documented to return TRUE but
put NULL in its argument if OOM is reached.

Bug: https://bugs.freedesktop.org/show_bug.cgi?id=89041
Reviewed-by: Ralf Habacker <ralf.habacker@freenet.de>
2015-02-11 16:26:16 +01:00
Simon McVittie
e387331220 Reduce the number of fds the fdpass test uses
It was relying on a higher-than-default fd limit; cut it down to
more than 256 but rather less than 1024, since the default Linux
limit is 1024 fds per user.

Also automatically skip this test if our rlimit is too small.

Bug: https://bugs.freedesktop.org/show_bug.cgi?id=88998
Reviewed-by: Philip Withnall <philip.withnall@collabora.co.uk>
2015-02-11 14:32:58 +00:00
Ralf Habacker
4a39439727 Minor optimization in _dbus_getsid().
MSDN recommands to use GetCurrentProcess() for current process.

Reviewed-by: Simon McVittie <simon.mcvittie@collabora.co.uk>
Bug: https://bugs.freedesktop.org/show_bug.cgi?id=54445
2015-02-11 11:57:49 +00:00
Ralf Habacker
87d40ec950 Add test for windows sid.
Bug: https://bugs.freedesktop.org/show_bug.cgi?id=54445
Reviewed-by: Simon McVittie <simon.mcvittie@collabora.co.uk>
2015-02-11 11:57:46 +00:00
Ralf Habacker
b417088ff7 Windows implementation of GetConnectionCredentials.
Reviewed-by: Simon McVittie <simon.mcvittie@collabora.co.uk>
Bug: https://bugs.freedesktop.org/show_bug.cgi?id=54445
2015-02-11 11:57:43 +00:00
Ralf Habacker
b8bb0119ef Fix 'dbus-daemon on Windows: Failed to bind socket "localhost:xxxx": Address already in use'.
Bug: https://bugs.freedesktop.org/show_bug.cgi?id=87999
Reviewed-by: Simon McVittie <simon.mcvittie@collabora.co.uk>
(cherry picked from commit 795ea3007e)
2015-02-09 23:08:24 +01:00
Simon McVittie
c2e2c15455 1.9.11 2015-02-09 15:35:55 +00:00
Simon McVittie
5394abe518 1.9.10 2015-02-09 11:09:51 +00:00
Simon McVittie
3d1426ac72 Add a regression test for making systemd activation appear to fail 2015-02-09 11:06:38 +00:00