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