Blame SOURCES/1add8a7d60e46806e0ef87994d3024245db0d84a.patch

3bac29
From 1add8a7d60e46806e0ef87994d3024245db0d84a Mon Sep 17 00:00:00 2001
3bac29
From: David Rheinsberg <david.rheinsberg@gmail.com>
3bac29
Date: Thu, 18 Mar 2021 11:10:02 +0100
3bac29
Subject: [PATCH] launch/policy: fix incorrect assertion for at_console
3bac29
3bac29
We write at_console policies for ranges of uids. If one of those ranges
3bac29
is 0, an overflow assertion will incorrectly fire. Fix this and simplify
3bac29
the assertions for better readability.
3bac29
3bac29
Note that such empty ranges will happen if more than one user on the
3bac29
system is considered `at_console` **and** those users have consecutive
3bac29
UIDs. Another possibility for empty ranges is when uid 0 is considered
3bac29
at_console.
3bac29
3bac29
In any case, the assertion will abort the application incorrectly. So
3bac29
this is not a security issue, but merely an incorrect assertion.
3bac29
3bac29
Signed-off-by: David Rheinsberg <david.rheinsberg@gmail.com>
3bac29
---
3bac29
 src/launch/policy.c | 5 ++++-
3bac29
 1 file changed, 4 insertions(+), 1 deletion(-)
3bac29
3bac29
diff --git a/src/launch/policy.c b/src/launch/policy.c
3bac29
index f91f11b..75eb0d3 100644
3bac29
--- a/src/launch/policy.c
3bac29
+++ b/src/launch/policy.c
3bac29
@@ -934,7 +934,10 @@ static int policy_export_xmit(Policy *policy, CList *list1, CList *list2, sd_bus
3bac29
 static int policy_export_console(Policy *policy, sd_bus_message *m, PolicyEntries *entries, uint32_t uid_start, uint32_t n_uid) {
3bac29
         int r;
3bac29
 
3bac29
-        c_assert(((uint32_t)-1) - n_uid + 1 >= uid_start);
3bac29
+        /* check for overflow */
3bac29
+        c_assert(uid_start + n_uid >= uid_start);
3bac29
+        /* check for encoding into dbus `u` type */
3bac29
+        c_assert(uid_start + n_uid <= (uint32_t)-1);
3bac29
 
3bac29
         if (n_uid == 0)
3bac29
                 return 0;