NetBSD Problem Report #52077

From www@NetBSD.org  Wed Mar 15 09:00:04 2017
Return-Path: <www@NetBSD.org>
Received: from mail.netbsd.org (mail.netbsd.org [199.233.217.200])
	(using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits))
	(Client CN "mail.netbsd.org", Issuer "Postmaster NetBSD.org" (verified OK))
	by mollari.NetBSD.org (Postfix) with ESMTPS id E43A07A2B3
	for <gnats-bugs@gnats.NetBSD.org>; Wed, 15 Mar 2017 09:00:04 +0000 (UTC)
Message-Id: <20170315090003.9E2777A2B4@mollari.NetBSD.org>
Date: Wed, 15 Mar 2017 09:00:03 +0000 (UTC)
From: s-yamaguchi@iij.ad.jp
Reply-To: s-yamaguchi@iij.ad.jp
To: gnats-bugs@NetBSD.org
Subject: "route add" installs unreachable gateway
X-Send-Pr-Version: www-1.0

>Number:         52077
>Category:       kern
>Synopsis:       "route add" installs unreachable gateway
>Confidential:   no
>Severity:       non-critical
>Priority:       low
>Responsible:    kern-bug-people
>State:          closed
>Class:          sw-bug
>Submitter-Id:   net
>Arrival-Date:   Wed Mar 15 09:05:00 +0000 2017
>Closed-Date:    Fri Mar 24 03:50:48 +0000 2017
>Last-Modified:  Fri Mar 24 04:05:00 +0000 2017
>Originator:     Shoichi Yamaguchi
>Release:        -current
>Organization:
Internet Initiative Japan Inc.
>Environment:
NetBSD netbsd 7.99.66 NetBSD 7.99.66 (GENERIC) #4: Wed Mar 15 15:04:08 JST 2017  root@deskfd:(hidden) amd64
>Description:
the "route add" command install wrong route whose gateway is unreachable if the destination is reachable. And the route whose gateway is directly connected cannot be installed.
I do not know whether this is bug, or not. But, OpenBSD fixed this behavior at the following commit.And, FreeBSD is same behavior as OpenBSD too
 - https://bitbucket.org/braindamaged/openbsd-src/commits/097d8d9ded40b4c7832d2e7e486a7876832445fc

>How-To-Repeat:
netbsd# route show -inet
Routing tables

Internet:
Destination        Gateway            Flags    Refs      Use    Mtu Interface
default            192.168.95.1       UG          -        -      -  wm1
127/8              localhost          UGR         -        -  33624  lo0
localhost          lo0                UHl         -        -  33624  lo0
192.168.56/24      link#2             U           -        -      -  wm0
192.168.56.68      link#2             UHl         -        -      -  lo0
192.168.95/24      link#3             U           -        -      -  wm1
192.168.95.105     link#3             UHl         -        -      -  lo0
netbsd# route add -net 192.168.56.192/26 10.0.0.1
add net 192.168.56.192: gateway 10.0.0.1
netbsd# route show -inet
Routing tables

Internet:
Destination        Gateway            Flags    Refs      Use    Mtu Interface
default            192.168.95.1       UG          -        -      -  wm1
127/8              localhost          UGR         -        -  33624  lo0
localhost          lo0                UHl         -        -  33624  lo0
192.168.56/24      link#2             U           -        -      -  wm0
192.168.56.68      link#2             UHl         -        -      -  lo0
192.168.56.192/26  10.0.0.1           UG          -        -      -  wm0
192.168.95/24      link#3             U           -        -      -  wm1
192.168.95.105     link#3             UHl         -        -      -  lo0
netbsd# route get 192.168.56.193
   route to: 192.168.56.193
destination: 192.168.56.192
       mask: 255.255.255.192
    gateway: 10.0.0.1
 local addr: 192.168.56.68
  interface: wm0
      flags: <UP,GATEWAY,DONE,STATIC>
 recvpipe  sendpipe  ssthresh  rtt,msec    rttvar  hopcount      mtu     expire
       0         0         0         0         0         0         0         0
