Bug 26168

Summary: /usr/bin/netstat gets bus error with -i -a options
Product: Base System Reporter: jim <jim>
Component: binAssignee: Poul-Henning Kamp <phk>
Status: Closed FIXED    
Severity: Affects Only Me    
Priority: Normal    
Version: Unspecified   
Hardware: Any   
OS: Any   

Description jim 2001-03-28 13:40:01 UTC
/usr/bin/netstat gets bus error with -i -a options

How-To-Repeat: # netstat -i (works)
gw# netstat -i
Name  Mtu   Network       Address            Ipkts Ierrs    Opkts Oerrs  Coll
xl0   1500  <Link#1>    00:01:02:6e:26:05  4827866     0  3752028     0 230193
xl0   1500  net.net-117/2 198.96.117.68    4827745     -  3751997     -     -
xl0   1500  fe80:1::201 fe80:1::201:2ff:f        0     -        0     -     -
lp0*  1500  <Link#2>                             0     0        0     0     0
gif0* 1280  <Link#3>                             0     0        0     0     0
gif1* 1280  <Link#4>                             0     0        0     0     0
gif2* 1280  <Link#5>                             0     0        0     0     0
gif3* 1280  <Link#6>                             0     0        0     0     0
lo0   16384 <Link#7>                             4     0        4     0     0
lo0   16384 fe80:7::1   fe80:7::1                0     -        0     -     -
lo0   16384 localhost   ::1                      0     -        0     -     -
lo0   16384 loopback.loca localhost              4     -        4     -     -
ppp0* 1500  <Link#8>                             0     0        0     0     0
sl0*  552   <Link#9>                             0     0        0     0     0
faith 1500  <Link#10>          

