Source-Changes-HG archive

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

[src/trunk]: src/sys/net Sanity check the tunnel route after computing it and...



details:   https://anonhg.NetBSD.org/src/rev/04e0c514e88b
branches:  trunk
changeset: 518099:04e0c514e88b
user:      martin <martin%NetBSD.org@localhost>
date:      Sat Nov 24 15:46:08 2001 +0000

description:
Sanity check the tunnel route after computing it and don't mark the
interface up if there is no route or the route loops back to ourself.
This helps to avoid pilot errors which would result in kernel stack
overflows.

diffstat:

 sys/net/if_gre.c |  32 ++++++++++++++++++++++++--------
 1 files changed, 24 insertions(+), 8 deletions(-)

diffs (88 lines):

diff -r 3bca3fa258e3 -r 04e0c514e88b sys/net/if_gre.c
--- a/sys/net/if_gre.c  Sat Nov 24 14:27:03 2001 +0000
+++ b/sys/net/if_gre.c  Sat Nov 24 15:46:08 2001 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: if_gre.c,v 1.24 2001/11/24 00:21:27 martin Exp $ */
+/*     $NetBSD: if_gre.c,v 1.25 2001/11/24 15:46:08 martin Exp $ */
 
 /*
  * Copyright (c) 1998 The NetBSD Foundation, Inc.
@@ -46,7 +46,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: if_gre.c,v 1.24 2001/11/24 00:21:27 martin Exp $");
+__KERNEL_RCSID(0, "$NetBSD: if_gre.c,v 1.25 2001/11/24 15:46:08 martin Exp $");
 
 #include "opt_inet.h"
 #include "opt_ns.h"
@@ -118,7 +118,7 @@
 struct if_clone gre_cloner =
     IF_CLONE_INITIALIZER("gre", gre_clone_create, gre_clone_destroy);
 
-void gre_compute_route(struct gre_softc *sc);
+int gre_compute_route(struct gre_softc *sc);
 
 void   greattach __P((int));
 
@@ -373,8 +373,8 @@
                            (sc->g_dst.s_addr != INADDR_ANY)) {
                                if (sc->route.ro_rt != 0) /* free old route */
                                        RTFREE(sc->route.ro_rt);
-                               gre_compute_route(sc);
-                               ifp->if_flags |= IFF_UP;
+                               if (gre_compute_route(sc) == 0)
+                                       ifp->if_flags |= IFF_UP;
                        }
                }
                break;
@@ -465,8 +465,8 @@
                    (sc->g_dst.s_addr != INADDR_ANY)) {
                        if (sc->route.ro_rt != 0) /* free old route */
                                RTFREE(sc->route.ro_rt);
-                       gre_compute_route(sc);
-                       ifp->if_flags |= IFF_UP;
+                       if (gre_compute_route(sc) == 0)
+                               ifp->if_flags |= IFF_UP;
                }
                break;
        case GREGADDRS:
@@ -498,7 +498,7 @@
  * a-->b. We know that this one exists as in normal operation we have
  * at least a default route which matches.
  */
-void
+int
 gre_compute_route(struct gre_softc *sc)
 {
        struct route *ro;
@@ -535,6 +535,20 @@
        rtalloc(ro);
 
        /*
+        * check if this returned a route at all and this route is no
+        * recursion to ourself
+        */
+       if (ro->ro_rt == NULL || ro->ro_rt->rt_ifp->if_softc == sc) {
+#ifdef DIAGNOSTIC
+               if (ro->ro_rt == NULL)
+                       printf(" - no route found!\n");
+               else
+                       printf(" - route loops back to ourself!\n");
+#endif
+               return EADDRNOTAVAIL;
+       }
+
+       /*
         * now change it back - else ip_output will just drop
         * the route and search one to this interface ...
         */
@@ -546,6 +560,8 @@
            inet_ntoa(((struct sockaddr_in *)(ro->ro_rt->rt_gateway))->sin_addr));
        printf("\n");
 #endif
+
+       return 0;
 }
 
 /*



Home | Main Index | Thread Index | Old Index