|
|
5d2ee9 |
From 8efdae75ddf035c8c04983820f8d8cf767cc17b1 Mon Sep 17 00:00:00 2001
|
|
|
5d2ee9 |
From: Jan Synacek <jsynacek@redhat.com>
|
|
|
5d2ee9 |
Date: Fri, 31 Jan 2020 11:34:45 +0100
|
|
|
5d2ee9 |
Subject: [PATCH] sd-bus: introduce API for re-enqueuing incoming messages
|
|
|
5d2ee9 |
|
|
|
5d2ee9 |
When authorizing via PolicyKit we want to process incoming method calls
|
|
|
5d2ee9 |
twice: once to process and figure out that we need PK authentication,
|
|
|
5d2ee9 |
and a second time after we aquired PK authentication to actually execute
|
|
|
5d2ee9 |
the operation. With this new call sd_bus_enqueue_for_read() we have a
|
|
|
5d2ee9 |
way to put an incoming message back into the read queue for this
|
|
|
5d2ee9 |
purpose.
|
|
|
5d2ee9 |
|
|
|
5d2ee9 |
This might have other uses too, for example debugging.
|
|
|
5d2ee9 |
Related: CVE-2020-1712
|
|
|
5d2ee9 |
---
|
|
|
5d2ee9 |
src/libsystemd/libsystemd.sym | 1 +
|
|
|
5d2ee9 |
src/libsystemd/sd-bus/sd-bus.c | 24 ++++++++++++++++++++++++
|
|
|
5d2ee9 |
src/systemd/sd-bus.h | 1 +
|
|
|
5d2ee9 |
3 files changed, 26 insertions(+)
|
|
|
5d2ee9 |
|
|
|
5d2ee9 |
diff --git a/src/libsystemd/libsystemd.sym b/src/libsystemd/libsystemd.sym
|
|
|
5d2ee9 |
index 1eec17db50..e9972593a6 100644
|
|
|
5d2ee9 |
--- a/src/libsystemd/libsystemd.sym
|
|
|
5d2ee9 |
+++ b/src/libsystemd/libsystemd.sym
|
|
|
5d2ee9 |
@@ -569,4 +569,5 @@ global:
|
|
|
5d2ee9 |
sd_event_source_get_inotify_mask;
|
|
|
5d2ee9 |
sd_event_source_set_destroy_callback;
|
|
|
5d2ee9 |
sd_event_source_get_destroy_callback;
|
|
|
5d2ee9 |
+ sd_bus_enqueue_for_read;
|
|
|
5d2ee9 |
} LIBSYSTEMD_238;
|
|
|
5d2ee9 |
diff --git a/src/libsystemd/sd-bus/sd-bus.c b/src/libsystemd/sd-bus/sd-bus.c
|
|
|
5d2ee9 |
index e49d58137d..68ad6cbe89 100644
|
|
|
5d2ee9 |
--- a/src/libsystemd/sd-bus/sd-bus.c
|
|
|
5d2ee9 |
+++ b/src/libsystemd/sd-bus/sd-bus.c
|
|
|
5d2ee9 |
@@ -4120,3 +4120,27 @@ _public_ int sd_bus_get_n_queued_write(sd_bus *bus, uint64_t *ret) {
|
|
|
5d2ee9 |
*ret = bus->wqueue_size;
|
|
|
5d2ee9 |
return 0;
|
|
|
5d2ee9 |
}
|
|
|
5d2ee9 |
+
|
|
|
5d2ee9 |
+_public_ int sd_bus_enqueue_for_read(sd_bus *bus, sd_bus_message *m) {
|
|
|
5d2ee9 |
+ int r;
|
|
|
5d2ee9 |
+
|
|
|
5d2ee9 |
+ assert_return(bus, -EINVAL);
|
|
|
5d2ee9 |
+ assert_return(bus = bus_resolve(bus), -ENOPKG);
|
|
|
5d2ee9 |
+ assert_return(m, -EINVAL);
|
|
|
5d2ee9 |
+ assert_return(m->sealed, -EINVAL);
|
|
|
5d2ee9 |
+ assert_return(!bus_pid_changed(bus), -ECHILD);
|
|
|
5d2ee9 |
+
|
|
|
5d2ee9 |
+ if (!BUS_IS_OPEN(bus->state))
|
|
|
5d2ee9 |
+ return -ENOTCONN;
|
|
|
5d2ee9 |
+
|
|
|
5d2ee9 |
+ /* Re-enqeue a message for reading. This is primarily useful for PolicyKit-style authentication,
|
|
|
5d2ee9 |
+ * where we want accept a message, then determine we need to interactively authenticate the user, and
|
|
|
5d2ee9 |
+ * when we have that process the message again. */
|
|
|
5d2ee9 |
+
|
|
|
5d2ee9 |
+ r = bus_rqueue_make_room(bus);
|
|
|
5d2ee9 |
+ if (r < 0)
|
|
|
5d2ee9 |
+ return r;
|
|
|
5d2ee9 |
+
|
|
|
5d2ee9 |
+ bus->rqueue[bus->rqueue_size++] = bus_message_ref_queued(m, bus);
|
|
|
5d2ee9 |
+ return 0;
|
|
|
5d2ee9 |
+}
|
|
|
5d2ee9 |
diff --git a/src/systemd/sd-bus.h b/src/systemd/sd-bus.h
|
|
|
5d2ee9 |
index 54c4b1ca83..9ba757b13d 100644
|
|
|
5d2ee9 |
--- a/src/systemd/sd-bus.h
|
|
|
5d2ee9 |
+++ b/src/systemd/sd-bus.h
|
|
|
5d2ee9 |
@@ -193,6 +193,7 @@ int sd_bus_process(sd_bus *bus, sd_bus_message **r);
|
|
|
5d2ee9 |
int sd_bus_process_priority(sd_bus *bus, int64_t max_priority, sd_bus_message **r);
|
|
|
5d2ee9 |
int sd_bus_wait(sd_bus *bus, uint64_t timeout_usec);
|
|
|
5d2ee9 |
int sd_bus_flush(sd_bus *bus);
|
|
|
5d2ee9 |
+int sd_bus_enqueue_for_read(sd_bus *bus, sd_bus_message *m);
|
|
|
5d2ee9 |
|
|
|
5d2ee9 |
sd_bus_slot* sd_bus_get_current_slot(sd_bus *bus);
|
|
|
5d2ee9 |
sd_bus_message* sd_bus_get_current_message(sd_bus *bus);
|