From 1dec367e031cf5753fd0c9c11343429f8dbc083d Mon Sep 17 00:00:00 2001 From: martin Date: Fri, 4 Aug 2023 13:28:40 +0000 Subject: [PATCH] Pull up following revision(s) (requested by riastradh in ticket #1881): usr.sbin/ldpd/socketops.c: revision 1.36 usr.sbin/ldpd/fsm.c: revision 1.16 usr.sbin/ldpd/ldp_peer.c: revision 1.19 ldpd(8): Fix address of misaligned packed members. PR kern/56895 --- usr.sbin/ldpd/fsm.c | 15 +++++++++------ usr.sbin/ldpd/ldp_peer.c | 9 +++++---- usr.sbin/ldpd/socketops.c | 11 ++++++++--- 3 files changed, 22 insertions(+), 13 deletions(-) diff --git a/usr.sbin/ldpd/fsm.c b/usr.sbin/ldpd/fsm.c index f6b25e526a8b..4790e41764f7 100644 --- a/usr.sbin/ldpd/fsm.c +++ b/usr.sbin/ldpd/fsm.c @@ -1,4 +1,4 @@ -/* $NetBSD: fsm.c,v 1.15 2014/03/18 18:20:47 riastradh Exp $ */ +/* $NetBSD: fsm.c,v 1.15.18.1 2023/08/04 13:28:40 martin Exp $ */ /*- * Copyright (c) 2010 The NetBSD Foundation, Inc. @@ -59,6 +59,7 @@ run_ldp_hello(const struct ldp_pdu * pduid, const struct hello_tlv * ht, const struct transport_address_tlv *trtlv; struct hello_info *hi = NULL; union sockunion traddr; + struct in_addr ldp_id; if ((!pduid) || (!ht)) return; @@ -125,7 +126,8 @@ run_ldp_hello(const struct ldp_pdu * pduid, const struct hello_tlv * ht, hi->keepalive = LDP_THELLO_KEEP; } - if (!get_ldp_peer_by_id(&pduid->ldp_id)) { + ldp_id = pduid->ldp_id; + if (!get_ldp_peer_by_id(&ldp_id)) { /* * RFC 5036 2.5.2: If A1 > A2, LSR1 plays the active role; * otherwise it is passive. @@ -134,7 +136,7 @@ run_ldp_hello(const struct ldp_pdu * pduid, const struct hello_tlv * ht, (hi->transport_address.sa.sa_family == AF_INET && ntohl(hi->transport_address.sin.sin_addr.s_addr) < ntohl(ladd->s_addr))) { - peer = ldp_peer_new(&pduid->ldp_id, padd, + peer = ldp_peer_new(&ldp_id, padd, &hi->transport_address.sa, ntohs(ht->ch.holdtime), 0); if (peer == NULL) @@ -151,7 +153,7 @@ build_address_list_tlv(void) struct address_list_tlv *t; struct ifaddrs *ifa, *ifb; struct sockaddr_in *sa; - struct in_addr *ia; + char *ia; uint16_t adrcount = 0; if (getifaddrs(&ifa) == -1) @@ -184,7 +186,7 @@ build_address_list_tlv(void) adrcount * sizeof(struct in_addr)); t->a_af = htons(LDP_AF_INET); - ia = &t->a_address; + ia = (void *)&t->a_address; for (adrcount = 0, ifb = ifa; ifb; ifb = ifb->ifa_next) { if ((ifb->ifa_addr->sa_family != AF_INET) || (!(ifb->ifa_flags & IFF_UP))) @@ -192,7 +194,8 @@ build_address_list_tlv(void) sa = (struct sockaddr_in *) ifb->ifa_addr; if (ntohl(sa->sin_addr.s_addr) >> 24 == IN_LOOPBACKNET) continue; - memcpy(&ia[adrcount], &sa->sin_addr, sizeof(struct in_addr)); + memcpy(ia + adrcount*sizeof(struct in_addr), &sa->sin_addr, + sizeof(struct in_addr)); adrcount++; } freeifaddrs(ifa); diff --git a/usr.sbin/ldpd/ldp_peer.c b/usr.sbin/ldpd/ldp_peer.c index 1cf17a7d5150..797f12621269 100644 --- a/usr.sbin/ldpd/ldp_peer.c +++ b/usr.sbin/ldpd/ldp_peer.c @@ -1,4 +1,4 @@ -/* $NetBSD: ldp_peer.c,v 1.16 2013/08/02 07:29:56 kefren Exp $ */ +/* $NetBSD: ldp_peer.c,v 1.16.18.1 2023/08/04 13:28:40 martin Exp $ */ /* * Copyright (c) 2010 The NetBSD Foundation, Inc. @@ -306,7 +306,7 @@ int add_ifaddresses(struct ldp_peer * p, const struct al_tlv * a) { int i, c, n; - const struct in_addr *ia; + const char *ia; struct sockaddr_in ipa; memset(&ipa, 0, sizeof(ipa)); @@ -328,8 +328,9 @@ add_ifaddresses(struct ldp_peer * p, const struct al_tlv * a) debugp("Trying to add %d addresses to peer %s ... \n", n, inet_ntoa(p->ldp_id)); - for (ia = (const struct in_addr *) & a->address,c = 0,i = 0; iaddress, c = 0, i = 0; i < n; i++) { + memcpy(&ipa.sin_addr, ia + i*sizeof(ipa.sin_addr), + sizeof(ipa.sin_addr)); if (add_ifaddr(p, (struct sockaddr *)&ipa) == LDP_E_OK) c++; } diff --git a/usr.sbin/ldpd/socketops.c b/usr.sbin/ldpd/socketops.c index 44e124c34674..0c640d758c39 100644 --- a/usr.sbin/ldpd/socketops.c +++ b/usr.sbin/ldpd/socketops.c @@ -1,4 +1,4 @@ -/* $NetBSD: socketops.c,v 1.34 2017/04/12 17:02:51 roy Exp $ */ +/* $NetBSD: socketops.c,v 1.34.4.1 2023/08/04 13:28:40 martin Exp $ */ /* * Copyright (c) 2010 The NetBSD Foundation, Inc. @@ -401,6 +401,7 @@ send_hello(void) struct hello_tlv *t; struct common_hello_tlv *cht; struct ldp_pdu *spdu; + struct in_addr ldp_id; struct transport_address_tlv *trtlv; void *v; struct sockaddr_in sadest; /* Destination ALL_ROUTERS */ @@ -440,7 +441,8 @@ send_hello(void) /* Prepare PDU envelope */ spdu->version = htons(LDP_VERSION); spdu->length = htons(IPV4_HELLO_MSG_SIZE - PDU_VER_LENGTH); - inet_aton(LDP_ID, &spdu->ldp_id); + inet_aton(LDP_ID, &ldp_id); + spdu->ldp_id = ldp_id; /* Prepare Hello TLV */ t->type = htons(LDP_HELLO); @@ -1384,10 +1386,13 @@ send_message(const struct ldp_peer * p, const struct ldp_pdu * pdu, int send_tlv(const struct ldp_peer * p, const struct tlv * t) { + struct in_addr ldp_id; struct ldp_pdu pdu; + inet_aton(LDP_ID, &ldp_id); + pdu.version = htons(LDP_VERSION); - inet_aton(LDP_ID, &pdu.ldp_id); + pdu.ldp_id = ldp_id; pdu.label_space = 0; pdu.length = htons(ntohs(t->length) + TLV_TYPE_LENGTH + PDU_PAYLOAD_LENGTH);