Commit graph

4417 commits

Author SHA1 Message Date
Ralf Habacker
96646adbe9 Build test-bus-system with cmake on non win32 platforms.
Bug: https://bugs.freedesktop.org/show_bug.cgi?id=83583
Reviewed-by: Simon McVittie <simon.mcvittie@collabora.co.uk>
2014-09-18 02:41:45 +02:00
Simon McVittie
c1b92aceee New test for fd-passing
Bug: https://bugs.freedesktop.org/show_bug.cgi?id=83622
Reviewed-by: Alban Crequy <alban.crequy@collabora.co.uk>
[add dbus-sysdeps-unix.h as required for close-on-exec in master -smcv]
2014-09-17 17:20:07 +01:00
Simon McVittie
1909a82a8a Merge branch 'dbus-1.8'
Conflicts:
	NEWS
	configure.ac
2014-09-16 17:50:14 +01:00
Simon McVittie
8874d3a0c5 1.8.9 2014-09-16 17:47:46 +01:00
Simon McVittie
eca7a1c5e0 NEWS for 1.9 2014-09-15 17:44:55 +01:00
Alban Crequy
c681f46c22 dbus-monitor: more details on file descriptors
Print more details when receiving a file descriptor.

Before:
   unix fd 5

After:
   file descriptor
         inode: 1030
         type: char
   file descriptor
         inode: 295664
         type: socket
         address family: unknown (16)
   file descriptor
         inode: 295665
         type: socket
         address family: inet
         name 127.0.0.1 port 47723
         peer 127.0.0.1 port 22
   file descriptor
         inode: 295666
         type: socket
         address family: unix
         name @/tmp/d67s774Sws0pEra
   file descriptor
         inode: 295667
         type: socket
         address family: unix
         name @
         peer @

Bug: https://bugs.freedesktop.org/show_bug.cgi?id=80603
Reviewed-by: Simon McVittie <simon.mcvittie@collabora.co.uk>
2014-09-15 17:37:59 +01:00
Alban Crequy
eb4584d5c5 dbus-monitor: do not leak file descriptors from fd-passing
Bug: https://bugs.freedesktop.org/show_bug.cgi?id=80603
Reviewed-by: Simon McVittie <simon.mcvittie@collabora.co.uk>
2014-09-15 17:37:34 +01:00
Simon McVittie
28cba65785 Prepare 1.8.8 (embargoed until tomorrow) 2014-09-15 12:43:04 +01:00
Ralf Habacker
6864780bd6 Fix installation of empty directories for cmake build system.
The differences has been found out by comparing with the cross compiled
mingw..-dbus packages.

[exclude system bus support bits on Windows -smcv]

Bug: https://bugs.freedesktop.org/show_bug.cgi?id=83583
Reviewed-by: Simon McVittie <simon.mcvittie@collabora.co.uk>
2014-09-15 13:33:23 +02:00
Simon McVittie
87448fed6f Make various system-bus-related things Unix-only
There is no system bus on Windows, and there won't be until/unless
it can be secure.

Bug: https://bugs.freedesktop.org/show_bug.cgi?id=83583
Reviewed-by: Ralf Habacker <ralf.habacker@freenet.de>
2014-09-15 13:33:21 +02:00
Simon McVittie
3765075c5f Split _dbus_fd_set_close_on_exec into Unix and Windows versions
On Unix, the thing that can be made close-on-exec is a file descriptor,
which is an int.

On Windows, the thing that can be made close-on-exec is a HANDLE,
which is pointer-sized (but not necessarily a pointer!). In practice,
on Windows we only called _dbus_fd_set_close_on_exec() on socket
pseudo-file-descriptors (SOCKET, which is an unsigned int);
every SOCKET can validly be cast to HANDLE, but not every HANDLE
is a SOCKET.

Before this commit we used an intptr_t as a sort of fake
union { int; HANDLE; }, which just obscures what's going on.

In practice, everything that called _dbus_fd_set_close_on_exec()
is really platform-specific anyway, so let's just have two separate
functions and call this solved.

Bug: https://bugs.freedesktop.org/show_bug.cgi?id=39610
2014-09-15 13:31:22 +02:00
Simon McVittie
ee11ec1256 _dbus_read_socket_with_unix_fds: do not accept extra fds in cmsg padding
This addresses CVE-2014-3635.

