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 | |
parent | d36b70313666b334cc01c0c2344070341f7d0eb3 (diff) |
bus: only accept gvariant native endian messages via kdbus
Diffstat (limited to 'src/libsystemd-bus')
-rw-r--r-- | src/libsystemd-bus/bus-kernel.c | 18 | ||||
-rw-r--r-- | src/libsystemd-bus/bus-socket.c | 7 |
2 files changed, 23 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; diff --git a/src/libsystemd-bus/bus-socket.c b/src/libsystemd-bus/bus-socket.c index 69f78c9a58..a449ce0eb3 100644 --- a/src/libsystemd-bus/bus-socket.c +++ b/src/libsystemd-bus/bus-socket.c @@ -623,6 +623,9 @@ int bus_socket_setup(sd_bus *b) { if (getsockopt(b->input_fd, SOL_SOCKET, SO_PEERCRED, &b->ucred, &l) >= 0 && l >= sizeof(b->ucred)) b->ucred_valid = b->ucred.pid > 0; + b->is_kernel = false; + b->message_version = 1; + return 0; } @@ -765,6 +768,10 @@ int bus_socket_exec(sd_bus *b) { close_nointr_nofail(s[1]); b->output_fd = b->input_fd = s[0]; + r = bus_socket_setup(b); + if (r < 0) + return r; + return bus_socket_start_auth(b); } |