Commit graph

6835 commits

Author SHA1 Message Date
Simon McVittie
12b367daaa sysdeps: Give a more useful error if unable to resolve a numeric uid
If we want to get the struct passwd corresponding to uid 42, but we
can't, it's much better to say

    User ID "42" unknown

rather than

    User "???" unknown

Helps: https://gitlab.freedesktop.org/dbus/dbus/-/issues/343
Signed-off-by: Simon McVittie <smcv@collabora.com>
2023-08-21 13:49:31 +00:00
Simon McVittie
80b90e570e sysdeps-unix: Deduplicate error handling for getpwnam and getpwnam_r
The only difference between these was that we only needed to allocate
and free buf in the getpwnam_r case. We expect that all reasonable
Unix platforms will have getpwnam_r (it's in POSIX) so adding a no-op
dbus_free(NULL) to the getpwnam code path seems harmless.

This will be helpful when we make the error handling better, in a
subsequent commit.

Helps: https://gitlab.freedesktop.org/dbus/dbus/-/issues/343
Signed-off-by: Simon McVittie <smcv@collabora.com>
2023-08-21 13:49:31 +00:00
Simon McVittie
672f05e5f3 Merge branch 'issue473' into 'master'
bus: Don't crash if inotify fails, even under DBUS_FATAL_WARNINGS=1

Closes #473

See merge request dbus/dbus!441
2023-08-21 13:49:14 +00:00
Simon McVittie
62692cd7e7 bus: Don't crash if inotify fails, even under DBUS_FATAL_WARNINGS=1
When running tests, we use DBUS_FATAL_WARNINGS=1 to make the tests fail
on internal errors. Failing to set up inotify is not really an internal
error: it's more like an environmental error, which can occur for
reasons outside our control.

Instead, log using bus_context_log(), which never crashes the process
and always just logs a warning.

Signed-off-by: Simon McVittie <smcv@collabora.com>
Resolves: https://gitlab.freedesktop.org/dbus/dbus/-/issues/473
2023-08-18 18:56:59 +00:00
Simon McVittie
01e65daa6a Update NEWS
Signed-off-by: Simon McVittie <smcv@collabora.com>
2023-08-18 19:55:59 +01:00
Simon McVittie
01757e0dd0 Merge branch 'issue343' into 'master'
Fix error behaviour on reload if a connection has an unknown uid

See merge request dbus/dbus!417
2023-08-18 18:33:55 +00:00
Simon McVittie
02b913f36c bus: When failing to reload client policy, continue iteration
If we have a large number of connections to the bus, and we fail to
reload the policy for one of them (perhaps because its uid no longer
exists in the system user database), previously we would crash, which
is obviously unintended. After the previous commit, we would stop
iteration through the list of client connections, which doesn't seem
great either: one bad connection shouldn't prevent us from reloading
the rest of our state.

Instead, let's distinguish between new connections (where we want
failure to establish a security policy to be fatal), and pre-existing
connections (where the current security policy is presumably good
enough to keep using if we have nothing better). If we're unable to
reload the policy for a pre-existing connection, log a warning and
carry on iterating.

Helps: https://gitlab.freedesktop.org/dbus/dbus/-/issues/343
Signed-off-by: Simon McVittie <smcv@collabora.com>
2023-08-18 18:51:12 +01:00
Simon McVittie
9bac14973d test: Add a targeted test for _dbus_unix_groups_from_uid()
Helps: https://gitlab.freedesktop.org/dbus/dbus/-/issues/343
Signed-off-by: Simon McVittie <smcv@collabora.com>
2023-08-18 18:51:08 +01:00
Simon McVittie
980e52898b userdb: Add proper error reporting when getting groups from a uid
Previously, if dbus_connection_get_unix_user() succeeded but
_dbus_unix_groups_from_uid() failed, then bus_connection_get_unix_groups()
would incorrectly fail without setting the error indicator, resulting
in "(null)" being logged, which is rather unhelpful.

This also lets us distinguish between ENOMEM and other errors, such as
the uid not existing in the system's user database.

Fixes: 145fb99b (untitled refactoring commit, 2006-12-12)
Helps: https://gitlab.freedesktop.org/dbus/dbus/-/issues/343
Signed-off-by: Simon McVittie <smcv@collabora.com>
2023-08-18 16:04:03 +01:00
Simon McVittie
73093fb3bc Merge branch 'issue343-minimal' into 'master'
bus: Don't crash if bus_context_create_client_policy() fails

