|
|
4b5a22 |
From 8f382ee405ec68850866298ba0574f12e261a6fa Mon Sep 17 00:00:00 2001
|
|
|
4b5a22 |
From: Simon McVittie <smcv@collabora.com>
|
|
|
4b5a22 |
Date: Tue, 13 Sep 2022 15:10:22 +0100
|
|
|
4b5a22 |
Subject: [PATCH] dbus-marshal-validate: Check brackets in signature nest
|
|
|
4b5a22 |
correctly
|
|
|
4b5a22 |
|
|
|
4b5a22 |
In debug builds with assertions enabled, a signature with incorrectly
|
|
|
4b5a22 |
nested `()` and `{}`, for example `a{i(u}` or `(a{ii)}`, could result
|
|
|
4b5a22 |
in an assertion failure.
|
|
|
4b5a22 |
|
|
|
4b5a22 |
In production builds without assertions enabled, a signature with
|
|
|
4b5a22 |
incorrectly nested `()` and `{}` could potentially result in a crash
|
|
|
4b5a22 |
or incorrect message parsing, although we do not have a concrete example
|
|
|
4b5a22 |
of either of these failure modes.
|
|
|
4b5a22 |
|
|
|
4b5a22 |
Thanks: Evgeny Vereshchagin
|
|
|
4b5a22 |
Resolves: https://gitlab.freedesktop.org/dbus/dbus/-/issues/418
|
|
|
4b5a22 |
Resolves: CVE-2022-42010
|
|
|
4b5a22 |
Signed-off-by: Simon McVittie <smcv@collabora.com>
|
|
|
4b5a22 |
(cherry picked from commit 9d07424e9011e3bbe535e83043d335f3093d2916)
|
|
|
4b5a22 |
(cherry picked from commit 3e53a785dee8d1432156188a2c4260e4cbc78c4d)
|
|
|
4b5a22 |
---
|
|
|
4b5a22 |
dbus/dbus-marshal-validate.c | 38 +++++++++++++++++++++++++++++++++++-
|
|
|
4b5a22 |
1 file changed, 37 insertions(+), 1 deletion(-)
|
|
|
4b5a22 |
|
|
|
4b5a22 |
diff --git a/dbus/dbus-marshal-validate.c b/dbus/dbus-marshal-validate.c
|
|
|
4b5a22 |
index 4d492f3f3..ae68414dd 100644
|
|
|
4b5a22 |
--- a/dbus/dbus-marshal-validate.c
|
|
|
4b5a22 |
+++ b/dbus/dbus-marshal-validate.c
|
|
|
4b5a22 |
@@ -62,6 +62,8 @@ _dbus_validate_signature_with_reason (const DBusString *type_str,
|
|
|
4b5a22 |
|
|
|
4b5a22 |
int element_count;
|
|
|
4b5a22 |
DBusList *element_count_stack;
|
|
|
4b5a22 |
+ char opened_brackets[DBUS_MAXIMUM_TYPE_RECURSION_DEPTH * 2 + 1] = { '\0' };
|
|
|
4b5a22 |
+ char last_bracket;
|
|
|
4b5a22 |
|
|
|
4b5a22 |
result = DBUS_VALID;
|
|
|
4b5a22 |
element_count_stack = NULL;
|
|
|
4b5a22 |
@@ -93,6 +95,10 @@ _dbus_validate_signature_with_reason (const DBusString *type_str,
|
|
|
4b5a22 |
|
|
|
4b5a22 |
while (p != end)
|
|
|
4b5a22 |
{
|
|
|
4b5a22 |
+ _dbus_assert (struct_depth + dict_entry_depth >= 0);
|
|
|
4b5a22 |
+ _dbus_assert (struct_depth + dict_entry_depth < _DBUS_N_ELEMENTS (opened_brackets));
|
|
|
4b5a22 |
+ _dbus_assert (opened_brackets[struct_depth + dict_entry_depth] == '\0');
|
|
|
4b5a22 |
+
|
|
|
4b5a22 |
switch (*p)
|
|
|
4b5a22 |
{
|
|
|
4b5a22 |
case DBUS_TYPE_BYTE:
|
|
|
4b5a22 |
@@ -136,6 +142,10 @@ _dbus_validate_signature_with_reason (const DBusString *type_str,
|
|
|
4b5a22 |
goto out;
|
|
|
4b5a22 |
}
|
|
|
4b5a22 |
|
|
|
4b5a22 |
+ _dbus_assert (struct_depth + dict_entry_depth >= 1);
|
|
|
4b5a22 |
+ _dbus_assert (struct_depth + dict_entry_depth < _DBUS_N_ELEMENTS (opened_brackets));
|
|
|
4b5a22 |
+ _dbus_assert (opened_brackets[struct_depth + dict_entry_depth - 1] == '\0');
|
|
|
4b5a22 |
+ opened_brackets[struct_depth + dict_entry_depth - 1] = DBUS_STRUCT_BEGIN_CHAR;
|
|
|
4b5a22 |
break;
|
|
|
4b5a22 |
|
|
|
4b5a22 |
case DBUS_STRUCT_END_CHAR:
|
|
|
4b5a22 |
@@ -151,9 +161,20 @@ _dbus_validate_signature_with_reason (const DBusString *type_str,
|
|
|
4b5a22 |
goto out;
|
|
|
4b5a22 |
}
|
|
|
4b5a22 |
|
|
|
4b5a22 |
+ _dbus_assert (struct_depth + dict_entry_depth >= 1);
|
|
|
4b5a22 |
+ _dbus_assert (struct_depth + dict_entry_depth < _DBUS_N_ELEMENTS (opened_brackets));
|
|
|
4b5a22 |
+ last_bracket = opened_brackets[struct_depth + dict_entry_depth - 1];
|
|
|
4b5a22 |
+
|
|
|
4b5a22 |
+ if (last_bracket != DBUS_STRUCT_BEGIN_CHAR)
|
|
|
4b5a22 |
+ {
|
|
|
4b5a22 |
+ result = DBUS_INVALID_STRUCT_ENDED_BUT_NOT_STARTED;
|
|
|
4b5a22 |
+ goto out;
|
|
|
4b5a22 |
+ }
|
|
|
4b5a22 |
+
|
|
|
4b5a22 |
_dbus_list_pop_last (&element_count_stack);
|
|
|
4b5a22 |
|
|
|
4b5a22 |
struct_depth -= 1;
|
|
|
4b5a22 |
+ opened_brackets[struct_depth + dict_entry_depth] = '\0';
|
|
|
4b5a22 |
break;
|
|
|
4b5a22 |
|
|
|
4b5a22 |
case DBUS_DICT_ENTRY_BEGIN_CHAR:
|
|
|
4b5a22 |
@@ -178,6 +199,10 @@ _dbus_validate_signature_with_reason (const DBusString *type_str,
|
|
|
4b5a22 |
goto out;
|
|
|
4b5a22 |
}
|
|
|
4b5a22 |
|
|
|
4b5a22 |
+ _dbus_assert (struct_depth + dict_entry_depth >= 1);
|
|
|
4b5a22 |
+ _dbus_assert (struct_depth + dict_entry_depth < _DBUS_N_ELEMENTS (opened_brackets));
|
|
|
4b5a22 |
+ _dbus_assert (opened_brackets[struct_depth + dict_entry_depth - 1] == '\0');
|
|
|
4b5a22 |
+ opened_brackets[struct_depth + dict_entry_depth - 1] = DBUS_DICT_ENTRY_BEGIN_CHAR;
|
|
|
4b5a22 |
break;
|
|
|
4b5a22 |
|
|
|
4b5a22 |
case DBUS_DICT_ENTRY_END_CHAR:
|
|
|
4b5a22 |
@@ -186,8 +211,19 @@ _dbus_validate_signature_with_reason (const DBusString *type_str,
|
|
|
4b5a22 |
result = DBUS_INVALID_DICT_ENTRY_ENDED_BUT_NOT_STARTED;
|
|
|
4b5a22 |
goto out;
|
|
|
4b5a22 |
}
|
|
|
4b5a22 |
-
|
|
|
4b5a22 |
+
|
|
|
4b5a22 |
+ _dbus_assert (struct_depth + dict_entry_depth >= 1);
|
|
|
4b5a22 |
+ _dbus_assert (struct_depth + dict_entry_depth < _DBUS_N_ELEMENTS (opened_brackets));
|
|
|
4b5a22 |
+ last_bracket = opened_brackets[struct_depth + dict_entry_depth - 1];
|
|
|
4b5a22 |
+
|
|
|
4b5a22 |
+ if (last_bracket != DBUS_DICT_ENTRY_BEGIN_CHAR)
|
|
|
4b5a22 |
+ {
|
|
|
4b5a22 |
+ result = DBUS_INVALID_DICT_ENTRY_ENDED_BUT_NOT_STARTED;
|
|
|
4b5a22 |
+ goto out;
|
|
|
4b5a22 |
+ }
|
|
|
4b5a22 |
+
|
|
|
4b5a22 |
dict_entry_depth -= 1;
|
|
|
4b5a22 |
+ opened_brackets[struct_depth + dict_entry_depth] = '\0';
|
|
|
4b5a22 |
|
|
|
4b5a22 |
element_count =
|
|
|
4b5a22 |
_DBUS_POINTER_TO_INT (_dbus_list_pop_last (&element_count_stack));
|
|
|
4b5a22 |
--
|
|
|
4b5a22 |
GitLab
|
|
|
4b5a22 |
|