Blame SOURCES/dbus-1.20.8-CVE-2022-42011.patch

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