|
Zbigniew Jędrzejewski-Szmek |
8e6c34 |
From 72fd713962ca2c2450e23b01d9e22017a7e28fd4 Mon Sep 17 00:00:00 2001
|
|
Zbigniew Jędrzejewski-Szmek |
8e6c34 |
From: Colin Walters <walters@verbum.org>
|
|
Zbigniew Jędrzejewski-Szmek |
8e6c34 |
Date: Thu, 22 Aug 2013 13:55:21 -0400
|
|
Zbigniew Jędrzejewski-Szmek |
8e6c34 |
Subject: [PATCH] polkit: Avoid race condition in scraping /proc
|
|
Zbigniew Jędrzejewski-Szmek |
8e6c34 |
|
|
Zbigniew Jędrzejewski-Szmek |
8e6c34 |
If a calling process execve()s a setuid program, it can appear to be
|
|
Zbigniew Jędrzejewski-Szmek |
8e6c34 |
uid 0. Since we're receiving requests over DBus, avoid this by simply
|
|
Zbigniew Jędrzejewski-Szmek |
8e6c34 |
passing system-bus-name as a subject.
|
|
Zbigniew Jędrzejewski-Szmek |
8e6c34 |
---
|
|
Zbigniew Jędrzejewski-Szmek |
8e6c34 |
src/shared/polkit.c | 31 +++++--------------------------
|
|
Zbigniew Jędrzejewski-Szmek |
8e6c34 |
1 file changed, 5 insertions(+), 26 deletions(-)
|
|
Zbigniew Jędrzejewski-Szmek |
8e6c34 |
|
|
Zbigniew Jędrzejewski-Szmek |
8e6c34 |
diff --git a/src/shared/polkit.c b/src/shared/polkit.c
|
|
Zbigniew Jędrzejewski-Szmek |
8e6c34 |
index cea7074..1c5e9e3 100644
|
|
Zbigniew Jędrzejewski-Szmek |
8e6c34 |
--- a/src/shared/polkit.c
|
|
Zbigniew Jędrzejewski-Szmek |
8e6c34 |
+++ b/src/shared/polkit.c
|
|
Zbigniew Jędrzejewski-Szmek |
8e6c34 |
@@ -38,12 +38,8 @@ int verify_polkit(
|
|
Zbigniew Jędrzejewski-Szmek |
8e6c34 |
|
|
Zbigniew Jędrzejewski-Szmek |
8e6c34 |
#ifdef ENABLE_POLKIT
|
|
Zbigniew Jędrzejewski-Szmek |
8e6c34 |
DBusMessage *m = NULL, *reply = NULL;
|
|
Zbigniew Jędrzejewski-Szmek |
8e6c34 |
- const char *unix_process = "unix-process", *pid = "pid", *starttime = "start-time", *cancel_id = "";
|
|
Zbigniew Jędrzejewski-Szmek |
8e6c34 |
+ const char *system_bus_name = "system-bus-name", *name = "name", *cancel_id = "";
|
|
Zbigniew Jędrzejewski-Szmek |
8e6c34 |
uint32_t flags = interactive ? 1 : 0;
|
|
Zbigniew Jędrzejewski-Szmek |
8e6c34 |
- pid_t pid_raw;
|
|
Zbigniew Jędrzejewski-Szmek |
8e6c34 |
- uint32_t pid_u32;
|
|
Zbigniew Jędrzejewski-Szmek |
8e6c34 |
- unsigned long long starttime_raw;
|
|
Zbigniew Jędrzejewski-Szmek |
8e6c34 |
- uint64_t starttime_u64;
|
|
Zbigniew Jędrzejewski-Szmek |
8e6c34 |
DBusMessageIter iter_msg, iter_struct, iter_array, iter_dict, iter_variant;
|
|
Zbigniew Jędrzejewski-Szmek |
8e6c34 |
int r;
|
|
Zbigniew Jędrzejewski-Szmek |
8e6c34 |
dbus_bool_t authorized = FALSE, challenge = FALSE;
|
|
Zbigniew Jędrzejewski-Szmek |
8e6c34 |
@@ -68,14 +64,6 @@ int verify_polkit(
|
|
Zbigniew Jędrzejewski-Szmek |
8e6c34 |
|
|
Zbigniew Jędrzejewski-Szmek |
8e6c34 |
#ifdef ENABLE_POLKIT
|
|
Zbigniew Jędrzejewski-Szmek |
8e6c34 |
|
|
Zbigniew Jędrzejewski-Szmek |
8e6c34 |
- pid_raw = bus_get_unix_process_id(c, sender, error);
|
|
Zbigniew Jędrzejewski-Szmek |
8e6c34 |
- if (pid_raw == 0)
|
|
Zbigniew Jędrzejewski-Szmek |
8e6c34 |
- return -EINVAL;
|
|
Zbigniew Jędrzejewski-Szmek |
8e6c34 |
-
|
|
Zbigniew Jędrzejewski-Szmek |
8e6c34 |
- r = get_starttime_of_pid(pid_raw, &starttime_raw);
|
|
Zbigniew Jędrzejewski-Szmek |
8e6c34 |
- if (r < 0)
|
|
Zbigniew Jędrzejewski-Szmek |
8e6c34 |
- return r;
|
|
Zbigniew Jędrzejewski-Szmek |
8e6c34 |
-
|
|
Zbigniew Jędrzejewski-Szmek |
8e6c34 |
m = dbus_message_new_method_call(
|
|
Zbigniew Jędrzejewski-Szmek |
8e6c34 |
"org.freedesktop.PolicyKit1",
|
|
Zbigniew Jędrzejewski-Szmek |
8e6c34 |
"/org/freedesktop/PolicyKit1/Authority",
|
|
Zbigniew Jędrzejewski-Szmek |
8e6c34 |
@@ -86,22 +74,13 @@ int verify_polkit(
|
|
Zbigniew Jędrzejewski-Szmek |
8e6c34 |
|
|
Zbigniew Jędrzejewski-Szmek |
8e6c34 |
dbus_message_iter_init_append(m, &iter_msg);
|
|
Zbigniew Jędrzejewski-Szmek |
8e6c34 |
|
|
Zbigniew Jędrzejewski-Szmek |
8e6c34 |
- pid_u32 = (uint32_t) pid_raw;
|
|
Zbigniew Jędrzejewski-Szmek |
8e6c34 |
- starttime_u64 = (uint64_t) starttime_raw;
|
|
Zbigniew Jędrzejewski-Szmek |
8e6c34 |
-
|
|
Zbigniew Jędrzejewski-Szmek |
8e6c34 |
if (!dbus_message_iter_open_container(&iter_msg, DBUS_TYPE_STRUCT, NULL, &iter_struct) ||
|
|
Zbigniew Jędrzejewski-Szmek |
8e6c34 |
- !dbus_message_iter_append_basic(&iter_struct, DBUS_TYPE_STRING, &unix_process) ||
|
|
Zbigniew Jędrzejewski-Szmek |
8e6c34 |
+ !dbus_message_iter_append_basic(&iter_struct, DBUS_TYPE_STRING, &system_bus_name) ||
|
|
Zbigniew Jędrzejewski-Szmek |
8e6c34 |
!dbus_message_iter_open_container(&iter_struct, DBUS_TYPE_ARRAY, "{sv}", &iter_array) ||
|
|
Zbigniew Jędrzejewski-Szmek |
8e6c34 |
!dbus_message_iter_open_container(&iter_array, DBUS_TYPE_DICT_ENTRY, NULL, &iter_dict) ||
|
|
Zbigniew Jędrzejewski-Szmek |
8e6c34 |
- !dbus_message_iter_append_basic(&iter_dict, DBUS_TYPE_STRING, &pid) ||
|
|
Zbigniew Jędrzejewski-Szmek |
8e6c34 |
- !dbus_message_iter_open_container(&iter_dict, DBUS_TYPE_VARIANT, "u", &iter_variant) ||
|
|
Zbigniew Jędrzejewski-Szmek |
8e6c34 |
- !dbus_message_iter_append_basic(&iter_variant, DBUS_TYPE_UINT32, &pid_u32) ||
|
|
Zbigniew Jędrzejewski-Szmek |
8e6c34 |
- !dbus_message_iter_close_container(&iter_dict, &iter_variant) ||
|
|
Zbigniew Jędrzejewski-Szmek |
8e6c34 |
- !dbus_message_iter_close_container(&iter_array, &iter_dict) ||
|
|
Zbigniew Jędrzejewski-Szmek |
8e6c34 |
- !dbus_message_iter_open_container(&iter_array, DBUS_TYPE_DICT_ENTRY, NULL, &iter_dict) ||
|
|
Zbigniew Jędrzejewski-Szmek |
8e6c34 |
- !dbus_message_iter_append_basic(&iter_dict, DBUS_TYPE_STRING, &starttime) ||
|
|
Zbigniew Jędrzejewski-Szmek |
8e6c34 |
- !dbus_message_iter_open_container(&iter_dict, DBUS_TYPE_VARIANT, "t", &iter_variant) ||
|
|
Zbigniew Jędrzejewski-Szmek |
8e6c34 |
- !dbus_message_iter_append_basic(&iter_variant, DBUS_TYPE_UINT64, &starttime_u64) ||
|
|
Zbigniew Jędrzejewski-Szmek |
8e6c34 |
+ !dbus_message_iter_append_basic(&iter_dict, DBUS_TYPE_STRING, &name) ||
|
|
Zbigniew Jędrzejewski-Szmek |
8e6c34 |
+ !dbus_message_iter_open_container(&iter_dict, DBUS_TYPE_VARIANT, "s", &iter_variant) ||
|
|
Zbigniew Jędrzejewski-Szmek |
8e6c34 |
+ !dbus_message_iter_append_basic(&iter_variant, DBUS_TYPE_STRING, &sender) ||
|
|
Zbigniew Jędrzejewski-Szmek |
8e6c34 |
!dbus_message_iter_close_container(&iter_dict, &iter_variant) ||
|
|
Zbigniew Jędrzejewski-Szmek |
8e6c34 |
!dbus_message_iter_close_container(&iter_array, &iter_dict) ||
|
|
Zbigniew Jędrzejewski-Szmek |
8e6c34 |
!dbus_message_iter_close_container(&iter_struct, &iter_array) ||
|
|
Zbigniew Jędrzejewski-Szmek |
8e6c34 |
--
|
|
Zbigniew Jędrzejewski-Szmek |
8e6c34 |
1.8.3.1
|
|
Zbigniew Jędrzejewski-Szmek |
8e6c34 |
|