Several updates for socket option (#36905)
This commit is contained in:
@@ -42,7 +42,7 @@ REQUIREMENTS:
|
||||
≥ 4.17 for cgroup-bpf socket address hooks, /sys/power/resume_offset,
|
||||
and FRA_PROTOCOL attribute for fib rules
|
||||
≥ 4.20 for PSI (used by systemd-oomd)
|
||||
≥ 5.0 for SO_BINDTOIFINDEX
|
||||
≥ 5.1 for SO_BINDTOIFINDEX
|
||||
≥ 5.2 for cgroup freezer and new mount API
|
||||
≥ 5.3 for bounded loops in BPF program, keyring namespacing,
|
||||
and nexthop support
|
||||
|
||||
@@ -3,33 +3,29 @@
|
||||
|
||||
#include <sys/socket.h>
|
||||
|
||||
#ifndef SO_PEERGROUPS
|
||||
#define SO_PEERGROUPS 59
|
||||
#endif
|
||||
|
||||
/* Supported since kernel v6.5 (5e2ff6704a275be009be8979af17c52361b79b89) */
|
||||
#ifndef SO_PASSPIDFD
|
||||
#define SO_PASSPIDFD 76
|
||||
#endif
|
||||
|
||||
/* Supported since kernel v6.5 (7b26952a91cf65ff1cc867a2382a8964d8c0ee7d) */
|
||||
#ifndef SO_PEERPIDFD
|
||||
#define SO_PEERPIDFD 77
|
||||
#endif
|
||||
|
||||
#ifndef SO_BINDTOIFINDEX
|
||||
#define SO_BINDTOIFINDEX 62
|
||||
#endif
|
||||
|
||||
/* Not exposed yet. Defined in include/linux/socket.h. */
|
||||
#ifndef SOL_SCTP
|
||||
#define SOL_SCTP 132
|
||||
#endif
|
||||
|
||||
/* since glibc-2.39 */
|
||||
/* Supported since kernel v2.6.17 (2c7946a7bf45ae86736ab3b43d0085e43947945c).
|
||||
* Defined since glibc-2.39 */
|
||||
#ifndef SCM_SECURITY
|
||||
#define SCM_SECURITY 0x03
|
||||
#endif
|
||||
|
||||
/* since glibc-2.39 */
|
||||
/* Supported since kernel v6.5 (5e2ff6704a275be009be8979af17c52361b79b89).
|
||||
* Defined since glibc-2.39 */
|
||||
#ifndef SCM_PIDFD
|
||||
#define SCM_PIDFD 0x04
|
||||
#endif
|
||||
|
||||
+3
-3
@@ -1109,10 +1109,10 @@ static int manager_setup_notify(Manager *m) {
|
||||
if (r < 0)
|
||||
return log_error_errno(r, "Failed to enable SO_PASSCRED for notify socket: %m");
|
||||
|
||||
// TODO: enforce SO_PASSPIDFD when our baseline of the kernel version is bumped to >= 6.5.
|
||||
r = setsockopt_int(fd, SOL_SOCKET, SO_PASSPIDFD, true);
|
||||
if (r < 0 && r != -ENOPROTOOPT)
|
||||
log_warning_errno(r, "Failed to enable SO_PASSPIDFD for notify socket, ignoring: %m");
|
||||
// TODO: maybe enforce SO_PASSPIDFD?
|
||||
|
||||
m->notify_fd = TAKE_FD(fd);
|
||||
|
||||
@@ -5002,8 +5002,8 @@ static int manager_dispatch_pidref_transport_fd(sd_event_source *source, int fd,
|
||||
* - Child PIDFD in SCM_RIGHTS in message body
|
||||
* - Child PID in message IOV
|
||||
*
|
||||
* SO_PASSPIDFD may not be supported by the kernel so we fall back to using parent PID from ucreds
|
||||
* and accept some raciness. */
|
||||
* SO_PASSPIDFD may not be supported by the kernel (it is supported since v6.5) so we fall back to
|
||||
* using parent PID from ucreds and accept some raciness. */
|
||||
n = recvmsg_safe(m->pidref_transport_fds[0], &msghdr, MSG_DONTWAIT|MSG_CMSG_CLOEXEC|MSG_TRUNC);
|
||||
if (ERRNO_IS_NEG_TRANSIENT(n))
|
||||
return 0; /* Spurious wakeup, try again */
|
||||
|
||||
@@ -1509,7 +1509,8 @@ int server_process_datagram(
|
||||
* limit is known.
|
||||
*
|
||||
* Here, we need to explicitly initialize the buffer with zero, as glibc has a bug in
|
||||
* __convert_scm_timestamps(), which assumes the buffer is initialized. See #20741. */
|
||||
* __convert_scm_timestamps(), which assumes the buffer is initialized. See #20741.
|
||||
* The issue is fixed on glibc-2.35 (8fba672472ae0055387e9315fc2eddfa6775ca79). */
|
||||
CMSG_BUFFER_TYPE(CMSG_SPACE(sizeof(struct ucred)) +
|
||||
CMSG_SPACE_TIMEVAL +
|
||||
CMSG_SPACE(sizeof(int)) + /* fd */
|
||||
|
||||
@@ -118,7 +118,8 @@ int icmp6_receive(
|
||||
struct in6_addr *ret_sender,
|
||||
triple_timestamp *ret_timestamp) {
|
||||
|
||||
/* This needs to be initialized with zero. See #20741. */
|
||||
/* This needs to be initialized with zero. See #20741.
|
||||
* The issue is fixed on glibc-2.35 (8fba672472ae0055387e9315fc2eddfa6775ca79). */
|
||||
CMSG_BUFFER_TYPE(CMSG_SPACE(sizeof(int)) + /* ttl */
|
||||
CMSG_SPACE_TIMEVAL) control = {};
|
||||
struct iovec iov = { buffer, size };
|
||||
|
||||
@@ -2056,7 +2056,8 @@ static int client_receive_message_udp(
|
||||
sd_dhcp_client *client = ASSERT_PTR(userdata);
|
||||
_cleanup_free_ DHCPMessage *message = NULL;
|
||||
ssize_t len, buflen;
|
||||
/* This needs to be initialized with zero. See #20741. */
|
||||
/* This needs to be initialized with zero. See #20741.
|
||||
* The issue is fixed on glibc-2.35 (8fba672472ae0055387e9315fc2eddfa6775ca79). */
|
||||
CMSG_BUFFER_TYPE(CMSG_SPACE_TIMEVAL) control = {};
|
||||
struct iovec iov;
|
||||
struct msghdr msg = {
|
||||
@@ -2107,7 +2108,8 @@ static int client_receive_message_raw(
|
||||
|
||||
sd_dhcp_client *client = ASSERT_PTR(userdata);
|
||||
_cleanup_free_ DHCPPacket *packet = NULL;
|
||||
/* This needs to be initialized with zero. See #20741. */
|
||||
/* This needs to be initialized with zero. See #20741.
|
||||
* The issue is fixed on glibc-2.35 (8fba672472ae0055387e9315fc2eddfa6775ca79). */
|
||||
CMSG_BUFFER_TYPE(CMSG_SPACE_TIMEVAL +
|
||||
CMSG_SPACE(sizeof(struct tpacket_auxdata))) control = {};
|
||||
struct iovec iov = {};
|
||||
|
||||
@@ -1225,7 +1225,8 @@ static size_t relay_agent_information_length(const char* agent_circuit_id, const
|
||||
static int server_receive_message(sd_event_source *s, int fd,
|
||||
uint32_t revents, void *userdata) {
|
||||
_cleanup_free_ DHCPMessage *message = NULL;
|
||||
/* This needs to be initialized with zero. See #20741. */
|
||||
/* This needs to be initialized with zero. See #20741.
|
||||
* The issue is fixed on glibc-2.35 (8fba672472ae0055387e9315fc2eddfa6775ca79). */
|
||||
CMSG_BUFFER_TYPE(CMSG_SPACE_TIMEVAL +
|
||||
CMSG_SPACE(sizeof(struct in_pktinfo))) control = {};
|
||||
sd_dhcp_server *server = ASSERT_PTR(userdata);
|
||||
|
||||
@@ -1289,7 +1289,8 @@ static int client_receive_message(
|
||||
|
||||
sd_dhcp6_client *client = ASSERT_PTR(userdata);
|
||||
DHCP6_CLIENT_DONT_DESTROY(client);
|
||||
/* This needs to be initialized with zero. See #20741. */
|
||||
/* This needs to be initialized with zero. See #20741.
|
||||
* The issue is fixed on glibc-2.35 (8fba672472ae0055387e9315fc2eddfa6775ca79). */
|
||||
CMSG_BUFFER_TYPE(CMSG_SPACE_TIMEVAL) control = {};
|
||||
struct iovec iov;
|
||||
union sockaddr_union sa = {};
|
||||
|
||||
@@ -397,7 +397,8 @@ static int manager_receive_response(sd_event_source *source, int fd, uint32_t re
|
||||
.iov_base = &ntpmsg,
|
||||
.iov_len = sizeof(ntpmsg),
|
||||
};
|
||||
/* This needs to be initialized with zero. See #20741. */
|
||||
/* This needs to be initialized with zero. See #20741.
|
||||
* The issue is fixed on glibc-2.35 (8fba672472ae0055387e9315fc2eddfa6775ca79). */
|
||||
CMSG_BUFFER_TYPE(CMSG_SPACE_TIMESPEC) control = {};
|
||||
union sockaddr_union server_addr;
|
||||
struct msghdr msghdr = {
|
||||
|
||||
Reference in New Issue
Block a user