NetBSD-Bugs archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

Re: bin/56895: /usr/sbin/ldpd fails on alignment-picky architectures



The following reply was made to PR bin/56895; it has been noted by GNATS.

From: Taylor R Campbell <riastradh%NetBSD.org@localhost>
To: Tom Lane <tgl%sss.pgh.pa.us@localhost>
Cc: gnats-bugs%NetBSD.org@localhost
Subject: Re: bin/56895: /usr/sbin/ldpd fails on alignment-picky architectures
Date: Mon, 20 Jun 2022 02:26:14 +0000

 This is a multi-part message in MIME format.
 --=_U+89j2l9CEBqI2aSXBW9qNw7GOwXDlcv
 
 Can you try the attached patch and see if it helps?
 
 --=_U+89j2l9CEBqI2aSXBW9qNw7GOwXDlcv
 Content-Type: text/plain; charset="ISO-8859-1"; name="pr56895"
 Content-Transfer-Encoding: quoted-printable
 Content-Disposition: attachment; filename="pr56895.patch"
 
 From ba622892c7f19e15351e4cc657cda746843021be Mon Sep 17 00:00:00 2001
 From: Taylor R Campbell <riastradh%NetBSD.org@localhost>
 Date: Mon, 20 Jun 2022 02:24:25 +0000
 Subject: [PATCH] ldpd(8): Fix address of misaligned packed members.
 
 PR kern/56895
 ---
  usr.sbin/ldpd/Makefile    |  3 ---
  usr.sbin/ldpd/fsm.c       | 13 ++++++++-----
  usr.sbin/ldpd/ldp_peer.c  |  7 ++++---
  usr.sbin/ldpd/socketops.c |  9 +++++++--
  4 files changed, 19 insertions(+), 13 deletions(-)
 
 diff --git a/usr.sbin/ldpd/Makefile b/usr.sbin/ldpd/Makefile
 index aaa8a2ed4d68..d477d8fd5dab 100644
 --- a/usr.sbin/ldpd/Makefile
 +++ b/usr.sbin/ldpd/Makefile
 @@ -26,7 +26,4 @@ LDADD+=3D	-lcrypt
  CPPFLAGS+=3D-DINET6
  .endif
 =20
 -CWARNFLAGS.clang+=3D	-Wno-error=3Daddress-of-packed-member
 -CWARNFLAGS.gcc+=3D        ${GCC_NO_ADDR_OF_PACKED_MEMBER}
 -
  .include <bsd.prog.mk>
 diff --git a/usr.sbin/ldpd/fsm.c b/usr.sbin/ldpd/fsm.c
 index f6b25e526a8b..8317a96b6628 100644
 --- a/usr.sbin/ldpd/fsm.c
 +++ b/usr.sbin/ldpd/fsm.c
 @@ -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 =3D NULL;
  	union sockunion traddr;
 +	struct in_addr ldp_id;
 =20
  	if ((!pduid) || (!ht))
  		return;
 @@ -125,7 +126,8 @@ run_ldp_hello(const struct ldp_pdu * pduid, const struc=
 t hello_tlv * ht,
  			hi->keepalive =3D LDP_THELLO_KEEP;
  	}
 =20
 -	if (!get_ldp_peer_by_id(&pduid->ldp_id)) {
 +	ldp_id =3D 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 struc=
 t hello_tlv * ht,
  		    (hi->transport_address.sa.sa_family =3D=3D AF_INET &&
  		    ntohl(hi->transport_address.sin.sin_addr.s_addr) <
  		    ntohl(ladd->s_addr))) {
 -			peer =3D ldp_peer_new(&pduid->ldp_id, padd,
 +			peer =3D ldp_peer_new(&ldp_id, padd,
  				&hi->transport_address.sa,
  				ntohs(ht->ch.holdtime), 0);
  			if (peer =3D=3D 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 =3D 0;
 =20
  	if (getifaddrs(&ifa) =3D=3D -1)
 @@ -184,7 +186,7 @@ build_address_list_tlv(void)
  	    adrcount * sizeof(struct in_addr));
  	t->a_af =3D htons(LDP_AF_INET);
 =20
 -	ia =3D &t->a_address;
 +	ia =3D (void *)&t->a_address;
  	for (adrcount =3D 0, ifb =3D ifa; ifb; ifb =3D ifb->ifa_next) {
  		if ((ifb->ifa_addr->sa_family !=3D AF_INET) ||
  		    (!(ifb->ifa_flags & IFF_UP)))
 @@ -192,7 +194,8 @@ build_address_list_tlv(void)
  		sa =3D (struct sockaddr_in *) ifb->ifa_addr;
  		if (ntohl(sa->sin_addr.s_addr) >> 24 =3D=3D 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 45c50a60cb9f..15282f530397 100644
 --- a/usr.sbin/ldpd/ldp_peer.c
 +++ b/usr.sbin/ldpd/ldp_peer.c
 @@ -307,7 +307,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;
 =20
  	memset(&ipa, 0, sizeof(ipa));
 @@ -329,8 +329,9 @@ add_ifaddresses(struct ldp_peer * p, const struct al_tl=
 v * a)
  	debugp("Trying to add %d addresses to peer %s ... \n", n,
  	    inet_ntoa(p->ldp_id));
 =20
 -	for (ia =3D (const struct in_addr *) & a->address,c =3D 0,i =3D 0; i<n; i=
 ++) {
 -		memcpy(&ipa.sin_addr, &ia[i], sizeof(ipa.sin_addr));
 +	for (ia =3D (const void *)&a->address, c =3D 0, i =3D 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) =3D=3D LDP_E_OK)
  			c++;
  	}
 diff --git a/usr.sbin/ldpd/socketops.c b/usr.sbin/ldpd/socketops.c
 index 47d2918728a8..d41c3104db5a 100644
 --- a/usr.sbin/ldpd/socketops.c
 +++ b/usr.sbin/ldpd/socketops.c
 @@ -404,6 +404,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 */
 @@ -443,7 +444,8 @@ send_hello(void)
  	/* Prepare PDU envelope */
  	spdu->version =3D htons(LDP_VERSION);
  	spdu->length =3D htons(IPV4_HELLO_MSG_SIZE - PDU_VER_LENGTH);
 -	inet_aton(LDP_ID, &spdu->ldp_id);
 +	inet_aton(LDP_ID, &ldp_id);
 +	spdu->ldp_id =3D ldp_id;
 =20
  	/* Prepare Hello TLV */
  	t->type =3D htons(LDP_HELLO);
 @@ -1387,10 +1389,13 @@ send_message(const struct ldp_peer * p, const struc=
 t ldp_pdu * pdu,
  int=20
  send_tlv(const struct ldp_peer * p, const struct tlv * t)
  {
 +	struct in_addr ldp_id;
  	struct ldp_pdu  pdu;
 =20
 +	inet_aton(LDP_ID, &ldp_id);
 +
  	pdu.version =3D htons(LDP_VERSION);
 -	inet_aton(LDP_ID, &pdu.ldp_id);
 +	pdu.ldp_id =3D ldp_id;
  	pdu.label_space =3D 0;
  	pdu.length =3D htons(ntohs(t->length) + TLV_TYPE_LENGTH +
  		PDU_PAYLOAD_LENGTH);
 
 --=_U+89j2l9CEBqI2aSXBW9qNw7GOwXDlcv--
 


Home | Main Index | Thread Index | Old Index