Commit Graph

6720 Commits

Author SHA1 Message Date
Simon McVittie a55f29e401 Merge branch 'dispatch_peer_messages' into 'master'
dbus-monitor: Don’t send messages after becoming a monitor

Closes #301

See merge request dbus/dbus!272
2022-10-11 11:45:11 +00:00
Kai A. Hiller bc23b03b5c dbus-connection: Test built-in filters 2022-10-11 10:50:08 +00:00
Kai A. Hiller f1c17c74ac dbus-monitor: Disable automatic message filtering 2022-10-11 10:50:08 +00:00
Kai A. Hiller 5dba91acea dbus-connection: Add builtin_filters_enabled flag 2022-10-11 10:50:08 +00:00
Simon McVittie 7d4f76e798 Merge branch 'stack-underflow' into 'master'
config-parser: no longer get past the last NULL passed to locate_attributes

See merge request dbus/dbus!357
2022-10-11 10:48:57 +00:00
Evgeny Vereshchagin ae03bcdb11 config-parser: no longer get past the last NULL passed to locate_attributes
Fixes: bc86794f23
Fixes:
```
==302818==ERROR: AddressSanitizer: stack-buffer-underflow on address 0x7ffd6ac253c0 at pc 0x000000534d0b bp 0x7ffd6ac24e10 sp 0x7ffd6ac24e08
READ of size 8 at 0x7ffd6ac253c0 thread T0
    #0 0x534d0a in locate_attributes /home/vagrant/dbus/build/../bus/config-parser.c:658:16
    #1 0x52ea3f in start_busconfig_child /home/vagrant/dbus/build/../bus/config-parser.c:1080:12
    #2 0x52cca4 in bus_config_parser_start_element /home/vagrant/dbus/build/../bus/config-parser.c:2039:14
    #3 0x52b82b in expat_StartElementHandler /home/vagrant/dbus/build/../bus/config-loader-expat.c:107:8
    #4 0x7f2179f2d2bd  (/lib64/libexpat.so.1+0xd2bd) (BuildId: 0165eed77c910f6ef2227d21afa9c5c5ed5849c2)
    #5 0x7f2179f2aed3  (/lib64/libexpat.so.1+0xaed3) (BuildId: 0165eed77c910f6ef2227d21afa9c5c5ed5849c2)
    #6 0x7f2179f2c9ec  (/lib64/libexpat.so.1+0xc9ec) (BuildId: 0165eed77c910f6ef2227d21afa9c5c5ed5849c2)
    #7 0x7f2179f30a8e in XML_ParseBuffer (/lib64/libexpat.so.1+0x10a8e) (BuildId: 0165eed77c910f6ef2227d21afa9c5c5ed5849c2)
    #8 0x52b040 in bus_config_load /home/vagrant/dbus/build/../bus/config-loader-expat.c:259:9
    #9 0x523c8a in bus_context_new /home/vagrant/dbus/build/../bus/bus.c:828:12
    #10 0x521056 in main /home/vagrant/dbus/build/../bus/main.c:716:13
    #11 0x7f2179a2954f in __libc_start_call_main (/lib64/libc.so.6+0x2954f) (BuildId: 9c5863396a11aab52ae8918ae01a362cefa855fe)
    #12 0x7f2179a29608 in __libc_start_main@GLIBC_2.2.5 (/lib64/libc.so.6+0x29608) (BuildId: 9c5863396a11aab52ae8918ae01a362cefa855fe)
    #13 0x42a914 in _start (/home/vagrant/dbus/build/bus/dbus-daemon+0x42a914) (BuildId: df5369f85137975aff9bd398ae859706cc3c52ff)

Address 0x7ffd6ac253c0 is located in stack of thread T0 at offset 0 in frame
    #0 0x52cfaf in start_busconfig_child /home/vagrant/dbus/build/../bus/config-parser.c:733
```

Signed-off-by: Evgeny Vereshchagin <evvers@ya.ru>
2022-10-10 16:25:55 +00:00
Simon McVittie fd650a7007 Merge branch 'clarify-marshalling' into 'master'
Clarify demarshalling code

