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