|
|
c2dfb7 |
From 9c23ceef0a08ffdf4aed7a96ec440e1b110568ac Mon Sep 17 00:00:00 2001
|
|
|
c2dfb7 |
From: Lennart Poettering <lennart@poettering.net>
|
|
|
c2dfb7 |
Date: Thu, 17 Jan 2019 18:14:17 +0100
|
|
|
c2dfb7 |
Subject: [PATCH] sd-bus: reorder bus ref and bus message ref handling
|
|
|
c2dfb7 |
|
|
|
c2dfb7 |
Let's always place handling of these references together, so that all
|
|
|
c2dfb7 |
reference counting during allocation is at a single place.
|
|
|
c2dfb7 |
|
|
|
c2dfb7 |
(cherry picked from commit e593b6a87a335267e5f7238b14683b7f840a01a3)
|
|
|
c2dfb7 |
Related: CVE-2020-1712
|
|
|
c2dfb7 |
---
|
|
|
c2dfb7 |
src/libsystemd/sd-bus/bus-message.c | 5 +++--
|
|
|
c2dfb7 |
1 file changed, 3 insertions(+), 2 deletions(-)
|
|
|
c2dfb7 |
|
|
|
c2dfb7 |
diff --git a/src/libsystemd/sd-bus/bus-message.c b/src/libsystemd/sd-bus/bus-message.c
|
|
|
c2dfb7 |
index 19cb2b9a97..e9cdf46c91 100644
|
|
|
c2dfb7 |
--- a/src/libsystemd/sd-bus/bus-message.c
|
|
|
c2dfb7 |
+++ b/src/libsystemd/sd-bus/bus-message.c
|
|
|
c2dfb7 |
@@ -461,7 +461,6 @@ int bus_message_from_header(
|
|
|
c2dfb7 |
if (!m)
|
|
|
c2dfb7 |
return -ENOMEM;
|
|
|
c2dfb7 |
|
|
|
c2dfb7 |
- m->n_ref = 1;
|
|
|
c2dfb7 |
m->sealed = true;
|
|
|
c2dfb7 |
m->header = header;
|
|
|
c2dfb7 |
m->header_accessible = header_accessible;
|
|
|
c2dfb7 |
@@ -515,7 +514,9 @@ int bus_message_from_header(
|
|
|
c2dfb7 |
m->creds.mask |= SD_BUS_CREDS_SELINUX_CONTEXT;
|
|
|
c2dfb7 |
}
|
|
|
c2dfb7 |
|
|
|
c2dfb7 |
+ m->n_ref = 1;
|
|
|
c2dfb7 |
m->bus = sd_bus_ref(bus);
|
|
|
c2dfb7 |
+
|
|
|
c2dfb7 |
*ret = TAKE_PTR(m);
|
|
|
c2dfb7 |
|
|
|
c2dfb7 |
return 0;
|
|
|
c2dfb7 |
@@ -588,13 +589,13 @@ _public_ int sd_bus_message_new(
|
|
|
c2dfb7 |
return -ENOMEM;
|
|
|
c2dfb7 |
|
|
|
c2dfb7 |
t->n_ref = 1;
|
|
|
c2dfb7 |
+ t->bus = sd_bus_ref(bus);
|
|
|
c2dfb7 |
t->header = (struct bus_header*) ((uint8_t*) t + ALIGN(sizeof(struct sd_bus_message)));
|
|
|
c2dfb7 |
t->header->endian = BUS_NATIVE_ENDIAN;
|
|
|
c2dfb7 |
t->header->type = type;
|
|
|
c2dfb7 |
t->header->version = bus->message_version;
|
|
|
c2dfb7 |
t->allow_fds = bus->can_fds || !IN_SET(bus->state, BUS_HELLO, BUS_RUNNING);
|
|
|
c2dfb7 |
t->root_container.need_offsets = BUS_MESSAGE_IS_GVARIANT(t);
|
|
|
c2dfb7 |
- t->bus = sd_bus_ref(bus);
|
|
|
c2dfb7 |
|
|
|
c2dfb7 |
if (bus->allow_interactive_authorization)
|
|
|
c2dfb7 |
t->header->flags |= BUS_MESSAGE_ALLOW_INTERACTIVE_AUTHORIZATION;
|