NetBSD Problem Report #58235
From martin@aprisoft.de Wed May 8 15:27:21 2024
Return-Path: <martin@aprisoft.de>
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 CC2581A9238
for <gnats-bugs@gnats.NetBSD.org>; Wed, 8 May 2024 15:27:21 +0000 (UTC)
Message-Id: <20240508152712.A9D5A5CC795@emmas.aprisoft.de>
Date: Wed, 8 May 2024 17:27:12 +0200 (CEST)
From: martin@NetBSD.org
Reply-To: martin@NetBSD.org
To: gnats-bugs@NetBSD.org
Subject: compat_netbsd32 broken for SIOCGIFDATA
X-Send-Pr-Version: 3.95
>Number: 58235
>Category: kern
>Synopsis: compat_netbsd32 broken for SIOCGIFDATA
>Confidential: no
>Severity: serious
>Priority: medium
>Responsible: pgoyette
>State: closed
>Class: sw-bug
>Submitter-Id: net
>Arrival-Date: Wed May 08 15:30:00 +0000 2024
>Closed-Date: Sat May 11 17:31:01 +0000 2024
>Last-Modified: Sat May 11 17:31:01 +0000 2024
>Originator: Martin Husemann
>Release: NetBSD 10.99.10
>Organization:
The NetBSD Foundation, Inc.
>Environment:
System: NetBSD seven-days-to-the-wolves.aprisoft.de 10.99.10 NetBSD 10.99.10 (GENERIC) #698: Wed May 8 14:54:31 CEST 2024 martin@seven-days-to-the-wolves.aprisoft.de:/work/src/sys/arch/amd64/compile/GENERIC amd64
Architecture: x86_64
Machine: amd64
>Description:
On an amd64 machine running a -current GENERIC kernel running i386 "ifconfig" will fail
like this:
# ifconfig lo0
lo0: flags=0x8049<UP,LOOPBACK,RUNNING,MULTICAST> mtu 33624
ifconfig: media_status: SIOCGIFDATA: Inappropriate ioctl for device
(both for the i386 binary running in a native installation via /usr/lib/i386 as
well as in a full populated i386 chroot)
This breaks some ATF tests (e.g. lib/libc/net/getaddrinfo/t_getaddrinfo)
>How-To-Repeat:
s/a
>Fix:
n/a
>Release-Note:
>Audit-Trail:
From: Paul Goyette <paul@whooppee.com>
To: gnats-bugs@netbsd.org
Cc:
Subject: Re: kern/58235: compat_netbsd32 broken for SIOCGIFDATA
Date: Wed, 8 May 2024 09:21:41 -0700 (PDT)
Is this related to ker/52193 ??
On Wed, 8 May 2024, martin@NetBSD.org wrote:
>> Number: 58235
>> Category: kern
>> Synopsis: compat_netbsd32 broken for SIOCGIFDATA
>> Confidential: no
>> Severity: serious
>> Priority: medium
>> Responsible: kern-bug-people
>> State: open
>> Class: sw-bug
>> Submitter-Id: net
>> Arrival-Date: Wed May 08 15:30:00 +0000 2024
>> Originator: Martin Husemann
>> Release: NetBSD 10.99.10
>> Organization:
> The NetBSD Foundation, Inc.
>> Environment:
> System: NetBSD seven-days-to-the-wolves.aprisoft.de 10.99.10 NetBSD 10.99.10 (GENERIC) #698: Wed May 8 14:54:31 CEST 2024 martin@seven-days-to-the-wolves.aprisoft.de:/work/src/sys/arch/amd64/compile/GENERIC amd64
> Architecture: x86_64
> Machine: amd64
>> Description:
>
> On an amd64 machine running a -current GENERIC kernel running i386 "ifconfig" will fail
> like this:
>
> # ifconfig lo0
> lo0: flags=0x8049<UP,LOOPBACK,RUNNING,MULTICAST> mtu 33624
> ifconfig: media_status: SIOCGIFDATA: Inappropriate ioctl for device
>
> (both for the i386 binary running in a native installation via /usr/lib/i386 as
> well as in a full populated i386 chroot)
>
> This breaks some ATF tests (e.g. lib/libc/net/getaddrinfo/t_getaddrinfo)
>
>> How-To-Repeat:
> s/a
>
>> Fix:
> n/a
>
>
> !DSPAM:663b9a82217104547016204!
>
>
+---------------------+--------------------------+----------------------+
| Paul Goyette (.sig) | PGP Key fingerprint: | E-mail addresses: |
| (Retired) | 1B11 1849 721C 56C8 F63A | paul@whooppee.com |
| Software Developer | 6E2E 05FD 15CE 9F2D 5102 | pgoyette@netbsd.org |
| & Network Engineer | | pgoyette99@gmail.com |
+---------------------+--------------------------+----------------------+
From: Martin Husemann <martin@duskware.de>
To: gnats-bugs@netbsd.org
Cc:
Subject: Re: kern/58235: compat_netbsd32 broken for SIOCGIFDATA
Date: Wed, 8 May 2024 18:29:00 +0200
On Wed, May 08, 2024 at 04:25:02PM +0000, Paul Goyette wrote:
> Is this related to ker/52193 ??
GENERIC has all compat code builtin.
Martin
From: Paul Goyette <paul@whooppee.com>
To: gnats-bugs@netbsd.org
Cc:
Subject: Re: kern/58235: compat_netbsd32 broken for SIOCGIFDATA
Date: Wed, 8 May 2024 09:34:36 -0700 (PDT)
> > Is this related to ker/52193 ??
>
> GENERIC has all compat code builtin.
Ah, right. So it must be something different.
+---------------------+--------------------------+----------------------+
| Paul Goyette (.sig) | PGP Key fingerprint: | E-mail addresses: |
| (Retired) | 1B11 1849 721C 56C8 F63A | paul@whooppee.com |
| Software Developer | 6E2E 05FD 15CE 9F2D 5102 | pgoyette@netbsd.org |
| & Network Engineer | | pgoyette99@gmail.com |
+---------------------+--------------------------+----------------------+
From: Martin Husemann <martin@duskware.de>
To: gnats-bugs@NetBSD.org
Cc:
Subject: Re: kern/58235: compat_netbsd32 broken for SIOCGIFDATA
Date: Wed, 8 May 2024 18:35:52 +0200
On Wed, May 08, 2024 at 04:30:02PM +0000, Martin Husemann wrote:
> GENERIC has all compat code builtin.
At first glance it is trivial to add. The ioctl arg includes if_data,
which is *nearly* constant size but has a struct timespec at the end,
so the size of the struct will vary slightly (causing the numeric value
of the ioctl to not match) and the only translation needed is a
netbsd32_to_timespec() for ifi_lastchange.
Martin
From: Paul Goyette <paul@whooppee.com>
To: gnats-bugs@netbsd.org
Cc:
Subject: Re: kern/58235: compat_netbsd32 broken for SIOCGIFDATA
Date: Wed, 8 May 2024 09:57:42 -0700 (PDT)
On Wed, 8 May 2024, Martin Husemann wrote:
> At first glance it is trivial to add. The ioctl arg includes if_data,
> which is *nearly* constant size but has a struct timespec at the end,
> so the size of the struct will vary slightly (causing the numeric value
> of the ioctl to not match) and the only translation needed is a
> netbsd32_to_timespec() for ifi_lastchange.
Hmmm, IIRC the struct timespec could cause problems as that was
changed in compat_50. So you might need to add more compat code
there, too.
+---------------------+--------------------------+----------------------+
| Paul Goyette (.sig) | PGP Key fingerprint: | E-mail addresses: |
| (Retired) | 1B11 1849 721C 56C8 F63A | paul@whooppee.com |
| Software Developer | 6E2E 05FD 15CE 9F2D 5102 | pgoyette@netbsd.org |
| & Network Engineer | | pgoyette99@gmail.com |
+---------------------+--------------------------+----------------------+
From: Martin Husemann <martin@duskware.de>
To: gnats-bugs@NetBSD.org
Cc:
Subject: Re: kern/58235: compat_netbsd32 broken for SIOCGIFDATA
Date: Wed, 8 May 2024 20:05:55 +0200
Here is a patch that works, but it seems the compiler needs the
__packed and the manual alignement, else the struct has the same size
as the native version (at least on amd64).
Ugly - any better tricks?
Martin
Index: netbsd32_ioctl.c
===================================================================
RCS file: /cvsroot/src/sys/compat/netbsd32/netbsd32_ioctl.c,v
retrieving revision 1.120
diff -u -p -r1.120 netbsd32_ioctl.c
--- netbsd32_ioctl.c 22 Dec 2021 00:21:32 -0000 1.120
+++ netbsd32_ioctl.c 8 May 2024 18:03:41 -0000
@@ -151,6 +151,20 @@ netbsd32_to_oifreq(struct netbsd32_oifre
}
static inline void
+netbsd32_to_ifdatareq(struct netbsd32_ifdatareq *s32p, struct ifdatareq *p, u_long cmd)
+{
+
+ memcpy(p, s32p, sizeof *s32p);
+ switch (cmd) {
+ case SIOCGIFDATA:
+ case SIOCZIFDATA:
+ netbsd32_to_timespec(&s32p->ifdr_data.ifi_lastchange,
+ &p->ifdr_data.ifi_lastchange);
+ break;
+ }
+}
+
+static inline void
netbsd32_to_if_addrprefreq(const struct netbsd32_if_addrprefreq *ifap32,
struct if_addrprefreq *ifap, u_long cmd)
{
@@ -693,6 +707,20 @@ netbsd32_from_oifreq(struct oifreq *p,
}
static inline void
+netbsd32_from_ifdatareq(const struct ifdatareq *p, struct netbsd32_ifdatareq *p32, u_long cmd)
+{
+
+ memcpy(p32, p, sizeof *p32);
+ switch (cmd) {
+ case SIOCGIFDATA:
+ case SIOCZIFDATA:
+ netbsd32_from_timespec(&p->ifdr_data.ifi_lastchange,
+ &p32->ifdr_data.ifi_lastchange);
+ break;
+ }
+}
+
+static inline void
netbsd32_from_if_addrprefreq(const struct if_addrprefreq *ifap,
struct netbsd32_if_addrprefreq *ifap32, u_long cmd)
{
@@ -1537,6 +1565,10 @@ netbsd32_ioctl(struct lwp *l,
case SIOCSIFADDRPREF32:
IOCTL_STRUCT_CONV_TO(SIOCSIFADDRPREF, if_addrprefreq);
+ case SIOCGIFDATA32:
+ IOCTL_STRUCT_CONV_TO(SIOCGIFDATA, ifdatareq);
+ case SIOCZIFDATA32:
+ IOCTL_STRUCT_CONV_TO(SIOCZIFDATA, ifdatareq);
case OSIOCGIFFLAGS32:
IOCTL_STRUCT_CONV_TO(OSIOCGIFFLAGS, oifreq);
Index: netbsd32_ioctl.h
===================================================================
RCS file: /cvsroot/src/sys/compat/netbsd32/netbsd32_ioctl.h,v
retrieving revision 1.79
diff -u -p -r1.79 netbsd32_ioctl.h
--- netbsd32_ioctl.h 22 Dec 2021 00:21:32 -0000 1.79
+++ netbsd32_ioctl.h 8 May 2024 18:03:41 -0000
@@ -316,6 +316,35 @@ struct netbsd32_if_clonereq {
netbsd32_charp ifcr_buffer;
};
+struct netbsd32_if_data {
+ u_char ifi_type;
+ u_char ifi_addrlen;
+ u_char ifi_hdrlen;
+ u_char __pack_dummy;
+ int ifi_link_state;
+ uint64_t ifi_mtu;
+ uint64_t ifi_metric;
+ uint64_t ifi_baudrate;
+ uint64_t ifi_ipackets;
+ uint64_t ifi_ierrors;
+ uint64_t ifi_opackets;
+ uint64_t ifi_oerrors;
+ uint64_t ifi_collisions;
+ uint64_t ifi_ibytes;
+ uint64_t ifi_obytes;
+ uint64_t ifi_imcasts;
+ uint64_t ifi_omcasts;
+ uint64_t ifi_iqdrops;
+ uint64_t ifi_noproto;
+ struct netbsd32_timespec ifi_lastchange;
+} __packed;
+
+struct netbsd32_ifdatareq {
+ char ifdr_name[IFNAMSIZ]; /* if name, e.g. "en0" */
+ struct netbsd32_if_data ifdr_data;
+};
+
+
/* from <dev/pci/if_devar.h> */
#define SIOCGADDRROM32 _IOW('i', 240, struct netbsd32_ifreq) /* get 128 bytes of ROM */
#define SIOCGCHIPID32 _IOWR('i', 241, struct netbsd32_ifreq) /* get chipid */
@@ -388,6 +417,10 @@ struct netbsd32_if_clonereq {
#define SIOCGIFMTU32 _IOWR('i', 126, struct netbsd32_ifreq) /* get ifnet mtu */
#define OSIOCGIFMTU32 _IOWR('i', 126, struct netbsd32_oifreq) /* get ifnet mtu */
+
+#define SIOCGIFDATA32 _IOWR('i', 133, struct netbsd32_ifdatareq)
+#define SIOCZIFDATA32 _IOWR('i', 134, struct netbsd32_ifdatareq)
+
/* was 125 SIOCSIFASYNCMAP32 */
/* was 124 SIOCGIFASYNCMAP32 */
/* from <net/bpf.h> */
From: Paul Goyette <paul@whooppee.com>
To: gnats-bugs@netbsd.org
Cc:
Subject: Re: kern/58235: compat_netbsd32 broken for SIOCGIFDATA
Date: Wed, 8 May 2024 15:22:39 -0700 (PDT)
On Wed, 8 May 2024, Paul Goyette wrote:
>> At first glance it is trivial to add. The ioctl arg includes if_data,
>> which is *nearly* constant size but has a struct timespec at the end,
>> so the size of the struct will vary slightly (causing the numeric value
>> of the ioctl to not match) and the only translation needed is a
>> netbsd32_to_timespec() for ifi_lastchange.
>
> Hmmm, IIRC the struct timespec could cause problems as that was
> changed in compat_50. So you might need to add more compat code
> there, too.
This additionall change should probsbly go into some source file
like compat32_netif_50.c and be added to the compat_netbsd32_50
module. This would give us compat32 support for pre- and post-50
From: Paul Goyette <paul@whooppee.com>
To: gnats-bugs@netbsd.org
Cc:
Subject: Re: kern/58235: compat_netbsd32 broken for SIOCGIFDATA
Date: Wed, 8 May 2024 15:32:02 -0700 (PDT)
On Wed, 8 May 2024, Paul Goyette wrote:
> The following reply was made to PR kern/58235; it has been noted by GNATS.
>
> From: Paul Goyette <paul@whooppee.com>
> To: gnats-bugs@netbsd.org
> Cc:
> Subject: Re: kern/58235: compat_netbsd32 broken for SIOCGIFDATA
> Date: Wed, 8 May 2024 15:22:39 -0700 (PDT)
>
> On Wed, 8 May 2024, Paul Goyette wrote:
>
> >> At first glance it is trivial to add. The ioctl arg includes if_data,
> >> which is *nearly* constant size but has a struct timespec at the end,
> >> so the size of the struct will vary slightly (causing the numeric value
> >> of the ioctl to not match) and the only translation needed is a
> >> netbsd32_to_timespec() for ifi_lastchange.
> >
> > Hmmm, IIRC the struct timespec could cause problems as that was
> > changed in compat_50. So you might need to add more compat code
> > there, too.
>
> This additionall change should probsbly go into some source file
> like compat32_netif_50.c and be added to the compat_netbsd32_50
> module. This would give us compat32 support for pre- and post-50
A good example of where this has prevously been done might be the
src/sys/modules/compat_netbsd32_quota{,_50} modules.
From: Martin Husemann <martin@duskware.de>
To: gnats-bugs@netbsd.org
Cc:
Subject: Re: kern/58235: compat_netbsd32 broken for SIOCGIFDATA
Date: Thu, 9 May 2024 08:37:20 +0200
On Wed, May 08, 2024 at 10:35:01PM +0000, Paul Goyette wrote:
> > This additionall change should probsbly go into some source file
> > like compat32_netif_50.c and be added to the compat_netbsd32_50
> > module. This would give us compat32 support for pre- and post-50
>
> A good example of where this has prevously been done might be the
> src/sys/modules/compat_netbsd32_quota{,_50} modules.
Sorry, you lost me here - what additional change?
Martin
From: Paul Goyette <paul@whooppee.com>
To: gnats-bugs@netbsd.org
Cc:
Subject: Re: kern/58235: compat_netbsd32 broken for SIOCGIFDATA
Date: Thu, 9 May 2024 00:06:08 -0700 (PDT)
On Thu, 9 May 2024, Martin Husemann wrote:
> The following reply was made to PR kern/58235; it has been noted by GNATS.
>
> From: Martin Husemann <martin@duskware.de>
> To: gnats-bugs@netbsd.org
> Cc:
> Subject: Re: kern/58235: compat_netbsd32 broken for SIOCGIFDATA
> Date: Thu, 9 May 2024 08:37:20 +0200
>
> On Wed, May 08, 2024 at 10:35:01PM +0000, Paul Goyette wrote:
> > > This additionall change should probsbly go into some source file
> > > like compat32_netif_50.c and be added to the compat_netbsd32_50
> > > module. This would give us compat32 support for pre- and post-50
> >
> > A good example of where this has prevously been done might be the
> > src/sys/modules/compat_netbsd32_quota{,_50} modules.
>
> Sorry, you lost me here - what additional change?
Sorry, my poor phrasing - I got lost, too!
The timespec change varies depending on whether you have compat_50 or
not. So to be fully compatable, there needs to be two versions of the
compat32 stuff, not just one. Both versions need to adjust for the
other args.
For completeness, you should test your changes for two different
i386 images. Both images would be 32-bit, but one image would be
from pre-5.0 and the other image would be post-5.0 (or current).
There would be _two_ modules affected by the changes. The "plain"
compat_netbsd32, and the compat_netbsd32_50 module.
+---------------------+--------------------------+----------------------+
| Paul Goyette (.sig) | PGP Key fingerprint: | E-mail addresses: |
| (Retired) | 1B11 1849 721C 56C8 F63A | paul@whooppee.com |
| Software Developer | 6E2E 05FD 15CE 9F2D 5102 | pgoyette@netbsd.org |
| & Network Engineer | | pgoyette99@gmail.com |
+---------------------+--------------------------+----------------------+
From: Martin Husemann <martin@duskware.de>
To: gnats-bugs@netbsd.org
Cc:
Subject: Re: kern/58235: compat_netbsd32 broken for SIOCGIFDATA
Date: Thu, 9 May 2024 09:12:38 +0200
On Thu, May 09, 2024 at 07:10:01AM +0000, Paul Goyette wrote:
> The timespec change varies depending on whether you have compat_50 or
> not. So to be fully compatable, there needs to be two versions of the
> compat32 stuff, not just one. Both versions need to adjust for the
> other args.
OK, I'll verify that pre-5.0 binaries also work.
Martin
From: Martin Husemann <martin@duskware.de>
To: gnats-bugs@netbsd.org
Cc:
Subject: Re: kern/58235: compat_netbsd32 broken for SIOCGIFDATA
Date: Thu, 9 May 2024 13:29:38 +0200
I tested NetBSD 4.0 and 5.2.3 binaries, both for amd64 and i386.
The 4.0 ones work fine, ifconfig is using different ioctls there, which are
properly translated.
The 5.x ones do not work at all - from a quick glance due to the sysctls
used by getifaddrs(3) not working. I'll leave this part alone.
If noone has better ideas how to deal with the struct layout in the compat
structures in my patch, I'll commit it in a few days.
Martin
From: Paul Goyette <paul@whooppee.com>
To: Martin Husemann <martin@duskware.de>
Cc: gnats-bugs@netbsd.org
Subject: Re: kern/58235: compat_netbsd32 broken for SIOCGIFDATA
Date: Thu, 9 May 2024 05:59:53 -0700 (PDT)
On Thu, 9 May 2024, Martin Husemann wrote:
> The following reply was made to PR kern/58235; it has been noted by GNATS.
>
> From: Martin Husemann <martin@duskware.de>
> To: gnats-bugs@netbsd.org
> Cc:
> Subject: Re: kern/58235: compat_netbsd32 broken for SIOCGIFDATA
> Date: Thu, 9 May 2024 13:29:38 +0200
>
> I tested NetBSD 4.0 and 5.2.3 binaries, both for amd64 and i386.
>
> The 4.0 ones work fine, ifconfig is using different ioctls there, which are
> properly translated.
>
> The 5.x ones do not work at all - from a quick glance due to the sysctls
> used by getifaddrs(3) not working. I'll leave this part alone.
>
> If noone has better ideas how to deal with the struct layout in the compat
> structures in my patch, I'll commit it in a few days.
I'm not really clear on what combinations you tested. But go ahead and
commit what you have, and _please_ file a new PR for the getifaddrs(3)
problems, and assign both PRs to me. I will try to get everything to
work, especially in a NOCOMPAT environment (with none of the compat code
built-in). It will take me some time to get a test environment set up.
+---------------------+--------------------------+----------------------+
| Paul Goyette (.sig) | PGP Key fingerprint: | E-mail addresses: |
| (Retired) | 1B11 1849 721C 56C8 F63A | paul@whooppee.com |
| Software Developer | 6E2E 05FD 15CE 9F2D 5102 | pgoyette@netbsd.org |
| & Network Engineer | | pgoyette99@gmail.com |
+---------------------+--------------------------+----------------------+
From: "Martin Husemann" <martin@netbsd.org>
To: gnats-bugs@gnats.NetBSD.org
Cc:
Subject: PR/58235 CVS commit: src/sys/compat/netbsd32
Date: Sat, 11 May 2024 10:22:17 +0000
Module Name: src
Committed By: martin
Date: Sat May 11 10:22:17 UTC 2024
Modified Files:
src/sys/compat/netbsd32: netbsd32_ioctl.c netbsd32_ioctl.h
Log Message:
PR 58235: add support for SIOCGIFDATA and SIOCZIFDATA ioctls.
To generate a diff of this commit:
cvs rdiff -u -r1.120 -r1.121 src/sys/compat/netbsd32/netbsd32_ioctl.c
cvs rdiff -u -r1.79 -r1.80 src/sys/compat/netbsd32/netbsd32_ioctl.h
Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.
Responsible-Changed-From-To: kern-bug-people->martin
Responsible-Changed-By: martin@NetBSD.org
Responsible-Changed-When: Sat, 11 May 2024 10:26:44 +0000
Responsible-Changed-Why:
take
State-Changed-From-To: open->closed
State-Changed-By: martin@NetBSD.org
State-Changed-When: Sat, 11 May 2024 10:26:44 +0000
State-Changed-Why:
fixed
Responsible-Changed-From-To: martin->pgoyette
Responsible-Changed-By: martin@NetBSD.org
Responsible-Changed-When: Sat, 11 May 2024 10:29:22 +0000
Responsible-Changed-Why:
Paul want's to look at the module side of things more closely
State-Changed-From-To: closed->open
State-Changed-By: martin@NetBSD.org
State-Changed-When: Sat, 11 May 2024 10:29:22 +0000
State-Changed-Why:
Keep it open untill Paul is satisfied with the state
State-Changed-From-To: open->closed
State-Changed-By: pgoyette@NetBSD.org
State-Changed-When: Sat, 11 May 2024 17:31:01 +0000
State-Changed-Why:
Looks good to me, modulo kern/54150
>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-2024
The NetBSD Foundation, Inc. ALL RIGHTS RESERVED.