d790e3
From 3b8a7aff228770f4f7b478db606b10cceacea875 Mon Sep 17 00:00:00 2001
d790e3
From: Simon McVittie <smcv@collabora.com>
d790e3
Date: Mon, 12 Sep 2022 13:14:18 +0100
d790e3
Subject: [PATCH] dbus-marshal-validate: Validate length of arrays of
d790e3
 fixed-length items
d790e3
d790e3
This fast-path previously did not check that the array was made up
d790e3
of an integer number of items. This could lead to assertion failures
d790e3
and out-of-bounds accesses during subsequent message processing (which
d790e3
assumes that the message has already been validated), particularly after
d790e3
the addition of _dbus_header_remove_unknown_fields(), which makes it
d790e3
more likely that dbus-daemon will apply non-trivial edits to messages.
d790e3
d790e3
Thanks: Evgeny Vereshchagin
d790e3
Fixes: e61f13cf "Bug 18064 - more efficient validation for fixed-size type arrays"
d790e3
Resolves: https://gitlab.freedesktop.org/dbus/dbus/-/issues/413
d790e3
Resolves: CVE-2022-42011
d790e3
Signed-off-by: Simon McVittie <smcv@collabora.com>
d790e3
(cherry picked from commit 079bbf16186e87fb0157adf8951f19864bc2ed69)
d790e3
(cherry picked from commit b9e6a7523085a2cfceaffca7ba1ab4251f12a984)
d790e3
---
d790e3
 dbus/dbus-marshal-validate.c | 13 ++++++++++++-
d790e3
 1 file changed, 12 insertions(+), 1 deletion(-)
d790e3
d790e3
diff --git a/dbus/dbus-marshal-validate.c b/dbus/dbus-marshal-validate.c
d790e3
index ae68414dd..7d0d6cf72 100644
d790e3
--- a/dbus/dbus-marshal-validate.c
d790e3
+++ b/dbus/dbus-marshal-validate.c
d790e3
@@ -503,13 +503,24 @@ validate_body_helper (DBusTypeReader       *reader,
d790e3
                  */ 
d790e3
                 if (dbus_type_is_fixed (array_elem_type))
d790e3
                   {
d790e3
+                    /* Note that fixed-size types all have sizes equal to
d790e3
+                     * their alignments, so this is really the item size. */
d790e3
+                    alignment = _dbus_type_get_alignment (array_elem_type);
d790e3
+                    _dbus_assert (alignment == 1 || alignment == 2 ||
d790e3
+                                  alignment == 4 || alignment == 8);
d790e3
+
d790e3
+                    /* Because the alignment is a power of 2, this is
d790e3
+                     * equivalent to: (claimed_len % alignment) != 0,
d790e3
+                     * but avoids slower integer division */
d790e3
+                    if ((claimed_len & (alignment - 1)) != 0)
d790e3
+                      return DBUS_INVALID_ARRAY_LENGTH_INCORRECT;
d790e3
+
d790e3
                     /* bools need to be handled differently, because they can
d790e3
                      * have an invalid value
d790e3
                      */
d790e3
                     if (array_elem_type == DBUS_TYPE_BOOLEAN)
d790e3
                       {
d790e3
                         dbus_uint32_t v;
d790e3
-                        alignment = _dbus_type_get_alignment (array_elem_type);
d790e3
 
d790e3
                         while (p < array_end)
d790e3
                           {
d790e3
-- 
d790e3
GitLab
d790e3