From owner-svn-src-head@freebsd.org Tue Oct 23 13:03:04 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 0FCDFFD73E4; Tue, 23 Oct 2018 13:03:04 +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 B6FDE7B2EF; Tue, 23 Oct 2018 13:03:03 +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 B1DA11045D; Tue, 23 Oct 2018 13:03:03 +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 w9ND336k016373; Tue, 23 Oct 2018 13:03:03 GMT (envelope-from ae@FreeBSD.org) Received: (from ae@localhost) by repo.freebsd.org (8.15.2/8.15.2/Submit) id w9ND33C1016372; Tue, 23 Oct 2018 13:03:03 GMT (envelope-from ae@FreeBSD.org) Message-Id: <201810231303.w9ND33C1016372@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:03:03 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org Subject: svn commit: r339646 - head/sys/net X-SVN-Group: head X-SVN-Commit-Author: ae X-SVN-Commit-Paths: head/sys/net X-SVN-Commit-Revision: 339646 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:03:04 -0000 Author: ae Date: Tue Oct 23 13:03:03 2018 New Revision: 339646 URL: https://svnweb.freebsd.org/changeset/base/339646 Log: Add the check that current VNET is ready and access to srchash is allowed. ipsec_srcaddr() callback can be called during VNET teardown, since ingress address checking subsystem isn't VNET specific. And thus callback can make access to already freed memory. To prevent this, use V_ipsec_idhtbl pointer as indicator of VNET readiness. And make epoch_wait() after resetting it to NULL in vnet_ipsec_uninit() to be sure that ipsec_srcaddr() is finished its work. Reported by: kp MFC after: 20 days Modified: head/sys/net/if_ipsec.c Modified: head/sys/net/if_ipsec.c ============================================================================== --- head/sys/net/if_ipsec.c Tue Oct 23 13:00:11 2018 (r339645) +++ head/sys/net/if_ipsec.c Tue Oct 23 13:03:03 2018 (r339646) @@ -273,6 +273,13 @@ vnet_ipsec_uninit(const void *unused __unused) if_clone_detach(V_ipsec_cloner); free(V_ipsec_idhtbl, M_IPSEC); + /* + * Use V_ipsec_idhtbl pointer as indicator that VNET is going to be + * destroyed, it is used by ipsec_srcaddr() callback. + */ + V_ipsec_idhtbl = NULL; + IPSEC_WAIT(); + #ifdef INET if (IS_DEFAULT_VNET(curvnet)) ip_encap_unregister_srcaddr(ipsec4_srctab); @@ -784,6 +791,10 @@ ipsec_srcaddr(void *arg __unused, const struct sockadd { struct ipsec_softc *sc; struct secasindex *saidx; + + /* Check that VNET is ready */ + if (V_ipsec_idhtbl == NULL) + return; MPASS(in_epoch(net_epoch_preempt)); CK_LIST_FOREACH(sc, ipsec_srchash(sa), srchash) {