From 6e081509db323a8352d22e9f4793f7837634abf7 Mon Sep 17 00:00:00 2001 From: "Andrey V. Elsukov" Date: Thu, 28 Jun 2018 11:39:27 +0000 Subject: [PATCH] Add NULL pointer check. encap_lookup_t method can be invoked by IP encap subsytem even if none of gif/gre/me interfaces are exist. Hash tables are allocated on demand, when first interface is created. So, make NULL pointer check before doing access to hash table. PR: 229378 --- sys/net/if_me.c | 3 +++ sys/netinet/in_gif.c | 3 +++ sys/netinet/ip_gre.c | 3 +++ sys/netinet6/in6_gif.c | 3 +++ sys/netinet6/ip6_gre.c | 3 +++ 5 files changed, 15 insertions(+) diff --git a/sys/net/if_me.c b/sys/net/if_me.c index 024d392cc3e9..9ba44b0cb215 100644 --- a/sys/net/if_me.c +++ b/sys/net/if_me.c @@ -312,6 +312,9 @@ me_lookup(const struct mbuf *m, int off, int proto, void **arg) const struct ip *ip; struct me_softc *sc; + if (V_me_hashtbl == NULL) + return (0); + MPASS(in_epoch()); ip = mtod(m, const struct ip *); CK_LIST_FOREACH(sc, &ME_HASH(ip->ip_dst.s_addr, diff --git a/sys/netinet/in_gif.c b/sys/netinet/in_gif.c index 5f4af01b199a..06b567400297 100644 --- a/sys/netinet/in_gif.c +++ b/sys/netinet/in_gif.c @@ -289,6 +289,9 @@ in_gif_lookup(const struct mbuf *m, int off, int proto, void **arg) struct gif_softc *sc; int ret; + if (V_ipv4_hashtbl == NULL) + return (0); + MPASS(in_epoch()); ip = mtod(m, const struct ip *); /* diff --git a/sys/netinet/ip_gre.c b/sys/netinet/ip_gre.c index ee36a0e18fce..9ee09f1e28d5 100644 --- a/sys/netinet/ip_gre.c +++ b/sys/netinet/ip_gre.c @@ -115,6 +115,9 @@ in_gre_lookup(const struct mbuf *m, int off, int proto, void **arg) const struct ip *ip; struct gre_softc *sc; + if (V_ipv4_hashtbl == NULL) + return (0); + MPASS(in_epoch()); ip = mtod(m, const struct ip *); CK_LIST_FOREACH(sc, &GRE_HASH(ip->ip_dst.s_addr, diff --git a/sys/netinet6/in6_gif.c b/sys/netinet6/in6_gif.c index 1834660ce1ee..cbcbfae0abc9 100644 --- a/sys/netinet6/in6_gif.c +++ b/sys/netinet6/in6_gif.c @@ -309,6 +309,9 @@ in6_gif_lookup(const struct mbuf *m, int off, int proto, void **arg) struct gif_softc *sc; int ret; + if (V_ipv6_hashtbl == NULL) + return (0); + MPASS(in_epoch()); /* * NOTE: it is safe to iterate without any locking here, because softc diff --git a/sys/netinet6/ip6_gre.c b/sys/netinet6/ip6_gre.c index b3c419ce6e6a..bb786c9416e8 100644 --- a/sys/netinet6/ip6_gre.c +++ b/sys/netinet6/ip6_gre.c @@ -107,6 +107,9 @@ in6_gre_lookup(const struct mbuf *m, int off, int proto, void **arg) const struct ip6_hdr *ip6; struct gre_softc *sc; + if (V_ipv6_hashtbl == NULL) + return (0); + MPASS(in_epoch()); ip6 = mtod(m, const struct ip6_hdr *); CK_LIST_FOREACH(sc, &GRE_HASH(&ip6->ip6_dst, &ip6->ip6_src), chain) {