Closes #413

See merge request dbus/dbus!355
2022-10-08 17:12:31 +00:00
Simon McVittie e955ae2109 dbus-marshal-basic: Fix an incorrect comment
We have 16-bit types with 2-byte alignment, but this comment claimed
we only have 1-, 4- or 8-byte alignment. The actual implementation is
fine, and correctly reports 2-byte alignment for the 16-bit types.

Signed-off-by: Simon McVittie <smcv@collabora.com>
2022-10-07 14:15:56 +01:00
Simon McVittie ba1cf69f38 dbus-marshal-basic: Assert that we are in-bounds after skipping items
We recommend disabling assertions in production builds of dbus, so it
is "cheap" to add them even in relatively fast-path locations.

Signed-off-by: Simon McVittie <smcv@collabora.com>
2022-10-07 14:15:52 +01:00
Simon McVittie f6c6c6a6a2 dbus-marshal-basic: Clarify what is going on when we skip an item
Signed-off-by: Simon McVittie <smcv@collabora.com>
2022-10-07 14:15:48 +01:00
Simon McVittie 1b9e005322 dbus-marshal-validate: Add more comments indicating what is going on
Signed-off-by: Simon McVittie <smcv@collabora.com>
2022-10-07 14:15:45 +01:00
Simon McVittie 606795f908 dbus-marshal-recursive: Correct an incorrect comment
array_reader_check_finished() no longer returns a type, only a boolean,
so this comment isn't accurate any more.

Signed-off-by: Simon McVittie <smcv@collabora.com>
2022-10-07 14:15:43 +01:00
Simon McVittie 831e8ac273 dbus-marshal-validate: Add an extra assertion
We already checked that claimed_len <= (end - p), therefore we can
assume that claimed_len + p <= end. Make this a bit more obvious.

Signed-off-by: Simon McVittie <smcv@collabora.com>
2022-10-07 14:15:40 +01:00
Simon McVittie fdad11b74e Merge branch 'meson-monotonic-macos' into 'master'
Check for more symbols before defining HAVE_CLOCK_MONOTONIC in Meson

Closes #419

See merge request dbus/dbus!352
2022-10-06 18:54:10 +00:00
Jordan Williams b20b379e50
Check for more symbols before defining HAVE_CLOCK_MONOTONIC in Meson
MacOS has limited support for monotonic clock in its pthread implementation.
When building with Meson, `HAVE_MONOTONIC_CLOCK` is defined despite this.
This PR checks for the existence of the missing function `pthread_condattr_setclock`.
To match parity with AutoTools, it also checks for `clock_getres`.

Fixes #419.
2022-10-06 13:22:06 -05:00
Simon McVittie 71cac05ffb Post-release version bump
Signed-off-by: Simon McVittie <smcv@collabora.com>
2022-10-05 14:50:05 +01:00
Simon McVittie ed866a9488 Prepare v1.15.2
Signed-off-by: Simon McVittie <smcv@collabora.com>
2022-10-05 11:00:56 +01:00
Simon McVittie 0ba4ba3d64 Update NEWS
Signed-off-by: Simon McVittie <smcv@collabora.com>
2022-10-05 10:26:35 +01:00
Simon McVittie bef693f442 test: Parse a message with a byteswapped Unix fd index
Reproduces: https://gitlab.freedesktop.org/dbus/dbus/-/issues/417
Signed-off-by: Simon McVittie <smcv@collabora.com>
2022-10-05 10:24:43 +01:00
Simon McVittie 7a2c13d21b test: Add infrastructure to parse valid raw message blobs
Signed-off-by: Simon McVittie <smcv@collabora.com>
2022-10-05 10:24:42 +01:00
Simon McVittie 236f16e444 dbus-marshal-byteswap: Byte-swap Unix fd indexes if needed
When a D-Bus message includes attached file descriptors, the body of the
message contains unsigned 32-bit indexes pointing into an out-of-band
array of file descriptors. Some D-Bus APIs like GLib's GDBus refer to
these indexes as "handles" for the associated fds (not to be confused
with a Windows HANDLE, which is a kernel object).

