|
|
84be87 |
From 3418f4e500e6589e21bfcc545b3d4d1d70b17390 Mon Sep 17 00:00:00 2001
|
|
|
84be87 |
From: Simon McVittie <smcv@collabora.com>
|
|
|
84be87 |
Date: Thu, 16 Apr 2020 14:45:11 +0100
|
|
|
84be87 |
Subject: [PATCH] sysdeps-unix: On MSG_CTRUNC, close the fds we did receive
|
|
|
84be87 |
|
|
|
84be87 |
MSG_CTRUNC indicates that we have received fewer fds that we should
|
|
|
84be87 |
have done because the buffer was too small, but we were treating it
|
|
|
84be87 |
as though it indicated that we received *no* fds. If we received any,
|
|
|
84be87 |
we still have to make sure we close them, otherwise they will be leaked.
|
|
|
84be87 |
|
|
|
84be87 |
On the system bus, if an attacker can induce us to leak fds in this
|
|
|
84be87 |
way, that's a local denial of service via resource exhaustion.
|
|
|
84be87 |
|
|
|
84be87 |
[Backport to dbus-1.10: Change signedness of iterator due to
|
|
|
84be87 |
commit ab8cb96e "_dbus_read_socket_with_unix_fds: make n_fds unsigned"
|
|
|
84be87 |
not having been applied to this branch.]
|
|
|
84be87 |
|
|
|
84be87 |
Reported-by: Kevin Backhouse, GitHub Security Lab
|
|
|
84be87 |
Fixes: dbus#294
|
|
|
84be87 |
Fixes: CVE-2020-12049
|
|
|
84be87 |
Fixes: GHSL-2020-057
|
|
|
84be87 |
---
|
|
|
84be87 |
dbus/dbus-sysdeps-unix.c | 32 ++++++++++++++++++++------------
|
|
|
84be87 |
1 file changed, 20 insertions(+), 12 deletions(-)
|
|
|
84be87 |
|
|
|
84be87 |
diff --git a/dbus/dbus-sysdeps-unix.c b/dbus/dbus-sysdeps-unix.c
|
|
|
84be87 |
index b73097124..6303dbc4c 100644
|
|
|
84be87 |
--- a/dbus/dbus-sysdeps-unix.c
|
|
|
84be87 |
+++ b/dbus/dbus-sysdeps-unix.c
|
|
|
84be87 |
@@ -432,18 +432,6 @@ _dbus_read_socket_with_unix_fds (DBusSocket fd,
|
|
|
84be87 |
struct cmsghdr *cm;
|
|
|
84be87 |
dbus_bool_t found = FALSE;
|
|
|
84be87 |
|
|
|
84be87 |
- if (m.msg_flags & MSG_CTRUNC)
|
|
|
84be87 |
- {
|
|
|
84be87 |
- /* Hmm, apparently the control data was truncated. The bad
|
|
|
84be87 |
- thing is that we might have completely lost a couple of fds
|
|
|
84be87 |
- without chance to recover them. Hence let's treat this as a
|
|
|
84be87 |
- serious error. */
|
|
|
84be87 |
-
|
|
|
84be87 |
- errno = ENOSPC;
|
|
|
84be87 |
- _dbus_string_set_length (buffer, start);
|
|
|
84be87 |
- return -1;
|
|
|
84be87 |
- }
|
|
|
84be87 |
-
|
|
|
84be87 |
for (cm = CMSG_FIRSTHDR(&m); cm; cm = CMSG_NXTHDR(&m, cm))
|
|
|
84be87 |
if (cm->cmsg_level == SOL_SOCKET && cm->cmsg_type == SCM_RIGHTS)
|
|
|
84be87 |
{
|
|
|
84be87 |
@@ -498,6 +486,26 @@ _dbus_read_socket_with_unix_fds (DBusSocket fd,
|
|
|
84be87 |
if (!found)
|
|
|
84be87 |
*n_fds = 0;
|
|
|
84be87 |
|
|
|
84be87 |
+ if (m.msg_flags & MSG_CTRUNC)
|
|
|
84be87 |
+ {
|
|
|
84be87 |
+ int i;
|
|
|
84be87 |
+
|
|
|
84be87 |
+ /* Hmm, apparently the control data was truncated. The bad
|
|
|
84be87 |
+ thing is that we might have completely lost a couple of fds
|
|
|
84be87 |
+ without chance to recover them. Hence let's treat this as a
|
|
|
84be87 |
+ serious error. */
|
|
|
84be87 |
+
|
|
|
84be87 |
+ /* We still need to close whatever fds we *did* receive,
|
|
|
84be87 |
+ * otherwise they'll never get closed. (CVE-2020-12049) */
|
|
|
84be87 |
+ for (i = 0; i < *n_fds; i++)
|
|
|
84be87 |
+ close (fds[i]);
|
|
|
84be87 |
+
|
|
|
84be87 |
+ *n_fds = 0;
|
|
|
84be87 |
+ errno = ENOSPC;
|
|
|
84be87 |
+ _dbus_string_set_length (buffer, start);
|
|
|
84be87 |
+ return -1;
|
|
|
84be87 |
+ }
|
|
|
84be87 |
+
|
|
|
84be87 |
/* put length back (doesn't actually realloc) */
|
|
|
84be87 |
_dbus_string_set_length (buffer, start + bytes_read);
|
|
|
84be87 |
|
|
|
84be87 |
--
|
|
|
84be87 |
GitLab
|
|
|
84be87 |
|