Commit graph

6694 commits

Author SHA1 Message Date
Simon McVittie
21763bfd41 test-autolaunch: Add a permissive license
The license for this file was never stated, but all contributions to it
have been from Red Hat or Collabora, and representatives of both
companies gave permission for MIT relicensing in 2007.

Signed-off-by: Simon McVittie <smcv@collabora.com>
2022-10-12 12:08:38 +00:00
Simon McVittie
fdd589c8d8 launch-helper-for-tests: Add a permissive license
I wrote this, and it hasn't changed since.

Signed-off-by: Simon McVittie <smcv@collabora.com>
2022-10-12 12:08:38 +00:00
Simon McVittie
cf3203575d Merge branch 'test-autolaunch-win-fixes' into 'master'
test-autolaunch-win.c: Prevent assertion in dbus_message_unref()

Closes #422

See merge request dbus/dbus!366
2022-10-12 11:08:53 +00:00
Ralf Habacker
7724bf574c test-autolaunch-win.c: Prevent assertion in dbus_message_unref()
dbus_message_unref() is in principle able to handle a NULL parameter, but
causes the program to abort when `fatal_warnings_on_check_failed` is set.

Therefore the call with a NULL parameter is avoided from now on.

Fixes #422
2022-10-12 09:38:46 +02:00
Ralf Habacker
b081c0a553 Merge branch 'no-as-ac-expand' into 'master'
Autotools: use AX_RECURSIVE_EVAL instead of AS_AC_EXPAND

See merge request dbus/dbus!364
2022-10-12 06:41:02 +00:00
Simon McVittie
786c47b51d Autotools: use AX_RECURSIVE_EVAL instead of AS_AC_EXPAND
AX_RECURSIVE_EVAL is maintained as part of autoconf-archive, so we don't
need to bundle our own copy and keep track of its licensing status.
It's very similar to AS_AC_EXPAND, but the arguments are the other way
round and it doesn't automatically AC_SUBST its result.

Signed-off-by: Simon McVittie <smcv@collabora.com>
2022-10-12 06:40:30 +00:00
Ralf Habacker
cced1a5e2d Merge branch 'no-pkg-m4' into 'master'
m4: Stop shipping our own copy of pkg.m4

See merge request dbus/dbus!365
2022-10-12 06:22:51 +00:00
Simon McVittie
37190b3c12 m4: Stop shipping our own copy of pkg.m4
The canonical way to find these macro is to run autogen.sh or autoreconf
while pkg-config (or pkgconf) is installed, which will copy an up-to-date
version of the macros from /usr/share/aclocal. The `make dist` archive
will include a bundled copy of those macros, but the git repository
doesn't need them.

Signed-off-by: Simon McVittie <smcv@collabora.com>
2022-10-12 06:20:33 +00:00
Ralf Habacker
b1bc73e61d Merge branch 'autolaunch-win' into 'master'
Fixes for test-autolaunch-win

See merge request dbus/dbus!363
2022-10-11 18:23:44 +00:00
Simon McVittie
f325252e5e test-autolaunch-win: Remove redundant check for ERROR message
This seems to have been intended to give a more specific error message
if the method call failed, but it will not have been effective, because
dbus_connection_send_with_reply_and_block() ends with a check for ERROR
messages using dbus_set_error_from_message(). This means that if the
reply was an ERROR message, it will already have been converted into a
DBusError by the time call_method() regains control.

Signed-off-by: Simon McVittie <smcv@collabora.com>
2022-10-11 18:20:53 +00:00
Simon McVittie
a7bbff5baf test-autolaunch-win: Don't overwrite an error with another error
An unrelated branch failed CI with this assertion failure:

    26: dbus[6768]: error: arguments to dbus_set_error() were incorrect,
    assertion "(error) == NULL || !dbus_error_is_set ((error))" failed in
    file ...\dbus-errors.c line 365.