The assertion message removed by this commit is arguably correct up to
a point: fd-passing is only reasonable on a local machine, and no known
operating system allows processes of differing endianness even on a
multi-endian ARM or PowerPC CPU, so it makes little sense for the sender
to specify a byte-order that differs from the byte-order of the recipient.

However, this doesn't account for the fact that a malicious sender
doesn't have to restrict itself to only doing things that make sense.
On a system with untrusted local users, a message sender could crash
the system dbus-daemon (a denial of service) by sending a message in
the opposite endianness that contains handles to file descriptors.

Before this commit, if assertions are enabled, attempting to byteswap
a fd index would cleanly crash the message recipient with an assertion
failure. If assertions are disabled, attempting to byteswap a fd index
would silently do nothing without advancing the pointer p, causing the
message's type and the pointer into its contents to go out of sync, which
can result in a subsequent crash (the crash demonstrated by fuzzing was
a use-after-free, but other failure modes might be possible).

In principle we could resolve this by rejecting wrong-endianness messages
from a local sender, but it's actually simpler and less code to treat
wrong-endianness messages as valid and byteswap them.

Thanks: Evgeny Vereshchagin
Fixes: ba7daa60 "unix-fd: add basic marshalling code for unix fds"
Resolves: https://gitlab.freedesktop.org/dbus/dbus/-/issues/417
Resolves: CVE-2022-42012
Signed-off-by: Simon McVittie <smcv@collabora.com>
2022-10-05 10:24:28 +01:00
Simon McVittie 3ef342410a test: Add targeted tests for dbus/dbus#413, dbus/dbus#418
Unlike the message-internals test, these do not rely on extra debug
instrumentation in libdbus, and so can be used for "as-installed"
testing. (However, they do require GLib.)

Reproduces: https://gitlab.freedesktop.org/dbus/dbus/-/issues/413
Reproduces: https://gitlab.freedesktop.org/dbus/dbus/-/issues/418
Signed-off-by: Simon McVittie <smcv@collabora.com>
2022-10-05 10:24:26 +01:00
Simon McVittie 37e0125943 test: Export G_TEST_BUILDDIR, G_TEST_SRCDIR
These environment variables are used by GLib's g_test_build_filename()
and related convenience functions, which make it easier for unit tests
to find data files in a way that works for both build-time tests and
"as-installed" tests. During "as-installed" testing, both variables
will normally be unset, and GLib uses the directory containing the
executable. In most cases that results in the right thing happening, and
this will also be true for dbus, since we install the test executables
in ${libexecdir}/installed-tests, helper executables in the same place,
and test data in ${libexecdir}/installed-tests/data.

Signed-off-by: Simon McVittie <smcv@collabora.com>
2022-10-05 10:24:24 +01:00
Simon McVittie d633016f73 test/data: Add messages that reproduce dbus/dbus#413, dbus/dbus#418
In debug builds with "embedded tests" enabled, these will automatically
be used as input for the message-internals test.

Some of the messages themselves are output from a fuzzer, others are
simplifications to include only one reason for lack of validity per
message.

I've included an annotated hex-dump for each message here, but the dbus
test suite doesn't currently know how to convert hex to binary, so I've
also committed the corresponding binary. See the comment at the top of
each hex-dump for how to create the binary version (which requires the
xxd tool shipped with vim).

It would be nice for the dbus test suite to be able to convert the
annotated hex-dump to binary, either at build-time with a Python script
or at runtime by loading the text file and decoding the hex, but I don't
want to block on that for dbus/dbus#413 and dbus/dbus#418.

