NetBSD Problem Report #56895
From www@netbsd.org Mon Jun 20 02:03:36 2022
Return-Path: <www@netbsd.org>
Received: from mail.netbsd.org (mail.netbsd.org [199.233.217.200])
(using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits))
(Client CN "mail.NetBSD.org", Issuer "mail.NetBSD.org CA" (not verified))
by mollari.NetBSD.org (Postfix) with ESMTPS id 536741A921F
for <gnats-bugs@gnats.NetBSD.org>; Mon, 20 Jun 2022 02:03:36 +0000 (UTC)
Message-Id: <20220620020334.9B70B1A9239@mollari.NetBSD.org>
Date: Mon, 20 Jun 2022 02:03:34 +0000 (UTC)
From: tgl@sss.pgh.pa.us
Reply-To: tgl@sss.pgh.pa.us
To: gnats-bugs@NetBSD.org
Subject: /usr/sbin/ldpd fails on alignment-picky architectures
X-Send-Pr-Version: www-1.0
>Number: 56895
>Category: bin
>Synopsis: /usr/sbin/ldpd fails on alignment-picky architectures
>Confidential: no
>Severity: serious
>Priority: medium
>Responsible: bin-bug-people
>State: closed
>Class: sw-bug
>Submitter-Id: net
>Arrival-Date: Mon Jun 20 02:05:02 +0000 2022
>Closed-Date: Sat Aug 05 16:34:15 +0000 2023
>Last-Modified: Sat Aug 05 16:34:15 +0000 2023
>Originator: Tom Lane
>Release: HEAD/202206150250Z
>Organization:
PostgreSQL Global Development Group
>Environment:
NetBSD sss2.sss.pgh.pa.us 9.99.97 NetBSD 9.99.97 (SD0) #0: Wed Jun 15 15:24:17 EDT 2022 tgl@nuc1.sss.pgh.pa.us:/home/tgl/netbsd-H-202206150250Z/obj.hppa/sys/arch/hppa/compile/SD0 hppa
>Description:
The net/mpls/t_ldp_regen test fails for me on HPPA, because ldpd crashes here:
Program terminated with signal SIGBUS, Bus error.
#0 0xaf163ec0 in _inet_aton (cp=0x20ef8 <my_ldp_id+8> "", addr=0xb00027e6)
at /home/tgl/netbsd-H-202206150250Z/usr/src/lib/libc/../../common/lib/libc/inet/inet_addr.c:222
(gdb) bt
#0 0xaf163ec0 in _inet_aton (cp=0x20ef8 <my_ldp_id+8> "", addr=0xb00027e6)
at /home/tgl/netbsd-H-202206150250Z/usr/src/lib/libc/../../common/lib/libc/inet/inet_addr.c:222
#1 0x0001a0e4 in send_tlv (t=0xb00027c8, p=0xafe8c040)
at /home/tgl/netbsd-H-202206150250Z/usr/src/usr.sbin/ldpd/socketops.c:1393
#2 send_initialize (p=0xafe8c040)
at /home/tgl/netbsd-H-202206150250Z/usr/src/usr.sbin/ldpd/socketops.c:1076
#3 0x0001aec0 in the_big_loop ()
at /home/tgl/netbsd-H-202206150250Z/usr/src/usr.sbin/ldpd/socketops.c:975
#4 0x0001c1c4 in main (argc=1, argv=0xb0001038)
at /home/tgl/netbsd-H-202206150250Z/usr/src/usr.sbin/ldpd/main.c:155
Visibly, "addr" is not word-aligned, so it's unsurprising that trying to do a 32-bit store into it SIGBUS's on picky architectures.
This appears to happen because pdu.h marks struct ldp_pdu as __packed, which I believe authorizes the compiler to store it at non-aligned addresses. That choice seems to be old, but perhaps gcc 10 takes advantage of that in a way that previous versions didn't?
>How-To-Repeat:
Run /usr/tests tests on HPPA.
>Fix:
Perhaps it'd be okay to remove the __packed annotation?
>Release-Note:
>Audit-Trail:
From: Taylor R Campbell <riastradh@NetBSD.org>
To: Tom Lane <tgl@sss.pgh.pa.us>
Cc: gnats-bugs@NetBSD.org
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>
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--
From: Tom Lane <tgl@sss.pgh.pa.us>
To: Taylor R Campbell <riastradh@NetBSD.org>
Cc: gnats-bugs@NetBSD.org
Subject: Re: bin/56895: /usr/sbin/ldpd fails on alignment-picky architectures
Date: Mon, 20 Jun 2022 13:13:30 -0400
Taylor R Campbell <riastradh@NetBSD.org> writes:
> Can you try the attached patch and see if it helps?
Yup, that seems to do the trick --- net/mpls/t_ldp_regen passes now.
regards, tom lane
From: "Taylor R Campbell" <riastradh@netbsd.org>
To: gnats-bugs@gnats.NetBSD.org
Cc:
Subject: PR/56895 CVS commit: src/usr.sbin/ldpd
Date: Sun, 26 Jun 2022 17:55:38 +0000
Module Name: src
Committed By: riastradh
Date: Sun Jun 26 17:55:38 UTC 2022
Modified Files:
src/usr.sbin/ldpd: Makefile fsm.c ldp_peer.c socketops.c
Log Message:
ldpd(8): Fix address of misaligned packed members.
PR kern/56895
To generate a diff of this commit:
cvs rdiff -u -r1.7 -r1.8 src/usr.sbin/ldpd/Makefile
cvs rdiff -u -r1.15 -r1.16 src/usr.sbin/ldpd/fsm.c
cvs rdiff -u -r1.18 -r1.19 src/usr.sbin/ldpd/ldp_peer.c
cvs rdiff -u -r1.35 -r1.36 src/usr.sbin/ldpd/socketops.c
Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.
From: Tom Lane <tgl@sss.pgh.pa.us>
To: Taylor R Campbell <riastradh@NetBSD.org>
Cc: gnats-bugs@NetBSD.org
Subject: Re: bin/56895: /usr/sbin/ldpd fails on alignment-picky architectures
Date: Tue, 28 Jun 2022 11:00:43 -0400
I confirm that the net/mpls tests all pass for me on HPPA
as of HEAD/202206271040Z. Thanks!
regards, tom lane
State-Changed-From-To: open->pending-pullups
State-Changed-By: riastradh@NetBSD.org
State-Changed-When: Tue, 28 Jun 2022 17:02:49 +0000
State-Changed-Why:
fix committed to HEAD, code exists in netbsd-9
From: "Martin Husemann" <martin@netbsd.org>
To: gnats-bugs@gnats.NetBSD.org
Cc:
Subject: PR/56895 CVS commit: [netbsd-9] src/usr.sbin/ldpd
Date: Fri, 4 Aug 2023 13:26:17 +0000
Module Name: src
Committed By: martin
Date: Fri Aug 4 13:26:17 UTC 2023
Modified Files:
src/usr.sbin/ldpd [netbsd-9]: fsm.c ldp_peer.c socketops.c
Log Message:
Pull up following revision(s) (requested by riastradh in ticket #1702):
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
To generate a diff of this commit:
cvs rdiff -u -r1.15 -r1.15.28.1 src/usr.sbin/ldpd/fsm.c
cvs rdiff -u -r1.16 -r1.16.28.1 src/usr.sbin/ldpd/ldp_peer.c
cvs rdiff -u -r1.34 -r1.34.14.1 src/usr.sbin/ldpd/socketops.c
Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.
From: "Martin Husemann" <martin@netbsd.org>
To: gnats-bugs@gnats.NetBSD.org
Cc:
Subject: PR/56895 CVS commit: [netbsd-8] src/usr.sbin/ldpd
Date: Fri, 4 Aug 2023 13:28:40 +0000
Module Name: src
Committed By: martin
Date: Fri Aug 4 13:28:40 UTC 2023
Modified Files:
src/usr.sbin/ldpd [netbsd-8]: fsm.c ldp_peer.c socketops.c
Log Message:
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
To generate a diff of this commit:
cvs rdiff -u -r1.15 -r1.15.18.1 src/usr.sbin/ldpd/fsm.c
cvs rdiff -u -r1.16 -r1.16.18.1 src/usr.sbin/ldpd/ldp_peer.c
cvs rdiff -u -r1.34 -r1.34.4.1 src/usr.sbin/ldpd/socketops.c
Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.
State-Changed-From-To: pending-pullups->closed
State-Changed-By: riastradh@NetBSD.org
State-Changed-When: Sat, 05 Aug 2023 16:34:15 +0000
State-Changed-Why:
fixed in HEAD before 10 branch, pulled up to 9 and 8
>Unformatted:
(Contact us)
$NetBSD: query-full-pr,v 1.47 2022/09/11 19:34:41 kim Exp $
$NetBSD: gnats_config.sh,v 1.9 2014/08/02 14:16:04 spz Exp $
Copyright © 1994-2023
The NetBSD Foundation, Inc. ALL RIGHTS RESERVED.