From owner-svn-src-head@freebsd.org Tue Oct 23 13:11:47 2018 Return-Path: Delivered-To: svn-src-head@mailman.ysv.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mailman.ysv.freebsd.org (Postfix) with ESMTP id 4E024FD794A; Tue, 23 Oct 2018 13:11:47 +0000 (UTC) (envelope-from ae@FreeBSD.org) Received: from mxrelay.nyi.freebsd.org (mxrelay.nyi.freebsd.org [IPv6:2610:1c1:1:606c::19:3]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client CN "mxrelay.nyi.freebsd.org", Issuer "Let's Encrypt Authority X3" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 003247BB60; Tue, 23 Oct 2018 13:11:47 +0000 (UTC) (envelope-from ae@FreeBSD.org) Received: from repo.freebsd.org (repo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:0]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client did not present a certificate) by mxrelay.nyi.freebsd.org (Postfix) with ESMTPS id EF488105DF; Tue, 23 Oct 2018 13:11:46 +0000 (UTC) (envelope-from ae@FreeBSD.org) Received: from repo.freebsd.org ([127.0.1.37]) by repo.freebsd.org (8.15.2/8.15.2) with ESMTP id w9NDBkSL020760; Tue, 23 Oct 2018 13:11:46 GMT (envelope-from ae@FreeBSD.org) Received: (from ae@localhost) by repo.freebsd.org (8.15.2/8.15.2/Submit) id w9NDBknc020756; Tue, 23 Oct 2018 13:11:46 GMT (envelope-from ae@FreeBSD.org) Message-Id: <201810231311.w9NDBknc020756@repo.freebsd.org> X-Authentication-Warning: repo.freebsd.org: ae set sender to ae@FreeBSD.org using -f From: "Andrey V. Elsukov" Date: Tue, 23 Oct 2018 13:11:46 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org Subject: svn commit: r339649 - in head/sys: net netinet netinet6 X-SVN-Group: head X-SVN-Commit-Author: ae X-SVN-Commit-Paths: in head/sys: net netinet netinet6 X-SVN-Commit-Revision: 339649 X-SVN-Commit-Repository: base MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-src-head@freebsd.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: SVN commit messages for the src tree for head/-current List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 23 Oct 2018 13:11:47 -0000 Author: ae Date: Tue Oct 23 13:11:45 2018 New Revision: 339649 URL: https://svnweb.freebsd.org/changeset/base/339649 Log: Add the check that current VNET is ready and access to srchash is allowed. This change is similar to r339646. The callback that checks for appearing and disappearing of tunnel ingress address can be called during VNET teardown. To prevent access to already freed memory, add check to the callback and epoch_wait() call to be sure that callback has finished its work. MFC after: 20 days Modified: head/sys/net/if_me.c head/sys/netinet/in_gif.c head/sys/netinet/ip_gre.c head/sys/netinet6/in6_gif.c head/sys/netinet6/ip6_gre.c Modified: head/sys/net/if_me.c ============================================================================== --- head/sys/net/if_me.c Tue Oct 23 13:07:03 2018 (r339648) +++ head/sys/net/if_me.c Tue Oct 23 13:11:45 2018 (r339649) @@ -161,6 +161,7 @@ me_hashinit(void) static void vnet_me_init(const void *unused __unused) { + V_me_cloner = if_clone_simple(mename, me_clone_create, me_clone_destroy, 0); } @@ -173,6 +174,8 @@ vnet_me_uninit(const void *unused __unused) if (V_me_hashtbl != NULL) { free(V_me_hashtbl, M_IFME); + V_me_hashtbl = NULL; + ME_WAIT(); free(V_me_srchashtbl, M_IFME); } if_clone_detach(V_me_cloner); @@ -363,7 +366,8 @@ me_srcaddr(void *arg __unused, const struct sockaddr * const struct sockaddr_in *sin; struct me_softc *sc; - if (V_me_srchashtbl == NULL) + /* Check that VNET is ready */ + if (V_me_hashtbl == NULL) return; MPASS(in_epoch(net_epoch_preempt)); Modified: head/sys/netinet/in_gif.c ============================================================================== --- head/sys/netinet/in_gif.c Tue Oct 23 13:07:03 2018 (r339648) +++ head/sys/netinet/in_gif.c Tue Oct 23 13:11:45 2018 (r339649) @@ -148,7 +148,8 @@ in_gif_srcaddr(void *arg __unused, const struct sockad const struct sockaddr_in *sin; struct gif_softc *sc; - if (V_ipv4_srchashtbl == NULL) + /* Check that VNET is ready */ + if (V_ipv4_hashtbl == NULL) return; MPASS(in_epoch(net_epoch_preempt)); @@ -457,6 +458,8 @@ in_gif_uninit(void) } if (V_ipv4_hashtbl != NULL) { gif_hashdestroy(V_ipv4_hashtbl); + V_ipv4_hashtbl = NULL; + GIF_WAIT(); gif_hashdestroy(V_ipv4_srchashtbl); } } Modified: head/sys/netinet/ip_gre.c ============================================================================== --- head/sys/netinet/ip_gre.c Tue Oct 23 13:07:03 2018 (r339648) +++ head/sys/netinet/ip_gre.c Tue Oct 23 13:11:45 2018 (r339649) @@ -167,7 +167,8 @@ in_gre_srcaddr(void *arg __unused, const struct sockad const struct sockaddr_in *sin; struct gre_softc *sc; - if (V_ipv4_srchashtbl == NULL) + /* Check that VNET is ready */ + if (V_ipv4_hashtbl == NULL) return; MPASS(in_epoch(net_epoch_preempt)); @@ -350,6 +351,8 @@ in_gre_uninit(void) } if (V_ipv4_hashtbl != NULL) { gre_hashdestroy(V_ipv4_hashtbl); + V_ipv4_hashtbl = NULL; + GRE_WAIT(); gre_hashdestroy(V_ipv4_srchashtbl); } } Modified: head/sys/netinet6/in6_gif.c ============================================================================== --- head/sys/netinet6/in6_gif.c Tue Oct 23 13:07:03 2018 (r339648) +++ head/sys/netinet6/in6_gif.c Tue Oct 23 13:11:45 2018 (r339649) @@ -153,7 +153,8 @@ in6_gif_srcaddr(void *arg __unused, const struct socka const struct sockaddr_in6 *sin; struct gif_softc *sc; - if (V_ipv6_srchashtbl == NULL) + /* Check that VNET is ready */ + if (V_ipv6_hashtbl == NULL) return; MPASS(in_epoch(net_epoch_preempt)); @@ -480,6 +481,8 @@ in6_gif_uninit(void) } if (V_ipv6_hashtbl != NULL) { gif_hashdestroy(V_ipv6_hashtbl); + V_ipv6_hashtbl = NULL; + GIF_WAIT(); gif_hashdestroy(V_ipv6_srchashtbl); } } Modified: head/sys/netinet6/ip6_gre.c ============================================================================== --- head/sys/netinet6/ip6_gre.c Tue Oct 23 13:07:03 2018 (r339648) +++ head/sys/netinet6/ip6_gre.c Tue Oct 23 13:11:45 2018 (r339649) @@ -160,7 +160,8 @@ in6_gre_srcaddr(void *arg __unused, const struct socka const struct sockaddr_in6 *sin; struct gre_softc *sc; - if (V_ipv6_srchashtbl == NULL) + /* Check that VNET is ready */ + if (V_ipv6_hashtbl == NULL) return; MPASS(in_epoch(net_epoch_preempt)); @@ -338,6 +339,8 @@ in6_gre_uninit(void) } if (V_ipv6_hashtbl != NULL) { gre_hashdestroy(V_ipv6_hashtbl); + V_ipv6_hashtbl = NULL; + GRE_WAIT(); gre_hashdestroy(V_ipv6_srchashtbl); } }