|
|
803fb7 |
From d0986e46b74de3b131fccbf79bd00de5ff054f71 Mon Sep 17 00:00:00 2001
|
|
|
803fb7 |
From: =?UTF-8?q?Zbigniew=20J=C4=99drzejewski-Szmek?= <zbyszek@in.waw.pl>
|
|
|
803fb7 |
Date: Sat, 6 Jun 2015 18:59:27 -0400
|
|
|
803fb7 |
Subject: [PATCH] sd-bus: do not use per-datagram auxiliary information
|
|
|
803fb7 |
|
|
|
803fb7 |
SELinux information cannot be retrieved this way, since we are
|
|
|
803fb7 |
using stream unix sockets and SCM_SECURITY does not work for
|
|
|
803fb7 |
them.
|
|
|
803fb7 |
|
|
|
803fb7 |
SCM_CREDENTIALS use dropped to be consistent. We also should
|
|
|
803fb7 |
get this information at connection time.
|
|
|
803fb7 |
|
|
|
803fb7 |
https://bugzilla.redhat.com/show_bug.cgi?id=1224211
|
|
|
803fb7 |
"SCM_SECURITY was only added for datagram sockets."
|
|
|
803fb7 |
|
|
|
803fb7 |
Cherry-picked from: d868f2a
|
|
|
803fb7 |
Related: #1230190
|
|
|
803fb7 |
---
|
|
|
803fb7 |
src/libsystemd/sd-bus/bus-socket.c | 70 +++++++-------------------------------
|
|
|
803fb7 |
1 file changed, 12 insertions(+), 58 deletions(-)
|
|
|
803fb7 |
|
|
|
803fb7 |
diff --git a/src/libsystemd/sd-bus/bus-socket.c b/src/libsystemd/sd-bus/bus-socket.c
|
|
|
803fb7 |
index 52883fa8c..abd9ece01 100644
|
|
|
803fb7 |
--- a/src/libsystemd/sd-bus/bus-socket.c
|
|
|
803fb7 |
+++ b/src/libsystemd/sd-bus/bus-socket.c
|
|
|
803fb7 |
@@ -501,9 +501,7 @@ static int bus_socket_read_auth(sd_bus *b) {
|
|
|
803fb7 |
void *p;
|
|
|
803fb7 |
union {
|
|
|
803fb7 |
struct cmsghdr cmsghdr;
|
|
|
803fb7 |
- uint8_t buf[CMSG_SPACE(sizeof(int) * BUS_FDS_MAX) +
|
|
|
803fb7 |
- CMSG_SPACE(sizeof(struct ucred)) +
|
|
|
803fb7 |
- CMSG_SPACE(NAME_MAX)]; /*selinux label */
|
|
|
803fb7 |
+ uint8_t buf[CMSG_SPACE(sizeof(int) * BUS_FDS_MAX)];
|
|
|
803fb7 |
} control;
|
|
|
803fb7 |
struct cmsghdr *cmsg;
|
|
|
803fb7 |
bool handle_cmsg = false;
|
|
|
803fb7 |
@@ -556,8 +554,8 @@ static int bus_socket_read_auth(sd_bus *b) {
|
|
|
803fb7 |
|
|
|
803fb7 |
b->rbuffer_size += k;
|
|
|
803fb7 |
|
|
|
803fb7 |
- if (handle_cmsg) {
|
|
|
803fb7 |
- for (cmsg = CMSG_FIRSTHDR(&mh); cmsg; cmsg = CMSG_NXTHDR(&mh, cmsg)) {
|
|
|
803fb7 |
+ if (handle_cmsg)
|
|
|
803fb7 |
+ for (cmsg = CMSG_FIRSTHDR(&mh); cmsg; cmsg = CMSG_NXTHDR(&mh, cmsg))
|
|
|
803fb7 |
if (cmsg->cmsg_level == SOL_SOCKET &&
|
|
|
803fb7 |
cmsg->cmsg_type == SCM_RIGHTS) {
|
|
|
803fb7 |
int j;
|
|
|
803fb7 |
@@ -568,31 +566,9 @@ static int bus_socket_read_auth(sd_bus *b) {
|
|
|
803fb7 |
j = (cmsg->cmsg_len - CMSG_LEN(0)) / sizeof(int);
|
|
|
803fb7 |
close_many((int*) CMSG_DATA(cmsg), j);
|
|
|
803fb7 |
return -EIO;
|
|
|
803fb7 |
-
|
|
|
803fb7 |
- } else if (cmsg->cmsg_level == SOL_SOCKET &&
|
|
|
803fb7 |
- cmsg->cmsg_type == SCM_CREDENTIALS &&
|
|
|
803fb7 |
- cmsg->cmsg_len == CMSG_LEN(sizeof(struct ucred))) {
|
|
|
803fb7 |
-
|
|
|
803fb7 |
- /* Ignore bogus data, which we might
|
|
|
803fb7 |
- * get on socketpair() sockets */
|
|
|
803fb7 |
- if (((struct ucred*) CMSG_DATA(cmsg))->pid != 0) {
|
|
|
803fb7 |
- memcpy(&b->ucred, CMSG_DATA(cmsg), sizeof(struct ucred));
|
|
|
803fb7 |
- b->ucred_valid = true;
|
|
|
803fb7 |
- }
|
|
|
803fb7 |
-
|
|
|
803fb7 |
- } else if (cmsg->cmsg_level == SOL_SOCKET &&
|
|
|
803fb7 |
- cmsg->cmsg_type == SCM_SECURITY) {
|
|
|
803fb7 |
-
|
|
|
803fb7 |
- size_t l;
|
|
|
803fb7 |
-
|
|
|
803fb7 |
- l = cmsg->cmsg_len - CMSG_LEN(0);
|
|
|
803fb7 |
- if (l > 0) {
|
|
|
803fb7 |
- memcpy(&b->label, CMSG_DATA(cmsg), l);
|
|
|
803fb7 |
- b->label[l] = 0;
|
|
|
803fb7 |
- }
|
|
|
803fb7 |
- }
|
|
|
803fb7 |
- }
|
|
|
803fb7 |
- }
|
|
|
803fb7 |
+ } else
|
|
|
803fb7 |
+ log_debug("Got unexpected auxiliary data with level=%d and type=%d",
|
|
|
803fb7 |
+ cmsg->cmsg_level, cmsg->cmsg_type);
|
|
|
803fb7 |
|
|
|
803fb7 |
r = bus_socket_auth_verify(b);
|
|
|
803fb7 |
if (r != 0)
|
|
|
803fb7 |
@@ -945,9 +921,7 @@ int bus_socket_read_message(sd_bus *bus) {
|
|
|
803fb7 |
void *b;
|
|
|
803fb7 |
union {
|
|
|
803fb7 |
struct cmsghdr cmsghdr;
|
|
|
803fb7 |
- uint8_t buf[CMSG_SPACE(sizeof(int) * BUS_FDS_MAX) +
|
|
|
803fb7 |
- CMSG_SPACE(sizeof(struct ucred)) +
|
|
|
803fb7 |
- CMSG_SPACE(NAME_MAX)]; /*selinux label */
|
|
|
803fb7 |
+ uint8_t buf[CMSG_SPACE(sizeof(int) * BUS_FDS_MAX)];
|
|
|
803fb7 |
} control;
|
|
|
803fb7 |
struct cmsghdr *cmsg;
|
|
|
803fb7 |
bool handle_cmsg = false;
|
|
|
803fb7 |
@@ -995,8 +969,8 @@ int bus_socket_read_message(sd_bus *bus) {
|
|
|
803fb7 |
|
|
|
803fb7 |
bus->rbuffer_size += k;
|
|
|
803fb7 |
|
|
|
803fb7 |
- if (handle_cmsg) {
|
|
|
803fb7 |
- for (cmsg = CMSG_FIRSTHDR(&mh); cmsg; cmsg = CMSG_NXTHDR(&mh, cmsg)) {
|
|
|
803fb7 |
+ if (handle_cmsg)
|
|
|
803fb7 |
+ for (cmsg = CMSG_FIRSTHDR(&mh); cmsg; cmsg = CMSG_NXTHDR(&mh, cmsg))
|
|
|
803fb7 |
if (cmsg->cmsg_level == SOL_SOCKET &&
|
|
|
803fb7 |
cmsg->cmsg_type == SCM_RIGHTS) {
|
|
|
803fb7 |
int n, *f;
|
|
|
803fb7 |
@@ -1021,29 +995,9 @@ int bus_socket_read_message(sd_bus *bus) {
|
|
|
803fb7 |
memcpy(f + bus->n_fds, CMSG_DATA(cmsg), n * sizeof(int));
|
|
|
803fb7 |
bus->fds = f;
|
|
|
803fb7 |
bus->n_fds += n;
|
|
|
803fb7 |
- } else if (cmsg->cmsg_level == SOL_SOCKET &&
|
|
|
803fb7 |
- cmsg->cmsg_type == SCM_CREDENTIALS &&
|
|
|
803fb7 |
- cmsg->cmsg_len == CMSG_LEN(sizeof(struct ucred))) {
|
|
|
803fb7 |
-
|
|
|
803fb7 |
- /* Ignore bogus data, which we might
|
|
|
803fb7 |
- * get on socketpair() sockets */
|
|
|
803fb7 |
- if (((struct ucred*) CMSG_DATA(cmsg))->pid != 0) {
|
|
|
803fb7 |
- memcpy(&bus->ucred, CMSG_DATA(cmsg), sizeof(struct ucred));
|
|
|
803fb7 |
- bus->ucred_valid = true;
|
|
|
803fb7 |
- }
|
|
|
803fb7 |
-
|
|
|
803fb7 |
- } else if (cmsg->cmsg_level == SOL_SOCKET &&
|
|
|
803fb7 |
- cmsg->cmsg_type == SCM_SECURITY) {
|
|
|
803fb7 |
-
|
|
|
803fb7 |
- size_t l;
|
|
|
803fb7 |
- l = cmsg->cmsg_len - CMSG_LEN(0);
|
|
|
803fb7 |
- if (l > 0) {
|
|
|
803fb7 |
- memcpy(&bus->label, CMSG_DATA(cmsg), l);
|
|
|
803fb7 |
- bus->label[l] = 0;
|
|
|
803fb7 |
- }
|
|
|
803fb7 |
- }
|
|
|
803fb7 |
- }
|
|
|
803fb7 |
- }
|
|
|
803fb7 |
+ } else
|
|
|
803fb7 |
+ log_debug("Got unexpected auxiliary data with level=%d and type=%d",
|
|
|
803fb7 |
+ cmsg->cmsg_level, cmsg->cmsg_type);
|
|
|
803fb7 |
|
|
|
803fb7 |
r = bus_socket_read_message_need(bus, &need);
|
|
|
803fb7 |
if (r < 0)
|