Looking at the test, this seems to be the most likely candidate for
this bug in error handling, which is masking whatever the real cause
for the failure was (we can't tell from here). If
dbus_connection_send_with_reply_and_block() returns NULL, then it should
already have set the error.

Fixing this bug in the error handling will hopefully give us a better
error message for the actual failure if it happens again.

Signed-off-by: Simon McVittie <smcv@collabora.com>
2022-10-11 18:20:53 +00:00
Simon McVittie
7cee01fca4 Merge branch 'autoconf-runstatedir' into 'master'
Use ${runstatedir} for system bus instead of ${localstatedir}/run

Closes #180

See merge request dbus/dbus!209
2022-10-11 17:53:39 +00:00
Simon McVittie
5bef1d3d13 Add NEWS entries for #180
Signed-off-by: Simon McVittie <smcv@collabora.com>
2022-10-11 17:15:47 +01:00
Simon McVittie
cc0544cd36 spec: Mention that the system bus address might actually be in /run
The interoperable address is unix:path=/var/run/dbus/system_bus_socket.
However, in most (perhaps all) current Linux distributions, /var/run
is guaranteed to be a symbolic link to /run, and using the path in /run
has some advantages (particularly if automounters are used).

Implementations that intend to be interoperable are not required to
listen on exactly /var/run/dbus/system_bus_socket, as long as clients
that connect to that socket will work correctly. Similarly, clients
are not required to connect to exactly /var/run/dbus/system_bus_socket,
as long as the overall system (consisting of the client and the OSs
that it supports) ensures that it ends up connecting to the same
well-known system bus that is available at
/var/run/dbus/system_bus_socket.

Because of the Unix conventions for how software installs into a prefix,
building a D-Bus implementation with its default build-time
configuration options will not necessarily result in an interoperable
system bus. The system bus is normally shipped by OS distributors,
who should ensure that they have configured it in a way that is
interoperable.

Resolves: https://gitlab.freedesktop.org/dbus/dbus/-/issues/180
Signed-off-by: Simon McVittie <smcv@collabora.com>
2022-10-11 17:14:11 +01:00
Issam E. Maghni
91fe77904a build: Put system bus socket in runstatedir by default
This lets OS distributors configure --runstatedir=/run if they want to,
although for interoperability, they should only do this if they can
guarantee that their /run and /var/run are equivalent.

A previous commit adds a warning if we are using the default path on a
system where /run and /var/run are not synoymous, mitigating the
compatibility impact of this change.

For CMake, this requires version 3.9, released in 2017.

For Meson, this is currently controlled by the runtime_dir option,
which defaults to /run if the prefix is /usr. The rationale for this
is that /run is correct for modern Unix systems, and distributors who
switch from Autotools or CMake to Meson need to review all their build
options at that time, which is an ideal opportunity to check that they
are doing the right thing around /run.

Helps: https://gitlab.freedesktop.org/dbus/dbus/-/issues/180
Co-authored-by: Simon McVittie <smcv@collabora.com>
2022-10-11 17:14:11 +01:00
Simon McVittie
e5d8d0c19a build: Show a warning if the system bus socket is not interoperable
We would like to start using ${runstatedir}/dbus/system_bus_socket,
so that distributors who make /var/run a symbolic link to /run will
usually get their dbus-daemon listening on /run/dbus/system_bus_socket,
which has some advantages in corner cases, such as when /var is mediated
by an automounter or is unmounted during system shutdown.

Unfortunately, the interoperable path in the D-Bus Specification is
/var/run/dbus/system_bus_socket for historical reasons (D-Bus is older
than /run), and older versions of Slackware are known to have had /run
and /var/run as distinct directories. Do a check during configuration
to catch systems configured like this and show a warning.

When cross-compiling, this assumes that the system where dbus is built
(the build system in Autotools/Meson, or the "host" in CMake terminology)
has its /var/run and /run set up in a way that is compatible with the
system where dbus will run (the host system in Autotools/Meson, or the
"target" in CMake terminology). This is not 100% correct, but seems good
enough for a warning that will hopefully only trigger for misguided OS
distributors.

Signed-off-by: Simon McVittie <smcv@collabora.com>
2022-10-11 17:14:11 +01:00
Simon McVittie
ba6fb129bd build: Update a comment with the release status of Autoconf
It took a while, but Autoconf 2.70 was eventually released.

Signed-off-by: Simon McVittie <smcv@collabora.com>
2022-10-11 17:14:11 +01:00
Simon McVittie
3ca855f264 build: Use AS_IF for system bus socket
Signed-off-by: Simon McVittie <smcv@collabora.com>
2022-10-11 17:14:11 +01:00
Simon McVittie
5b9d64023b Update NEWS
Signed-off-by: Simon McVittie <smcv@collabora.com>
2022-10-11 14:19:11 +01:00
Simon McVittie
98b710283a Merge branch 'spdx-syntax' into 'master'
dbus/dbus-macros-internal, test/test-platform-mutex.c: Use upper case for SPDX license operator

See merge request dbus/dbus!360
2022-10-11 13:00:13 +00:00
Ralf Habacker
4712a05874 dbus/dbus-macros-internal, test/test-platform-mutex.c: Use upper case for SPDX license operator
https://spdx.github.io/spdx-spec/SPDX-license-expressions/ says that
using upper-case operators is canonical.
2022-10-11 13:00:00 +00:00
Simon McVittie
c6173dfd83 Merge branch 'issue420' into 'master'
dbus-message: Report OOM as OOM, not InvalidArgs

Closes #420

See merge request dbus/dbus!353
2022-10-11 12:55:10 +00:00
Simon McVittie
3c0e63c10a dbus-message: Report OOM as OOM, not InvalidArgs
Resolves: https://gitlab.freedesktop.org/dbus/dbus/-/issues/420
Signed-off-by: Simon McVittie <smcv@collabora.com>
2022-10-11 11:54:21 +00:00
Simon McVittie
ccab882bad Update NEWS
Signed-off-by: Simon McVittie <smcv@collabora.com>
2022-10-11 12:53:52 +01:00
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