Closes #343

See merge request dbus/dbus!435
2023-08-18 14:55:32 +00:00
Peter Benie
63522f2887 bus: Don't crash if bus_context_create_client_policy() fails
If policy creation fails, we can't usefully leave a NULL policy in the
BusConnectionData. If we did, the next attempt to reload policy would
crash with a NULL dereference when we tried to unref it, or with
an assertion failure.

One situation in which we can legitimately fail to create a client policy
is an out-of-memory condition. Another is if we are unable to look up a
connection's supplementary groups with SO_PEERGROUPS, and also unable to
look up the connection's uid's groups in the system user database, for
example because it belongs to a user account that has been deleted (which
is sysadmin error, but can happen, particularly in automated test systems)
or because a service required by a Name Service Switch plugin has failed.

Keeping the last known policy is consistent with what happens to all
the connections that are after this one in iteration order: after we
early-return, all of those connections retain their previous policies
(which doesn't seem ideal either, but that's how this has always worked).

[smcv: Add commit message]
Co-authored-by: Simon McVittie <smcv@collabora.com>
Resolves: https://gitlab.freedesktop.org/dbus/dbus/-/issues/343
2023-08-16 11:26:10 +01:00
Simon McVittie
3378792746 Update NEWS 2023-08-15 15:45:54 +01:00
Simon McVittie
b54af72dfd Add REUSE copyright/license information for binary message blobs
Most of these binary blobs is mechanically derived from the
corresponding .hex file, which is hand-written.

boolean-has-no-value.message-raw is presumably either hand-constructed
or fuzzer-generated: it was committed by a Red Hat employee and never
altered, so I've assumed Red Hat is the copyright holder. Permission
was already granted by Red Hat to relicense their dbus contributions
under the MIT (Expat) license.

Signed-off-by: Simon McVittie <smcv@collabora.com>
2023-08-15 15:41:17 +01:00
Simon McVittie
1b329c31ba subprojects: Move SPDX information from inline to .reuse/dep5
This makes updates with `meson wrap update` more straightforward.

Signed-off-by: Simon McVittie <smcv@collabora.com>
2023-08-15 15:41:17 +01:00
Simon McVittie
6ed4284f14 Merge branch 'issue439' into 'master'
meson: Specify that build-machine compiler for C++ is not required

Closes #439

See merge request dbus/dbus!432
2023-08-15 14:27:34 +00:00
Simon McVittie
3d0ee109c3 meson: Specify that build-machine compiler for C++ is not required
When cross-compiling Windows binaries on (for example) Linux, we only
need a Windows C++ compiler and not a Linux C++ compiler.

Resolves: https://gitlab.freedesktop.org/dbus/dbus/-/issues/439
Signed-off-by: Simon McVittie <smcv@collabora.com>
2023-08-15 13:55:12 +00:00
Simon McVittie
3365c95c20 Merge branch 'stdatomic' into 'master'
sysdeps: Use C11 stdatomic.h where possible

See merge request dbus/dbus!431
2023-08-15 13:34:10 +00:00
Simon McVittie
88b5749984 sysdeps: Use C11 stdatomic.h where possible
On Unix, dbus has historically used gcc-specific lock-free atomic
intrinsics where available, falling back to a pthreads mutex where
possible. Meanwhile, on Windows, it has historically used
InterlockedIncrement() and similar library functions (in practice
wrappers around lock-free intrinsics on real Windows, but IPC calls into
wineserver on Wine).

ISO C11 provides a new header, stdatomic.h, with standardized support
for atomic operations. Exactly how these are implemented is a compiler
quality-of-implementation decision, but any reasonable compiler
implementation on a modern CPU should be using intrinsics. Let's use
this wherever possible, falling back to our old implementation only if
the C11 implementation is unsupported.

One concrete benefit that we get from this is that when compiling with
mingw-w64 gcc and running via Wine, this makes atomic reference counting
operations into a simple local operation, rather than IPC to wineserver
which can be very slow. This should make our CI tests considerably more
reliable.

In all vaguely modern gcc versions (gcc 5.5 or later) and in contemporary
versions of clang, the default compiler mode is C11 or later with GNU
extensions. We intentionally do not ask for any specific C standard, so
we can use C11 features like this one, as long as we do so conditionally.