Reproduces: https://gitlab.freedesktop.org/dbus/dbus/-/issues/413
Reproduces: https://gitlab.freedesktop.org/dbus/dbus/-/issues/418
Signed-off-by: Simon McVittie <smcv@collabora.com>
2022-10-05 10:24:22 +01:00
Simon McVittie 079bbf1618 dbus-marshal-validate: Validate length of arrays of fixed-length items
This fast-path previously did not check that the array was made up
of an integer number of items. This could lead to assertion failures
and out-of-bounds accesses during subsequent message processing (which
assumes that the message has already been validated), particularly after
the addition of _dbus_header_remove_unknown_fields(), which makes it
more likely that dbus-daemon will apply non-trivial edits to messages.

Thanks: Evgeny Vereshchagin
Fixes: e61f13cf "Bug 18064 - more efficient validation for fixed-size type arrays"
Resolves: https://gitlab.freedesktop.org/dbus/dbus/-/issues/413
Resolves: CVE-2022-42011
Signed-off-by: Simon McVittie <smcv@collabora.com>
2022-10-05 10:24:09 +01:00
Simon McVittie 67800ac5fe test-syntax: Exercise correctly- and incorrectly-nested structs, dicts
Reproduces: https://gitlab.freedesktop.org/dbus/dbus/-/issues/418
Signed-off-by: Simon McVittie <smcv@collabora.com>
2022-10-05 10:24:04 +01:00
Simon McVittie 9d07424e90 dbus-marshal-validate: Check brackets in signature nest correctly
In debug builds with assertions enabled, a signature with incorrectly
nested `()` and `{}`, for example `a{i(u}` or `(a{ii)}`, could result
in an assertion failure.

In production builds without assertions enabled, a signature with
incorrectly nested `()` and `{}` could potentially result in a crash
or incorrect message parsing, although we do not have a concrete example
of either of these failure modes.

Thanks: Evgeny Vereshchagin
Resolves: https://gitlab.freedesktop.org/dbus/dbus/-/issues/418
Resolves: CVE-2022-42010
Signed-off-by: Simon McVittie <smcv@collabora.com>
2022-10-05 10:23:28 +01:00
Simon McVittie 1ecbbc3760 Merge branch 'no-abstract-tmpdir-2' into 'master'
dbus-server-socket: Make unix:tmpdir equivalent to unix:dir (while leaving unix:tmpdir as default)

Closes #416

See merge request dbus/dbus!350
2022-10-05 09:21:12 +00:00
Simon McVittie 8246113fb1 NEWS: Describe the behaviour change resulting from fixing dbus#416
Signed-off-by: Simon McVittie <smcv@collabora.com>
2022-10-02 11:43:30 +01:00
Simon McVittie d1951de9b8 spec: Mention the consequences of abstract sockets when using namespaces
Signed-off-by: Simon McVittie <smcv@collabora.com>
2022-10-02 11:43:11 +01:00
Simon McVittie 4033dc5786 spec: Clarify that unix:tmpdir may create unix:path sockets even on Linux
Signed-off-by: Simon McVittie <smcv@collabora.com>
2022-10-02 11:42:30 +01:00
Simon McVittie f01382ae31 dbus-server-socket: Make unix:tmpdir equivalent to unix:dir
On Linux, there are two classes of AF_UNIX socket, which D-Bus refers
to as unix:path=... (portable to non-Linux systems) and unix:abstract=...
(not portable).

Back in 2003 when dbus gained support for abstract Unix sockets on Linux,
everyone thought they were better in every way than path-based Unix
sockets: if a DBusServer crashes or is terminated abnormally, there's
no detritus left in the filesystem. What's not to like? As a result,
since commit a70b042f (2003-06-04), when a DBusServer listens on a
unix:tmpdir=... address on Linux, the default is for the result to be
a unix:abstract=... address, with unix:path=... addresses only used on
non-Linux platforms.