>Fix:
diff --git a/sys/net/route.c b/sys/net/route.c
index 1411f54..c99fc6e 100644
--- a/sys/net/route.c
+++ b/sys/net/route.c
@@ -1026,11 +1026,15 @@ ifa_ifwithroute_psref(int flags, const struct sockaddr *dst,

                /* XXX we cannot call rtalloc1 if holding the rt lock */
                if (RT_LOCKED())
-                       rt = rtalloc1_locked(dst, 0, true);
+                       rt = rtalloc1_locked(gateway, 0, true);
                else
-                       rt = rtalloc1(dst, 0);
+                       rt = rtalloc1(gateway, 0);
                if (rt == NULL)
                        return NULL;
+               if (rt->rt_flags & RTF_GATEWAY) {
+                       rt_unref(rt);
+                       return NULL;
+               }
                /*
                 * Just in case. May not need to do this workaround.
                 * Revisit when working on rtentry MP-ification.


----------------------------------------------------------------
Added the RTF_GATEWAY check by looking at the following commit:
 - https://bitbucket.org/braindamaged/openbsd-src/commits/78ba7cb9777cd1540f703219bd6463521f1f138b

>Release-Note:

>Audit-Trail:
From: Ryota Ozaki <ozaki-r@netbsd.org>
To: s-yamaguchi@iij.ad.jp
Cc: "gnats-bugs@NetBSD.org" <gnats-bugs@netbsd.org>, kern-bug-people@netbsd.org, 
	gnats-admin@netbsd.org, netbsd-bugs@netbsd.org
Subject: Re: kern/52077: "route add" installs unreachable gateway
Date: Wed, 22 Mar 2017 16:35:25 +0900

 On Wed, Mar 15, 2017 at 6:05 PM,  <s-yamaguchi@iij.ad.jp> wrote:
 >>Number:         52077
 >>Category:       kern
 >>Synopsis:       "route add" installs unreachable gateway
 >>Confidential:   no
 >>Severity:       non-critical
 >>Priority:       low
 >>Responsible:    kern-bug-people
 >>State:          open
 >>Class:          sw-bug
 >>Submitter-Id:   net
 >>Arrival-Date:   Wed Mar 15 09:05:00 +0000 2017
 >>Originator:     Shoichi Yamaguchi
 >>Release:        -current
 >>Organization:
 > Internet Initiative Japan Inc.
 >>Environment:
 > NetBSD netbsd 7.99.66 NetBSD 7.99.66 (GENERIC) #4: Wed Mar 15 15:04:08 JST 2017  root@deskfd:(hidden) amd64
 >>Description:
 > the "route add" command install wrong route whose gateway is unreachable if the destination is reachable. And the route whose gateway is directly connected cannot be installed.
 > I do not know whether this is bug, or not. But, OpenBSD fixed this behavior at the following commit.And, FreeBSD is same behavior as OpenBSD too
 >  - https://bitbucket.org/braindamaged/openbsd-src/commits/097d8d9ded40b4c7832d2e7e486a7876832445fc
 >
 >>How-To-Repeat:
 > netbsd# route show -inet
 > Routing tables
 >
 > Internet:
 > Destination        Gateway            Flags    Refs      Use    Mtu Interface
 > default            192.168.95.1       UG          -        -      -  wm1
 > 127/8              localhost          UGR         -        -  33624  lo0
 > localhost          lo0                UHl         -        -  33624  lo0
 > 192.168.56/24      link#2             U           -        -      -  wm0
 > 192.168.56.68      link#2             UHl         -        -      -  lo0
 > 192.168.95/24      link#3             U           -        -      -  wm1
 > 192.168.95.105     link#3             UHl         -        -      -  lo0
 > netbsd# route add -net 192.168.56.192/26 10.0.0.1
 > add net 192.168.56.192: gateway 10.0.0.1
 > netbsd# route show -inet
 > Routing tables
 >
 > Internet:
 > Destination        Gateway            Flags    Refs      Use    Mtu Interface
 > default            192.168.95.1       UG          -        -      -  wm1
 > 127/8              localhost          UGR         -        -  33624  lo0
 > localhost          lo0                UHl         -        -  33624  lo0
 > 192.168.56/24      link#2             U           -        -      -  wm0
 > 192.168.56.68      link#2             UHl         -        -      -  lo0
 > 192.168.56.192/26  10.0.0.1           UG          -        -      -  wm0
 > 192.168.95/24      link#3             U           -        -      -  wm1
 > 192.168.95.105     link#3             UHl         -        -      -  lo0
 > netbsd# route get 192.168.56.193
 >    route to: 192.168.56.193
 > destination: 192.168.56.192
 >        mask: 255.255.255.192
 >     gateway: 10.0.0.1
 >  local addr: 192.168.56.68
 >   interface: wm0
 >       flags: <UP,GATEWAY,DONE,STATIC>
 >  recvpipe  sendpipe  ssthresh  rtt,msec    rttvar  hopcount      mtu     expire
 >        0         0         0         0         0         0         0         0
 >>Fix:
 > diff --git a/sys/net/route.c b/sys/net/route.c
 > index 1411f54..c99fc6e 100644
 > --- a/sys/net/route.c
 > +++ b/sys/net/route.c
 > @@ -1026,11 +1026,15 @@ ifa_ifwithroute_psref(int flags, const struct sockaddr *dst,
 >
 >                 /* XXX we cannot call rtalloc1 if holding the rt lock */
 >                 if (RT_LOCKED())
 > -                       rt = rtalloc1_locked(dst, 0, true);
 > +                       rt = rtalloc1_locked(gateway, 0, true);
 >                 else
 > -                       rt = rtalloc1(dst, 0);
 > +                       rt = rtalloc1(gateway, 0);
 >                 if (rt == NULL)
 >                         return NULL;
 > +               if (rt->rt_flags & RTF_GATEWAY) {
 > +                       rt_unref(rt);
 > +                       return NULL;
 > +               }
 >                 /*
 >                  * Just in case. May not need to do this workaround.
 >                  * Revisit when working on rtentry MP-ification.
 >
 >
 > ----------------------------------------------------------------
 > Added the RTF_GATEWAY check by looking at the following commit:
 >  - https://bitbucket.org/braindamaged/openbsd-src/commits/78ba7cb9777cd1540f703219bd6463521f1f138b
 >

 The patch breaks an ATF test, t_route#route_default_reject;
 "route change -inet6 default -reject" in the test begins failing.

 It seems that we need to skip route checks if a gateway isn't specified,
 which exist in FreeBSD and OpenBSD: http://www.netbsd.org/~ozaki-r/pr52077.diff

   ozaki-r

State-Changed-From-To: open->closed
State-Changed-By: ozaki-r@NetBSD.org
State-Changed-When: Fri, 24 Mar 2017 03:50:48 +0000
State-Changed-Why:
The patch with my tweaks is committed. Thanks.


From: "Ryota Ozaki" <ozaki-r@netbsd.org>
To: gnats-bugs@gnats.NetBSD.org
Cc: 
Subject: PR/52077 CVS commit: src/sys/net
Date: Fri, 24 Mar 2017 03:45:02 +0000

 Module Name:	src
 Committed By:	ozaki-r
 Date:		Fri Mar 24 03:45:02 UTC 2017

 Modified Files:
 	src/sys/net: route.c rtsock.c

 Log Message:
 Forbit installing a route which its gateway is unreachable

 This change needs a tweak in route_output_change to unbreak route
 change commands (e.g., route change -inet6 default -reject).

 PR kern/52077 (s-yamaguchi@IIJ and ozaki-r@)


 To generate a diff of this commit:
 cvs rdiff -u -r1.193 -r1.194 src/sys/net/route.c
 cvs rdiff -u -r1.210 -r1.211 src/sys/net/rtsock.c

 Please note that diffs are not public domain; they are subject to the
 copyright notices on the relevant files.

From: "Ryota Ozaki" <ozaki-r@netbsd.org>
To: gnats-bugs@gnats.NetBSD.org
Cc: 
Subject: PR/52077 CVS commit: src/tests/net/route
Date: Fri, 24 Mar 2017 03:47:25 +0000

 Module Name:	src
 Committed By:	ozaki-r
 Date:		Fri Mar 24 03:47:25 UTC 2017

 Modified Files:
 	src/tests/net/route: t_route.sh

 Log Message:
 Add test cases for PR kern/52077

 From s-yamaguchi@IIJ


 To generate a diff of this commit:
 cvs rdiff -u -r1.11 -r1.12 src/tests/net/route/t_route.sh

 Please note that diffs are not public domain; they are subject to the
 copyright notices on the relevant files.

>Unformatted:

NetBSD Home
NetBSD PR Database Search

(Contact us) $NetBSD: query-full-pr,v 1.39 2013/11/01 18:47:49 spz Exp $
$NetBSD: gnats_config.sh,v 1.8 2006/05/07 09:23:38 tsutsui Exp $
Copyright © 1994-2014 The NetBSD Foundation, Inc. ALL RIGHTS RESERVED.