The Microsoft Visual C compiler does not currently support this without
special options, so we still use the Interlocked family of functions
when compiling for Windows with MSVC.

Signed-off-by: Simon McVittie <smcv@collabora.com>
2023-08-15 12:54:41 +00:00
Simon McVittie
e621e99241 sysdeps: Move declarations used from C++ to their own header
I want to use <stdatomic.h> in dbus-sysdeps.h, but if we do that, we
won't be able to include that header into C++ code on all compilers.
Move the declarations for new internal Windows-specific functions
introduced in commit 17a23d08
"dbus_threads_init_default, dbus_threads_init: be safe to call at any time"
into their own header.

Signed-off-by: Simon McVittie <smcv@collabora.com>
2023-08-15 12:54:41 +00:00
Simon McVittie
dbe7de00ae Merge branch 'as-installed' into 'master'
CI: Run "as-installed" tests with Meson, not just Autotools

Closes #436 and #470

See merge request dbus/dbus!425
2023-08-15 12:27:52 +00:00
Simon McVittie
3e4dd491bb CI: Install systemd system and user units into our ${prefix}
This keeps everything we install from CI separate from a possible
OS-level installation in /usr.

Resolves: https://gitlab.freedesktop.org/dbus/dbus/-/issues/470
Signed-off-by: Simon McVittie <smcv@collabora.com>
2023-08-15 12:14:57 +00:00
Simon McVittie
4b4aa24919 CI: Run "as-installed" tests with Meson, not just Autotools
Otherwise, we'd lose this test coverage when we remove Autotools.

Resolves: https://gitlab.freedesktop.org/dbus/dbus/-/issues/436
Signed-off-by: Simon McVittie <smcv@collabora.com>
2023-08-15 12:14:57 +00:00
Simon McVittie
14c1dcd322 meson: Allow sudo meson install, which doesn't set DESTDIR
This is generally not recommended (dbus should usually be installed from
the OS distributor's packages, which should install into a staging
directory using `DESTDIR`), but we'll want to use it in Gitlab-CI.

Signed-off-by: Simon McVittie <smcv@collabora.com>
2023-08-15 12:14:57 +00:00
Simon McVittie
dd5fdcacf7 INSTALL: Add some sub-headings for non-Meson build systems
Signed-off-by: Simon McVittie <smcv@collabora.com>
2023-08-15 13:10:37 +01:00
Ralf Habacker
041b236251 INSTALL: Re-word CMake build instructions
Originally part of commit
"README,INSTALL: remove references to the autotools build system"
in dbus!378.

Co-authored-by: Simon McVittie <smcv@collabora.com>
Signed-off-by: Simon McVittie <smcv@collabora.com>
2023-08-15 13:09:56 +01:00
Simon McVittie
4325a0fcc8 Continue to recommend CMake when building on Windows
In the longer term I'd like to move everything towards Meson so we only
have one primary build system, but at the moment Ralf would prefer to
keep recommending CMake for Windows builds (see dbus!378) so let's
stick with that for now.

Signed-off-by: Simon McVittie <smcv@collabora.com>
2023-08-15 13:06:18 +01:00
Simon McVittie
0b685497a0 Merge branch 'spdx-mit' into 'master'
Add SPDX license tags for the MIT (Expat) license, where straightforward

See merge request dbus/dbus!427
2023-08-15 11:22:54 +00:00
Simon McVittie
3190b488e3 Add SPDX license tags for the MIT (Expat) license, where straightforward
Signed-off-by: Simon McVittie <smcv@collabora.com>
2023-08-14 17:18:04 +00:00
Simon McVittie
680ba5d4a7 Merge branch 'meson-special-builds' into 'master'
Use Meson for the 'reduced' and 'legacy' build variants

See merge request dbus/dbus!430
2023-08-14 17:17:29 +00:00
Ralf Habacker
5d1922784c Use Meson for the 'reduced' and 'legacy' build variants
There are some differences between Autotools and Meson here:

- Because we detect native atomic operations differently, we can no
  longer emulate a platform that doesn't have them, such as ARMv4;
  but modern OSs no longer support ARMv4 and all significant hardware
  platforms now have native atomic operations, so this is now less of
  a concern.