However, the world has changed in the last 19 years, and namespace-based
Linux containers (which didn't exist in 2003) are now very popular. This
makes abstract sockets problematic.

Abstract sockets are tied to the network namespace, which is
all-or-nothing: if a container is to access the Internet without using
some sort of proxy or intermediary (like slirp4netns) then it needs to
share the network namespace with the host system, and that implies
sharing all abstract sockets with the host system. If the well-known
session bus is listening on an abstract socket, then it's a sandbox
escape route for any sandboxed or containerized app running under the
same uid. Conversely, if a container is *not* sharing the network
namespace with the host system, then it cannot access a session bus that
is listening on an abstract socket without using some sort of proxy
(like xdg-dbus-proxy), even if it isn't intended to impose a security
boundary and giving it direct access to the session bus would have been
more desirable.

Path-based sockets do not have this problem because they exist in the
filesystem (part of the "everything is a file" Unix philosophy),
allowing mount namespaces and bind-mounts to be used to share or
unshare them selectively.

On systems with `systemd --user` where dbus has been configured with
`--enable-user-session`, in general the session bus will already be
using a path-based socket for the "user bus", disregarding the listening
address specified in /usr/share/dbus-1/session.conf. The default in many
recent Linux distributions is either to use dbus-daemon in this way, or
to use dbus-broker, a reimplementation of the message bus service which
has similar "user bus" behaviour.

However, the <listen> address in session.conf is used when dbus-launch(1)
or dbus-run-session(1) is used to start a session bus, either manually,
via autolaunching, or via system integration glue in operating systems
that are not using `systemd --user`. This will occur particularly often
in operating systems that boot using a non-systemd init system.

Making unix:tmpdir=/tmp equivalent to unix:dir=/tmp ensures that the
well-known session bus listens on a path-based socket, allowing container
and sandboxing frameworks to mediate access to it in the same way they
would for the user bus. The D-Bus Specification already allows (but does
not require) this behaviour, because it is the only thing that was
implementable on non-Linux systems such as *BSD.

This change has the potential to cause regressions. If a container
framework enters a chroot or unshares the mount namespace but does not
unshare the network namespace, and is relying on the ability for a
process inside a container to access the session bus outside the
container via its abstract socket, then that assumption will be broken
by this change. Some use cases of schroot(1) are likely to suffer from
this. However, container frameworks with that assumption would already
have found that it does not hold when using the user bus, and it is
necessary to break that assumption if we want it to be possible to apply
application-level sandboxing in a secure way.

Another potential regression from this change is that if a dbus-daemon
is terminated abnormally, it will leave a socket in /tmp. Distributors
of operating systems where heavy use of dbus-launch(1) is expected might
wish to run dbus-cleanup-sockets(1) periodically.

This partially reverts commit a70b042f.

Resolves: https://gitlab.freedesktop.org/dbus/dbus/-/issues/416
Signed-off-by: Simon McVittie <smcv@collabora.com>
2022-09-30 10:42:11 +01:00
Simon McVittie b5172c3be1 Post-release version bump
Signed-off-by: Simon McVittie <smcv@collabora.com>
2022-09-22 13:53:25 +01:00
Simon McVittie c4c521d37f maint: Make maintainer-upload-docs.sh executable
Signed-off-by: Simon McVittie <smcv@collabora.com>
2022-09-22 13:52:38 +01:00
Simon McVittie 79aae57357 maint: Make update-authors.sh executable when not going via a shell
Signed-off-by: Simon McVittie <smcv@collabora.com>
2022-09-22 13:52:24 +01:00
Simon McVittie 2770215f6c AUTHORS: Update
Result of:
./maint/update-authors.sh

Signed-off-by: Simon McVittie <smcv@collabora.com>
2022-09-22 12:27:57 +01:00
Simon McVittie 628e97d62d Prepare v1.15.0 (development-branch release)
Signed-off-by: Simon McVittie <smcv@collabora.com>
2022-09-22 12:17:27 +01:00
Simon McVittie 28e0a57262 Prepare spec v0.39
Signed-off-by: Simon McVittie <smcv@collabora.com>
2022-09-22 12:16:40 +01:00
Simon McVittie 361ecd7dc0 Update NEWS
Signed-off-by: Simon McVittie <smcv@collabora.com>
2022-09-22 12:11:15 +01:00
Simon McVittie ffbf053e2a Merge branch 'morello-support' into 'master'
Add support for building for Arm Morello

See merge request dbus/dbus!335
2022-09-21 11:52:02 +00:00
Alex Richardson c5686f0c24 DBusMessageIter: ensure contiguous layout with 128-bit pointers
I am building DBus targeting the Arm Morello board and the "no padding"
layout assertion fails here since pointers require 16-byte alignment, and
therefore we have to add two additional ints to the DBusMessageIter struct.
As this is a new architecture, where DBus previously failed to compiled
we do not have any layout backwards compatibility requirements, so we can
simplify the DBusMessageIter structure to allocate space for 16 pointers
(which should give us a lot of space for any further changes).
2022-09-21 11:35:05 +00:00
Alex Richardson 6933a9263e dbus-message.c: skip 1.10 layout compatibility test on new architectures
These static assertions fail on CHERI-enabled architectures such as Arm
Morello, where pointers are 128 bits. Architectures with 128-bit pointers
were not supported in DBus 1.10, so we can skip the checks for DBus 1.10
structure layout compatibility for architectures with pointer size > 64 bit.
2022-09-21 11:35:05 +00:00
Alex Richardson 91f4ac9cf6 dbus-marshal-recursive.h: reduce padding in DBusType{Reader,Writer}
When building for Arm Morello (where pointers are 16 bytes), I hit the
static assertion that sizeof (DBusMessageRealIter) <= sizeof (DBusMessageIter)
inside _dbus_message_iter_init_common() otherwise. This can be fixed by
moving the pointers to the beginning of the struct to remove padding.
2022-09-21 11:35:05 +00:00
Alex Richardson 33dbeb5ebe dbus-mempool.c: ensure that all alignments are aligned to max_align_t
This is required e.g. for CHERI-enabled targets such as Arm Morello where
aligning to sizeof(long) is not sufficient to load/store pointers (which
need 16 byte alignment instead of 8 bytes).

As we can't depend on C11 yet, this commit adds a max_align_t emulation
to dbus-internals.h.
2022-09-21 11:35:05 +00:00
Alex Richardson c4a8c2d920 dbus-mempool.c: use size_t for variables holding object sizes 2022-09-21 11:35:05 +00:00
Alex Richardson 464b51acde dbus-internals: use size_t in _DBUS_ALIGN_VALUE()
When targeting CHERI-enabled architectures such as Arm Morello, performing
a bitwise and with uintptr_t values can result in an ambiguous operation
compiler warning. Fix this warning by telling  compiler which operand is
(potentially) a pointer and which one is an integer by changing the
boundary type to size_t. This change has no functional effect on other
architectures but is required to build with -Werror for Morello.

Example warning message:
```
warning: binary expression on capability types 'unsigned __intcap' and 'unsigned __intcap'; it is not clear which should be used as the source of provenance; currently provenance is inherited from the left-hand side [-Wcheri-provenance]
  _dbus_assert (_DBUS_ALIGN_VALUE (insert_at, 8) == (unsigned) insert_at);
```
2022-09-21 11:35:05 +00:00
Alex Richardson 8c0d9709f3 clang-format: don't align escaped newlines in macro definitions 2022-09-21 11:35:05 +00:00
Alex Richardson e2f3f0123c clang-format: add spaces before parens
Previously, clang-format was not adding a space after sizeof.
2022-09-21 11:35:05 +00:00
Simon McVittie a225a9c41a Merge branch 'fix-freebsd-ci' into 'master'
gitlab-ci: update FreeBSD CI image to 13.1

See merge request dbus/dbus!347
2022-09-21 11:31:43 +00:00
Alex Richardson 93203e9524 gitlab-ci: update FreeBSD CI image to 13.1
FreeBSD 13.0 has reached EOL and it appears packages
are built against a newer baseline now, so we end up
with missing symbol errors:
ld-elf.so.1: /lib/libc.so.7: version FBSD_1.7 required by /usr/local/lib/libpython3.9.so.1.0 not found

It also appears that the fdpass test still fails on 13.1, so update the
condition to less than 14.0
2022-09-21 09:01:56 +00:00