If (*n_fds * sizeof (int) % sizeof (size_t)) is nonzero,
then CMSG_SPACE (*n_fds * sizeof (int)) > CMSG_LEN (*n_fds * sizeof (int)
because the SPACE includes padding to a size_t boundary, whereas the LEN
does not. We have to allocate the SPACE. Previously, we told the kernel
that the buffer size we wanted was the SPACE, not the LEN, which meant
it was free to fill the padding with additional fds: on a 64-bit
platform with 32-bit int, that's one extra fd, if *n_fds happens
to be odd.

This meant that a malicious sender could send exactly 1 fd too many,
which would make us fail an assertion if enabled, or overrun a buffer
by 1 fd otherwise.

Bug: https://bugs.freedesktop.org/show_bug.cgi?id=83622
Reviewed-by: Alban Crequy <alban.crequy@collabora.co.uk>
2014-09-15 12:31:14 +01:00
Simon McVittie
f70c0e98c5 Add _DBUS_GNUC_UNUSED, and use it in _DBUS_STATIC_ASSERT
This means we can use _DBUS_STATIC_ASSERT at non-global scope without
tripping -Wunused-local-typedefs.

Bug: https://bugs.freedesktop.org/show_bug.cgi?id=83767
Reviewed-by: Alban Crequy <alban.crequy@collabora.co.uk>
(cherry picked from commit 0e3d08d45c)
2014-09-15 12:31:04 +01:00
Alban Crequy
e0c9d31be3 bus: enforce pending_fd_timeout
This is one of four commits needed to address CVE-2014-3637.

The bus uses _dbus_connection_set_pending_fds_function and
_dbus_connection_get_pending_fds_count to be notified when there are pending
file descriptors. A timeout per connection is armed and disarmed when the file
descriptor list is used and emptied.

Bug: https://bugs.freedesktop.org/show_bug.cgi?id=80559
Reviewed-by: Simon McVittie <simon.mcvittie@collabora.co.uk>
2014-09-15 12:30:33 +01:00
Alban Crequy
8021fd8426 DBusConnection: implements _dbus_connection_set_pending_fds_function
This is one of four commits needed to address CVE-2014-3637.

This will allow the bus to be notified whenever a file descriptor is added or
removed from a DBusConnection's DBusMessageLoader.

Bug: https://bugs.freedesktop.org/show_bug.cgi?id=80559
Reviewed-by: Simon McVittie <simon.mcvittie@collabora.co.uk>
2014-09-15 12:30:30 +01:00
Alban Crequy
995734750c DBusConnection: implements _dbus_connection_get_pending_fds_count
This is one of four commits needed to address CVE-2014-3637.

This will allow the bus to know whether there are pending file descriptors in a
DBusConnection's DBusMessageLoader.

https://bugs.freedesktop.org/show_bug.cgi?id=80559
Reviewed-by: Simon McVittie <simon.mcvittie@collabora.co.uk>
[fix compilation on platforms that do not HAVE_UNIX_FD_PASSING -smcv]
Signed-off-by: Simon McVittie <simon.mcvittie@collabora.co.uk>
2014-09-15 12:30:25 +01:00
Alban Crequy
bbf11cd5f9 config: add new limit: pending_fd_timeout
This is one of four commits needed to address CVE-2014-3637.

When a file descriptor is passed to dbus-daemon, the associated D-Bus message
might not be fully sent to dbus-daemon yet. Dbus-daemon keeps the file
descriptor in the DBusMessageLoader of the connection, waiting for the rest of
the message. If the client stops sending the remaining bytes, dbus-daemon will
wait forever and keep that file descriptor.

This patch adds pending_fd_timeout (milliseconds) in the configuration to
disconnect a connection after a timeout when a file descriptor was sent but not
the remaining message.

Bug: https://bugs.freedesktop.org/show_bug.cgi?id=80559
Reviewed-by: Simon McVittie <simon.mcvittie@collabora.co.uk>
2014-09-15 12:29:30 +01:00
Alban Crequy
8ad179a8da Stop listening on DBusServer sockets when reaching max_incomplete_connections
This addresses the parts of CVE-2014-3639 not already addressed by
reducing the default authentication timeout.

Bug: https://bugs.freedesktop.org/show_bug.cgi?id=80851
Bug: https://bugs.freedesktop.org/show_bug.cgi?id=80919
Reviewed-by: Simon McVittie <simon.mcvittie@collabora.co.uk>
2014-09-15 12:28:37 +01:00
Alban Crequy
54d26df52b config: change default auth_timeout to 5 seconds
This partially addresses CVE-2014-3639.

This will change the default on the system bus where the limit
  <limit name="auth_timeout">...</limit>
is not specified.

Bug: https://bugs.freedesktop.org/show_bug.cgi?id=80919
Reviewed-by: Thiago Macieira <thiago@kde.org>
Reviewed-by: Simon McVittie <simon.mcvittie@collabora.co.uk>
2014-09-15 12:28:10 +01:00
Simon McVittie
6465e37c8f config: change DEFAULT_MESSAGE_UNIX_FDS to 16
This addresses CVE-2014-3636.

Based on a patch by Alban Crequy. Now that it's the same on all
platforms, there's little point in it being set by configure/cmake.

This change fixes two distinct denials of service:

fd.o#82820, part A
------------------

Before this patch, the system bus had the following default configuration:
- max_connections_per_user: 256
- DBUS_DEFAULT_MESSAGE_UNIX_FDS: usually 1024 (or 256 on QNX, see fd.o#61176)
  as defined by configure.ac
- max_incoming_unix_fds: DBUS_DEFAULT_MESSAGE_UNIX_FDS*4 = usually 4096
- max_outgoing_unix_fds: DBUS_DEFAULT_MESSAGE_UNIX_FDS*4 = usually 4096
- max_message_unix_fds: DBUS_DEFAULT_MESSAGE_UNIX_FDS = usually 1024

This means that a single user could create 256 connections and transmit
256*4096 = 1048576 file descriptors.

The file descriptors stay attached to the dbus-daemon process while they are
in the message loader, in the outgoing queue or waiting to be dispatched before
D-Bus activation.

dbus-daemon is usually limited to 65536 file descriptors (ulimit -n). If the
limit is reached and dbus-daemon needs to receive a message with a file
descriptor attached, this is signalled by recvfrom with the flag MSG_CTRUNC.
Dbus-daemon cannot recover from that error because the kernel does not have any
API to retrieve a file descriptor which has been discarded with MSG_CTRUNC.
Therefore, it closes the connection of the sender. This is not necessarily the
connection which generated the most file descriptors so it can lead to
denial-of-service attacks.

In order to prevent DoS issues, this patch reduces DEFAULT_MESSAGE_UNIX_FDS to
16:

max_connections_per_user * max_incoming_unix_fds = 256 * 64 = 16384

This is less than the usual "ulimit -n" (65536) with a good margin to
accomodate the other sources of file descriptors (stdin/stdout/stderr,
listening sockets, message loader, etc.).

Distributors on non-Linux may need to configure a smaller limit in
system.conf, if their limit on the number of fds is smaller than
Linux's.

fd.o#82820, part B
------------------

On Linux, it's not possible to send more than 253 fds in a single sendmsg()
call: sendmsg() would return -EINVAL.
  #define SCM_MAX_FD      253

SCM_MAX_FD changed value during Linux history:
- it used to be (OPEN_MAX-1)
- commit c09edd6eb (Jul 2007) changed it to 255
- commit bba14de98 (Nov 2010) changed it to 253

Libdbus always sends all of a message's fds, and the beginning
of the message itself, in a single sendmsg() call. Combining these
two, a malicious sender could split a message across two or more
sendmsg() calls to construct a composite message with 254 or more
fds. When dbus-daemon attempted to relay that message to its
recipient in a single sendmsg() call, it would receive EINVAL,
interpret that as a fatal socket error and disconnect the recipient,
resulting in denial of service.

This is fixed by keeping max_message_unix_fds <= SCM_MAX_FD.

Bug: https://bugs.freedesktop.org/show_bug.cgi?id=82820
Reviewed-by: Alban Crequy <alban.crequy@collabora.co.uk>
2014-09-15 12:27:26 +01:00
Alban Crequy
5bc7f9519e system bus limit: use max_replies_per_connection=128 by default
This addresses CVE-2014-3638.

Bug: https://bugs.freedesktop.org/show_bug.cgi?id=81053
Reviewed-by: Simon McVittie <simon.mcvittie@collabora.co.uk>
2014-09-15 12:27:20 +01:00
Simon McVittie
31b3809018 Replace some runtime assertions with compile-time assertions
This requires a little bit of code re-ordering, because
_DBUS_STATIC_ASSERT can appear anywhere that a variable declaration
would be valid, i.e. not after executable code.

Bug: https://bugs.freedesktop.org/show_bug.cgi?id=83767
Reviewed-by: Alban Crequy <alban.crequy@collabora.co.uk>
2014-09-15 12:22:23 +01:00
Simon McVittie
0e3d08d45c Add _DBUS_GNUC_UNUSED, and use it in _DBUS_STATIC_ASSERT
This means we can use _DBUS_STATIC_ASSERT at non-global scope without
tripping -Wunused-local-typedefs.

Bug: https://bugs.freedesktop.org/show_bug.cgi?id=83767
Reviewed-by: Alban Crequy <alban.crequy@collabora.co.uk>
2014-09-15 12:22:09 +01:00
Simon McVittie
79c35a7d5a Merge branch 'dbus-1.8' 2014-09-15 11:51:26 +01:00
Simon McVittie
900011a268 NEWS for 1.8 2014-09-15 11:50:57 +01:00
Simon McVittie
ae50d46ff2 On Linux, call prctl to disable core dumps
Whenever I forget to turn off corekeeper, the regression tests
take ages to record all test-segfault's crashes.

Bug: https://bugs.freedesktop.org/show_bug.cgi?id=83772
Reviewed-by: Alban Crequy <alban.crequy@collabora.co.uk>
2014-09-15 11:50:48 +01:00
Simon McVittie
02731e3718 Merge branch 'dbus-1.8'
Conflicts:
	NEWS
2014-09-12 12:36:20 +01:00
Simon McVittie
467f7a6d42 NEWS for 1.8.x 2014-09-12 12:35:31 +01:00
Umut Tezduyar Lindskog
ae268a2b1a enable build support without systemd compatibility libraries
systemd 209 merged all the libraries to libsystemd. Old
libraries can still be enabled with --enable-compat-libs
switch in systemd but this increases the binary size.

Implement a fallback library check in case compat libraries
dont exist.

[Fixed underquoting; switched priority so we try libsystemd first -smcv]
Signed-off-by: Simon McVittie <simon.mcvittie@collabora.co.uk>
2014-09-12 12:24:18 +01:00
Chengwei Yang
66bac8c3e3 free_pending_restore_data --> free_restore_pending_data
This patch doesn't do any function change, but only the function name,
to align its name with the struct RestorePendingData.

Bug: https://bugs.freedesktop.org/show_bug.cgi?id=72254
Reviewed-by: Simon McVittie <simon.mcvittie@collabora.co.uk>
2014-09-09 14:25:13 +01:00
Ralf Habacker
911d803af1 Port dbus_directory_...() function to use win32 native api instead of opendir()/readdir() and closedir() emulation.
This fixes a license issue introduced by the initial win32 port.

Bug: https://bugs.freedesktop.org/show_bug.cgi?id=57272
Reviewed-by: Simon McVittie <simon.mcvittie@collabora.co.uk>
2014-09-08 14:38:16 +00:00
Ralf Habacker
89c6173706 Add directory test application 'manual-dir-iter' to cmake and autotools build system.
Bug: https://bugs.freedesktop.org/show_bug.cgi?id=57272
Reviewed-by: Simon McVittie <simon.mcvittie@collabora.co.uk>
2014-09-08 14:33:37 +00:00
Ralf Habacker
0cde94ecd9 Add dbus string convenience function _dbus_string_init_from_string().
Bug: https://bugs.freedesktop.org/show_bug.cgi?id=57272
Reviewed-by: Simon McVittie <simon.mcvittie@collabora.co.uk>
2014-09-08 12:00:42 +00:00
Ralf Habacker
6c8b5ed056 Improve debug message to be able to see empty files.
Bug: https://bugs.freedesktop.org/show_bug.cgi?id=57272
Reviewed-by: Simon McVittie <simon.mcvittie@collabora.co.uk>
2014-09-08 11:58:52 +00:00
Ralf Habacker
4349033667 Merge branch 'dbus-1.8' 2014-09-07 11:37:58 +02:00
Ralf Habacker
575256cd48 Fix windows doc for running tests.
Bug: https://bugs.freedesktop.org/show_bug.cgi?id=41252
Reviewed-by: Simon McVittie <simon.mcvittie@collabora.co.uk>
2014-09-07 11:36:41 +02:00
Simon McVittie
41676a1a36 NEWS for 1.9 2014-09-05 16:51:02 +01:00
Simon McVittie
496ebc6c5e NEWS for 1.8 2014-09-05 16:48:00 +01:00
Simon McVittie
14fa1a1e75 Merge branch 'dbus-1.8' 2014-09-05 13:41:12 +01:00
Alban Crequy
e2a78c0951 Stats: fix compilation issue
Bug-Gentoo: https://bugs.gentoo.org/show_bug.cgi?id=507232
Bug: https://bugs.freedesktop.org/show_bug.cgi?id=81043
Reviewed-by: Simon McVittie <simon.mcvittie@collabora.co.uk>
2014-09-04 15:42:45 +01:00
Thomas Haller
d8be7e614e doc/dbus-tutorial: fix tutorial to reference the proper GType for 'ay'
DBUS_TYPE_G_BYTE_ARRAY does not exist. It should be DBUS_TYPE_G_UCHAR_ARRAY

Signed-off-by: Thomas Haller <thaller@redhat.com>
Reviewed-by: Simon McVittie <simon.mcvittie@collabora.co.uk>
Bug: https://bugs.freedesktop.org/show_bug.cgi?id=80795
2014-09-04 15:38:56 +01:00
Ralf Habacker
d8394d75d1 Win32 cmake msvc16 64 bit native and mingw32/64 4.8.3 cross compile fix.
This patch fixes a "missing include directory" compile error on test-print build target.

Bug: http://lists.freedesktop.org/archives/dbus/2014-August/016260.html
Reviewed-by: rony@wu.ac.at
Reviewed-by: Ralf Habacker <ralf.habacker@freenet.de>
2014-08-08 19:03:05 +02:00
Simon McVittie
a05ef3b129 Merge branch 'dbus-1.8'
Conflicts:
	NEWS
	configure.ac
2014-07-02 18:33:51 +01:00
Simon McVittie
8f31484171 start 1.8.7 2014-07-02 18:24:44 +01:00
Simon McVittie
194f6f7589 Prepare 1.8.6 in advance 2014-06-30 14:18:03 +01:00
Alban Crequy
9ca90648fc Handle ETOOMANYREFS when sending recursive fds (SCM_RIGHTS)
Since Linux commit 25888e (from 2.6.37-rc4, Nov 2010), sendmsg() on Unix
sockets returns -1 errno=ETOOMANYREFS ("Too many references: cannot splice")
when the passfd mechanism (SCM_RIGHTS) is "abusively" used recursively by
applications. A malicious client could use this to force a victim system
service to be disconnected from the system bus; the victim would likely
respond by exiting. This is a denial of service (fd.o #80163,
CVE-2014-3532).

This patch silently drops the D-Bus message on ETOOMANYREFS and does not close
the connection.

Bug: https://bugs.freedesktop.org/show_bug.cgi?id=80163
Reviewed-by: Thiago Macieira <thiago@kde.org>
[altered commit message to explain DoS significance -smcv]
Reviewed-by: Simon McVittie <simon.mcvittie@collabora.co.uk>
2014-06-30 14:09:21 +01:00
Simon McVittie
07f4c12efe If loader contains two messages with fds, don't corrupt the second
There were two bugs here: we would previously overwrite the unused
fds with the already-used fds instead of the other way round, and
we would copy n bytes where we should have copied n ints.

Additionally, sending crafted messages in a chosen sequence to a victim
system service could cause an invalid file descriptor to be present
when dbus-daemon tries to forward one of those crafted messages to the
victim, causing sendmsg() to fail with EBADF, which resulted in
disconnecting the victim service, which would likely respond to that
by exiting. This is a denial of service (fd.o #80469, CVE-2014-3533).

Bug: https://bugs.freedesktop.org/show_bug.cgi?id=79694
Bug: https://bugs.freedesktop.org/show_bug.cgi?id=80469
Reviewed-by: Alban Crequy <alban.crequy@collabora.co.uk>
2014-06-30 14:04:32 +01:00
Simon McVittie
93d98e4480 NEWS 2014-06-11 11:56:51 +01:00
Patrick Welche
5d91f615d1 bus_set_watched_dirs: portability patch for systems which lack O_CLOEXEC
Bug: https://bugs.freedesktop.org/show_bug.cgi?id=77032
Reviewed-by: Simon McVittie <simon.mcvittie@collabora.co.uk>
2014-06-11 11:56:25 +01:00
Simon McVittie
d002a430cc Merge branch 'dbus-1.8'
Conflicts:
	NEWS
	configure.ac
2014-06-11 11:46:27 +01:00