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