From bbb2a0fb4129a11df84059cbce326b05f18604c3 Mon Sep 17 00:00:00 2001 From: Yu Watanabe Date: Fri, 1 Mar 2024 09:21:55 +0900 Subject: [PATCH 1/3] icmp6-packet: check the alignment of struct nd_opt_hdr for safety Addresses https://github.com/systemd/systemd/pull/31492#discussion_r1507481748. --- src/libsystemd-network/ndisc-protocol.c | 1 + 1 file changed, 1 insertion(+) diff --git a/src/libsystemd-network/ndisc-protocol.c b/src/libsystemd-network/ndisc-protocol.c index 39dcdcdfd8..d1f0819e14 100644 --- a/src/libsystemd-network/ndisc-protocol.c +++ b/src/libsystemd-network/ndisc-protocol.c @@ -22,6 +22,7 @@ int ndisc_option_parse( if (p->raw_size - offset < sizeof(struct nd_opt_hdr)) return -EBADMSG; + assert_cc(alignof(struct nd_opt_hdr) == 1); const struct nd_opt_hdr *hdr = (const struct nd_opt_hdr*) (p->raw_packet + offset); if (hdr->nd_opt_len == 0) return -EBADMSG; From f169c5644754457e1ad7a2826f7c0895a863bbf2 Mon Sep 17 00:00:00 2001 From: Yu Watanabe Date: Thu, 29 Feb 2024 12:46:48 +0900 Subject: [PATCH 2/3] sd-ndisc: use _packed_ attribute --- src/libsystemd-network/ndisc-protocol.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/libsystemd-network/ndisc-protocol.h b/src/libsystemd-network/ndisc-protocol.h index 94842524ee..dcb1b191c7 100644 --- a/src/libsystemd-network/ndisc-protocol.h +++ b/src/libsystemd-network/ndisc-protocol.h @@ -26,7 +26,7 @@ struct nd_opt_prefix64_info { uint8_t length; uint16_t lifetime_and_plc; uint8_t prefix[12]; -} __attribute__((__packed__)); +} _packed_; int pref64_plc_to_prefix_length(uint16_t plc, uint8_t *ret); int pref64_prefix_length_to_plc(uint8_t prefixlen, uint8_t *ret); From ccb1ace77f17fa271d15b5973ba1f8c27c16e535 Mon Sep 17 00:00:00 2001 From: Yu Watanabe Date: Thu, 29 Feb 2024 12:37:26 +0900 Subject: [PATCH 3/3] sd-ndisc: drop unused sd_ndisc_router_get_raw() --- src/libsystemd-network/sd-ndisc-router.c | 11 ----------- src/systemd/sd-ndisc-router.h | 1 - 2 files changed, 12 deletions(-) diff --git a/src/libsystemd-network/sd-ndisc-router.c b/src/libsystemd-network/sd-ndisc-router.c index 6a5f6b3faf..4a95d7dba7 100644 --- a/src/libsystemd-network/sd-ndisc-router.c +++ b/src/libsystemd-network/sd-ndisc-router.c @@ -90,17 +90,6 @@ DEFINE_GET_TIMESTAMP(rdnss_get_lifetime); DEFINE_GET_TIMESTAMP(dnssl_get_lifetime); DEFINE_GET_TIMESTAMP(prefix64_get_lifetime); -int sd_ndisc_router_get_raw(sd_ndisc_router *rt, const void **ret, size_t *ret_size) { - assert_return(rt, -EINVAL); - assert_return(ret, -EINVAL); - assert_return(ret_size, -EINVAL); - - *ret = NDISC_ROUTER_RAW(rt); - *ret_size = rt->packet->raw_size; - - return 0; -} - static bool pref64_option_verify(const struct nd_opt_prefix64_info *p, size_t length) { uint16_t lifetime_and_plc; diff --git a/src/systemd/sd-ndisc-router.h b/src/systemd/sd-ndisc-router.h index bfdaeb4689..57dbb12817 100644 --- a/src/systemd/sd-ndisc-router.h +++ b/src/systemd/sd-ndisc-router.h @@ -34,7 +34,6 @@ _SD_DEFINE_POINTER_CLEANUP_FUNC(sd_ndisc_router, sd_ndisc_router_unref); int sd_ndisc_router_get_address(sd_ndisc_router *rt, struct in6_addr *ret); int sd_ndisc_router_get_timestamp(sd_ndisc_router *rt, clockid_t clock, uint64_t *ret); -int sd_ndisc_router_get_raw(sd_ndisc_router *rt, const void **ret, size_t *ret_size); int sd_ndisc_router_get_hop_limit(sd_ndisc_router *rt, uint8_t *ret); int sd_ndisc_router_get_flags(sd_ndisc_router *rt, uint64_t *ret);