diff options
author | Lennart Poettering <lennart@poettering.net> | 2013-12-10 01:07:09 +0100 |
---|---|---|
committer | Lennart Poettering <lennart@poettering.net> | 2013-12-10 01:07:09 +0100 |
commit | e1d337d4626728545748302735e9e382b5741e83 (patch) | |
tree | 99b42eae3bb895560d3de2bd00a02aa0dababdc8 /src/libsystemd-bus/bus-kernel.c | |
parent | d36b70313666b334cc01c0c2344070341f7d0eb3 (diff) |
bus: only accept gvariant native endian messages via kdbus
Diffstat (limited to 'src/libsystemd-bus/bus-kernel.c')
-rw-r--r-- | src/libsystemd-bus/bus-kernel.c | 18 |
1 files changed, 16 insertions, 2 deletions
diff --git a/src/libsystemd-bus/bus-kernel.c b/src/libsystemd-bus/bus-kernel.c index a3afb2eba6..d0a9fbc3fb 100644 --- a/src/libsystemd-bus/bus-kernel.c +++ b/src/libsystemd-bus/bus-kernel.c @@ -362,6 +362,7 @@ int bus_kernel_take_fd(sd_bus *b) { b->is_kernel = true; b->bus_client = true; b->can_fds = !!(hello.conn_flags & KDBUS_HELLO_ACCEPT_FD); + b->message_version = 2; /* the kernel told us the UUID of the underlying bus */ memcpy(b->server_id.bytes, hello.id128, sizeof(b->server_id.bytes)); @@ -676,6 +677,12 @@ static int bus_kernel_make_message(sd_bus *bus, struct kdbus_msg *k) { if (n_bytes != total) return -EBADMSG; + /* on kdbus we only speak native endian gvariant, never dbus1 + * marshalling or reverse endian */ + if (h->version != 2 || + h->endian != BUS_NATIVE_ENDIAN) + return -EPROTOTYPE; + r = bus_message_from_header(bus, h, sizeof(struct bus_header), fds, n_fds, NULL, seclabel, 0, &m); if (r < 0) return r; @@ -885,9 +892,16 @@ int bus_kernel_read_message(sd_bus *bus) { } k = (struct kdbus_msg *)((uint8_t *)bus->kdbus_buffer + off); - if (k->payload_type == KDBUS_PAYLOAD_DBUS) + if (k->payload_type == KDBUS_PAYLOAD_DBUS) { r = bus_kernel_make_message(bus, k); - else if (k->payload_type == KDBUS_PAYLOAD_KERNEL) + + /* Anybody can send us invalid messages, let's just drop them. */ + if (r == -EBADMSG || r == -EPROTOTYPE) { + log_error("Ignoring invalid message: %s", strerror(-r)); + r = 0; + } + + } else if (k->payload_type == KDBUS_PAYLOAD_KERNEL) r = bus_kernel_translate_message(bus, k); else r = 0; |