netstat -ia (doesn't work)
gw# netstat -ia
Name  Mtu   Network       Address            Ipkts Ierrs    Opkts Oerrs  Coll
xl0   1500  <Link#1>    00:01:02:6e:26:05  4827896     0  3752053     0 230193
Bus error
Comment 1 Peter Pentchev 2001-03-28 14:15:24 UTC
On Wed, Mar 28, 2001 at 04:37:13AM -0800, jim@reptiles.org wrote:
> 
> >Number:         26168
> >Category:       bin
> >Synopsis:       /usr/bin/netstat gets bus error with -i -a options
> >Originator:     Jim Mercer
> >Release:        4.3-RC
> >Organization:
> Reptilian Research
> >Environment:
> gw# uname -a
> FreeBSD gw.reptiles.org 4.3-RC FreeBSD 4.3-RC #0: Tue Mar 27 18:24:41 EST 2001     root@gw.reptiles.org:/usr/src/sys/compile/GENERIC  i386
> >Description:
> /usr/bin/netstat gets bus error with -i -a options

I can confirm this; can you try the attached patch?

(multiaddr holds an address in KVM, not in userspace; dereferencing
 it does not give any meaningful value to the user process).

G'luck,
Peter

-- 
This inert sentence is my body, but my soul is alive, dancing in the sparks of your brain.

Index: src/usr.bin/netstat/if.c
===================================================================
RCS file: /home/ncvs/src/usr.bin/netstat/if.c,v
retrieving revision 1.32.2.5
diff -u -r1.32.2.5 if.c
--- src/usr.bin/netstat/if.c	2001/03/22 13:48:42	1.32.2.5
+++ src/usr.bin/netstat/if.c	2001/03/28 13:14:35
@@ -448,9 +448,10 @@
 			const char *fmt;
 
 			LIST_FOREACH(multiaddr, &ifnet.if_multiaddrs, ifma_link) {
-				if (kread(*(u_long *)multiaddr, (char *)&ifma,
+				if (kread((u_long)multiaddr, (char *)&ifma,
 					  sizeof ifma))
 					break;
+				multiaddr = &ifma;
 				if (kread((u_long)ifma.ifma_addr, (char *)&msa,
 					  sizeof msa))
 					break;
Comment 2 jim 2001-03-28 14:38:31 UTC
On Wed, Mar 28, 2001 at 04:15:24PM +0300, Peter Pentchev wrote:
> On Wed, Mar 28, 2001 at 04:37:13AM -0800, jim@reptiles.org wrote:
> > >Number:         26168
> > >Category:       bin
> > >Synopsis:       /usr/bin/netstat gets bus error with -i -a options
> > >Originator:     Jim Mercer
> > >Release:        4.3-RC
> > >Organization:
> > Reptilian Research
> > >Environment:
> > gw# uname -a
> > FreeBSD gw.reptiles.org 4.3-RC FreeBSD 4.3-RC #0: Tue Mar 27 18:24:41 EST 2001     root@gw.reptiles.org:/usr/src/sys/compile/GENERIC  i386
> > >Description:
> > /usr/bin/netstat gets bus error with -i -a options
> 
> I can confirm this; can you try the attached patch?
> 
> (multiaddr holds an address in KVM, not in userspace; dereferencing
>  it does not give any meaningful value to the user process).

this patch seems to have fixed it:

gw# /usr/bin/netstat -ia
Name  Mtu   Network       Address            Ipkts Ierrs    Opkts Oerrs  Coll
xl0   1500  <Link#1>    00:01:02:6e:26:05      498     0      328     0     0
Bus error

gw# make install
install -c -s -o root -g kmem -m 2555   netstat /usr/bin
install -c -o root -g wheel -m 444 netstat.1.gz  /usr/share/man/man1

gw# netstat -ia
Name  Mtu   Network       Address            Ipkts Ierrs    Opkts Oerrs  Coll
xl0   1500  <Link#1>    00:01:02:6e:26:05      595     0      388     0     0
                        33:33:5e:86:7b:45
                        33:33:0:0:0:1
                        33:33:ff:6e:26:5
                        1:0:5e:0:0:1
...
faith 1500  <Link#10>                 

> 
> G'luck,
> Peter
> 
> -- 
> This inert sentence is my body, but my soul is alive, dancing in the sparks of your brain.
> 
> Index: src/usr.bin/netstat/if.c
> ===================================================================
> RCS file: /home/ncvs/src/usr.bin/netstat/if.c,v
> retrieving revision 1.32.2.5
> diff -u -r1.32.2.5 if.c
> --- src/usr.bin/netstat/if.c	2001/03/22 13:48:42	1.32.2.5
> +++ src/usr.bin/netstat/if.c	2001/03/28 13:14:35
> @@ -448,9 +448,10 @@
>  			const char *fmt;
>  
>  			LIST_FOREACH(multiaddr, &ifnet.if_multiaddrs, ifma_link) {
> -				if (kread(*(u_long *)multiaddr, (char *)&ifma,
> +				if (kread((u_long)multiaddr, (char *)&ifma,
>  					  sizeof ifma))
>  					break;
> +				multiaddr = &ifma;
>  				if (kread((u_long)ifma.ifma_addr, (char *)&msa,
>  					  sizeof msa))
>  					break;

-- 
[ Jim Mercer          jim@pneumonoultramicroscopicsilicovolcanoconiosis.ca ]
[          Reptilian Research -- Longer Life through Colder Blood          ]
[ aka                        jim@reptiles.org              +1 416 410-5633 ]
Comment 3 Peter Pentchev freebsd_committer freebsd_triage 2001-03-28 14:58:54 UTC
Responsible Changed
From-To: freebsd-bugs->des

It seems that DES introduced the wrong dereferencing of multiaddr in 
the TAILQ changeover in rev. 1.32.2.5.
Comment 4 Garrett A. Wollman 2001-03-28 16:39:57 UTC
<<On Wed, 28 Mar 2001 05:20:02 -0800 (PST), Peter Pentchev <roam@orbitel.bg> said:

>   			LIST_FOREACH(multiaddr, &ifnet.if_multiaddrs, ifma_link) {
>  -				if (kread(*(u_long *)multiaddr, (char *)&ifma,
>  +				if (kread((u_long)multiaddr, (char *)&ifma,
>   					  sizeof ifma))
>   					break;
>  +				multiaddr = &ifma;

Yet another reason why the LIST_FOREACH macro is an utter botch.

-GAWollman
Comment 5 Dag-Erling Smørgrav freebsd_committer freebsd_triage 2001-03-28 22:16:02 UTC
Responsible Changed
From-To: des->phk

I backed out part of my MFC, so it works again in -STABLE, but it's still 
broken in -CURRENT.  Pass it on to phk, who broke it in the first place.
Comment 6 Poul-Henning Kamp freebsd_committer freebsd_triage 2001-03-30 20:16:09 UTC
State Changed
From-To: open->closed

Fixed, thanks!