- Similarly, we can no longer emulate a platform that doesn't have the
  getrandom() library function, but that function is available in all
  relevant glibc versions (such as CentOS >= 8, Debian >= 10,
  Ubuntu >= 18.04) so testing the fallback path is less of a concern now.

We also no longer try to disable dnotify in the legacy build, but our
dnotify code path was removed in 2013, so --disable-dnotify didn't do
anything anyway.

[Separated from a larger commit on dbus!378 —smcv]

Co-authored-by: Simon McVittie <smcv@collabora.com>
Signed-off-by: Simon McVittie <smcv@collabora.com>
2023-08-14 17:38:17 +01:00
Simon McVittie
6fb74c76ee Merge branch 'spdx-misc' into 'master'
Improve SPDX license info slightly

See merge request dbus/dbus!428
2023-08-14 16:21:35 +00:00
Simon McVittie
b463b301b9 stats.h: Add missing copyright information
Signed-off-by: Simon McVittie <smcv@collabora.com>
2023-08-14 16:58:22 +01:00
Simon McVittie
7c4d0d6281 doc: Repeat a copyright notice in a form understood by SPDX tools
Signed-off-by: Simon McVittie <smcv@collabora.com>
2023-08-14 16:58:21 +01:00
Simon McVittie
ad44d655ba NEWS: Update
Signed-off-by: Simon McVittie <smcv@collabora.com>
2023-08-14 16:29:47 +01:00
Simon McVittie
1999ea0537 INSTALL: Rewrite extremely outdated list of dependencies
Signed-off-by: Simon McVittie <smcv@collabora.com>
2023-08-14 16:29:46 +01:00
Simon McVittie
24c4b60a59 release-checklist: Update for increased use of Meson
Signed-off-by: Simon McVittie <smcv@collabora.com>
2023-08-14 16:18:58 +01:00
Simon McVittie
7b7effc175 INSTALL: Remove generic Autotools installation instructions
Now that we are recommending Meson, let's de-emphasize Autotools.
Anyone who still needs Autotools will already know how it works, at
least generically.

Signed-off-by: Simon McVittie <smcv@collabora.com>
2023-08-14 16:18:39 +01:00
Simon McVittie
f7005fbb40 README, INSTALL: Move build/install instructions into INSTALL
Signed-off-by: Simon McVittie <smcv@collabora.com>
2023-08-14 16:17:46 +01:00
Simon McVittie
9a47cca662 Merge branch 'time64' into 'master'
On 32-bit glibc, define _TIME_BITS to 64 if not already defined

Closes #465

See merge request dbus/dbus!416
2023-08-14 14:45:53 +00:00
Simon McVittie
3072109b11 On 32-bit glibc, define _TIME_BITS to 64 if not already defined
On older 32-bit architectures such as i386, this redefines time_t to be
64-bit, and correspondingly increases the size of all system data
structures that contain a time_t, such as struct timeval and struct stat.
This is necessary to allow timestamps beyond January 2038 to be
represented; as well as things that obviously deal with timestamps,
this affects functions like stat() (and therefore our wrapper
_dbus_stat()), which will fail with EOVERFLOW if asked to inspect a
file whose correct timestamp does not fit in time_t.

In particular, if the modification or access timestamp on
/etc/machine-id has somehow been set to a post-2038 time, libdbus will
consider the inability to stat() that file to be an installation error,
and when using the deprecated dbus_get_local_machine_id(), that can
cause third-party i386 software such as the Steam client to crash.
Using 64-bit timestamps avoids that failure mode.

Using 64-bit timestamps in glibc is an opt-in and not the default,
because if done carelessly it can change libraries' ABIs. However,
libdbus is careful not to include system headers and system data
types in its own headers, with the only exceptions being extremely
basic ISO C headers like <stddef.h> and <stdarg.h>; so we can safely
do this without it breaking our ABI. This is similar to the reasoning
for why commit 96ffc2a0 "configure.ac: support large-file for stat64"
was a safe change.

This change only affects glibc. Some non-GNU operating system libraries
(such as musl) are less concerned with binary backwards compatibility
than glibc, and therefore have incompatibly changed their ABI on 32-bit
platforms to switch to 64-bit timestamps throughout; no action is needed
on those platforms. If other non-GNU OS libraries have taken a route
similar to GNU's, then maintainers of those operating systems are
welcome to send tested merge requests similar to this one.

An extra subtlety here is that _TIME_BITS=64 requires
_FILE_OFFSET_BITS=64. In the Meson build, Meson unconditionally enables
_FILE_OFFSET_BITS=64 where appropriate, and in the Autotools build,
we already had that via AC_SYS_LARGEFILE, but in the CMake build we
did not necessarily have this; so we also define _FILE_OFFSET_BITS=64
there if necessary, as a continuation of commit 96ffc2a0
"configure.ac: support large-file for stat64".

On newer 32-bit architectures like x32, time_t is always 64-bit and so
this has no practical effect.

On 64-bit, setting these would have no practical effect, but to minimize
risk I'm only doing this for 32-bit architectures.

Resolves: https://gitlab.freedesktop.org/dbus/dbus/-/issues/465
Signed-off-by: Simon McVittie <smcv@collabora.com>
2023-08-14 14:18:25 +00:00
Simon McVittie
91b59ea792 Merge branch 'pidfd' into 'master'
Use PID FD if available from SO_PEERPIDFD, and return it via GetConnectionCredentials()

See merge request dbus/dbus!398
2023-08-08 11:45:34 +00:00
Luca Boccassi
7a4c47a929 bus: return ProcessFD in GetConnectionCredentials()
Allows to track a process by pinning to a file descriptor,
which unlike a PID cannot be reused.

root@image:~# busctl call org.freedesktop.DBus /org/freedesktop/DBus org.freedesktop.DBus GetConnectionCredentials "s" org.freedesktop.systemd1
a{sv} 3 "ProcessID" u 1 "UnixUserID" u 0 "ProcessFD" h 4

Signed-off-by: Luca Boccassi <bluca@debian.org>
2023-08-08 12:24:20 +01:00
Luca Boccassi
8883f0dd01 _dbus_asv_add_unix_fd: add
Add a new helper to add unix FDs to arrays. Will be used for
GetConnectionCredentials().

Signed-off-by: Luca Boccassi <bluca@debian.org>
2023-08-08 12:24:20 +01:00
Luca Boccassi
80d523dcc8 DBusCredentials: add support for PID FDs via SO_PEERPIDFD
The new socket option SO_PEERPIDFD allows to pin the process on the
other side of the socket by file descriptor, which closes a race
condition where a PID can be reused before we can pin it manually.
Available since Linux v6.5.

When storing credentials, pin the process by FD from the PID.
When querying the PID, if the PID FD is available, resolve
it from there first if possible.

Ensure the DBusCredentials object only returns the PID FD if it was
obtained by this call, so that we know for sure we can rely on it
being safe against PID reuse attacks.

Signed-off-by: Luca Boccassi <bluca@debian.org>
2023-08-08 12:24:20 +01:00
Simon McVittie
5f9c3da486 Merge branch 'ci-fixes' into 'master'
CI: cleanup setting build directory

See merge request dbus/dbus!424
2023-08-08 11:10:03 +00:00
Ralf Habacker
1b10f4f89c tools/ci-build.sh: cleanup setup and usage of ci_builddir
The order and arrangement of the initialization of the build directories
has been improved: the deletion of special directories have been moved to
the associated part, the rest have been merged and there is a default
value if not specified as an environment variable, making it easier to
execute on the command line.

Signed-off-by: Ralf Habacker <ralf.habacker@freenet.de>
2023-08-07 19:59:16 +02:00
Ralf Habacker
5ddb3b67bf CI: add prefix 'ci_' to env var 'builddir'
This customization simplifies their use, e.g. when outputting the command
line used. Because of FreeBSD, 'awk' is used instead of 'gawk' to make
sure that the tool is available.
2023-08-07 19:49:53 +02:00
Simon McVittie
8cd3ebabf6 Merge branch 'cmake-using-meson-variables' into 'master'
Let cmake retrieve version and variable information from meson build system

See merge request dbus/dbus!382
2023-08-07 14:59:34 +00:00
Ralf Habacker
e665f96c76 Let cmake retrieve version and variable information from meson build system
Signed-off-by: Ralf Habacker <ralf.habacker@freenet.de>
2023-08-07 16:10:21 +02:00
Ralf Habacker
dbb4e0ea90 cmake: reorder include header and function checks to match meson build system 2023-08-07 16:10:21 +02:00