From nobody Mon Apr 10 04:16:49 2023 X-Original-To: dev-commits-src-all@mlmmj.nyi.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mlmmj.nyi.freebsd.org (Postfix) with ESMTP id 4Pvwf96xBRz44kSX; Mon, 10 Apr 2023 04:16:49 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from mxrelay.nyi.freebsd.org (mxrelay.nyi.freebsd.org [IPv6:2610:1c1:1:606c::19:3]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256 client-signature RSA-PSS (4096 bits) client-digest SHA256) (Client CN "mxrelay.nyi.freebsd.org", Issuer "R3" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 4Pvwf943BXz4Mkn; Mon, 10 Apr 2023 04:16:49 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1681100209; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=fyJF/FYjOwXVUVl3PLloQA4hs8DTMMLikhp/UB6BSLQ=; b=QjUNF1Q+VbFw605ysioWLjo2CL6f15Hx/EzoKgcF2Gr9zHn4ViI0swROEK0mUMN2UZkqlo DNhR0TjksAEE8ly8jZ8gcvggUHgeAWIivwKfxRKdYu/LxtD2S84sxPmaafxN0kHWAGNLiZ /QVNUWEzLqP0aZ2Hr13azjIg5HVd8/cc+d8JakNv2KIeluEx8VJ/3Lf8TXsZZ1c8UnvCOs 9ou38m/sSKOLZjO1Am+wRzJrTsS4so7pFexngpiBR+JG26aL74DF7IR66VLssb5rquGnVP +w9zYkx0lEh3QE50wfTtEs7WxuLkgB1Fjsd1Ag7Z2m8K1/WylXFp6DpfqUq+9w== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1681100209; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=fyJF/FYjOwXVUVl3PLloQA4hs8DTMMLikhp/UB6BSLQ=; b=pS5V99g0hw9hJJKxX9TsJ61cgP37HHrDbUdWhRHcjBcanswWuywfnHEkBGWCxXENXKkUCL eZI/YU7NtZ6m8zQAXR1VgLcTjyJIWUHb4AIotc7737pKZe4hsJ//0ODZCQXJ0J2u38zRel r6EejtUEwKAv5wVMiCuSrvb4dfVIl6ssVdnc9Yu7ViNE9rvYf0AzB+fTscdN5ni+ZYLkvm INKg4wmwjUzJkXWZ2Z8GfpmyrKAt4I4HwGlusDax2g2NAW4dTm2zXh3QZBvAPZ05L5RY7C 9xHyRDsSXAMSOvjWhsJktqJYkY4Ds1pW0Tb49LkhEjAFL59zLXZrfPLm5si/9w== ARC-Authentication-Results: i=1; mx1.freebsd.org; none ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1681100209; a=rsa-sha256; cv=none; b=QfHwJhARbLJ0xvn+Q6sSkU8EZPQKaIy28Q/F0oAl8zXRKKW7QtNnJhFykXx1LytCklQ7V4 qlTJ53lLKFs/ZbgpaLY/1O6wOXwI4vmuRs+3gL5DhP49CWvCXzc6kER4kHJ+kzrJBqobYO zuukbdoX7TLVqVk/Dpf4790T3NqWmdCIhQbGzeQKx3rjWFUYwgGFORBmi8CWfXKyf79zkj moVOUmxrfaKIWQVSJ1iH+y5o3K5lAHkDw2oXTKhQjWFvyYdEQScfWWWG/yd0kW12BvdTT7 ymL8c1r1C9ysDXdq8p+QQpLCyRa0sA3aakUvp1vPOZ3vlhjNVPl5llXs5EMjfg== Received: from gitrepo.freebsd.org (gitrepo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:5]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (Client did not present a certificate) by mxrelay.nyi.freebsd.org (Postfix) with ESMTPS id 4Pvwf91vhszZvm; Mon, 10 Apr 2023 04:16:49 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from gitrepo.freebsd.org ([127.0.1.44]) by gitrepo.freebsd.org (8.16.1/8.16.1) with ESMTP id 33A4Gnjp039639; Mon, 10 Apr 2023 04:16:49 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.16.1/8.16.1/Submit) id 33A4Gnua039638; Mon, 10 Apr 2023 04:16:49 GMT (envelope-from git) Date: Mon, 10 Apr 2023 04:16:49 GMT Message-Id: <202304100416.33A4Gnua039638@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-branches@FreeBSD.org From: Zhenlei Huang Subject: git: 5d45e09d50e6 - stable/13 - infiniband: Widen NET_EPOCH coverage List-Id: Commit messages for all branches of the src repository List-Archive: https://lists.freebsd.org/archives/dev-commits-src-all List-Help: List-Post: List-Subscribe: List-Unsubscribe: Sender: owner-dev-commits-src-all@freebsd.org X-BeenThere: dev-commits-src-all@freebsd.org MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Git-Committer: zlei X-Git-Repository: src X-Git-Refname: refs/heads/stable/13 X-Git-Reftype: branch X-Git-Commit: 5d45e09d50e648a75667c9b12b204eb62fa60ed2 Auto-Submitted: auto-generated X-ThisMailContainsUnwantedMimeParts: N The branch stable/13 has been updated by zlei: URL: https://cgit.FreeBSD.org/src/commit/?id=5d45e09d50e648a75667c9b12b204eb62fa60ed2 commit 5d45e09d50e648a75667c9b12b204eb62fa60ed2 Author: Zhenlei Huang AuthorDate: 2023-04-02 16:51:49 +0000 Commit: Zhenlei Huang CommitDate: 2023-04-10 04:15:04 +0000 infiniband: Widen NET_EPOCH coverage From static code analysis, some device drivers (cxgbe, mlx4, mthca, and qlnx) do not enter net epoch before lagg_input_infiniband(). If IPoIB interface is a member of lagg(4) interface, and after returning from lagg_input_infiniband() the receiving interface of mbuf is set to lagg(4) interface, then when concurrently destroying the lagg(4) interface, there is a small window that the interface gets destroyed and becomes invalid before infiniband_input() re-enter net epoch, thus leading use-after-free. Widen NET_EPOCH coverage to prevent use-after-free. Thanks hselasky@ for testing with mlx5 devices. Reviewed by: hselasky Tested by: hselasky MFC after: 1 week Differential Revision: https://reviews.freebsd.org/D39275 (cherry picked from commit 90820ef121b38479f2479c03c12c69f940f5fa33) --- sys/net/if_infiniband.c | 4 ++-- sys/net/if_lagg.c | 5 +---- 2 files changed, 3 insertions(+), 6 deletions(-) diff --git a/sys/net/if_infiniband.c b/sys/net/if_infiniband.c index 4dfbd5272d15..9bf4756f2556 100644 --- a/sys/net/if_infiniband.c +++ b/sys/net/if_infiniband.c @@ -411,6 +411,7 @@ infiniband_input(struct ifnet *ifp, struct mbuf *m) int isr; CURVNET_SET_QUIET(ifp->if_vnet); + NET_EPOCH_ENTER(et); if ((ifp->if_flags & IFF_UP) == 0) { if_inc_counter(ifp, IFCOUNTER_IERRORS, 1); @@ -498,10 +499,9 @@ infiniband_input(struct ifnet *ifp, struct mbuf *m) mac_ifnet_create_mbuf(ifp, m); #endif /* Allow monitor mode to claim this frame, after stats are updated. */ - NET_EPOCH_ENTER(et); netisr_dispatch(isr, m); - NET_EPOCH_EXIT(et); done: + NET_EPOCH_EXIT(et); CURVNET_RESTORE(); } diff --git a/sys/net/if_lagg.c b/sys/net/if_lagg.c index 3bbcb4f8e4cd..687c07971d60 100644 --- a/sys/net/if_lagg.c +++ b/sys/net/if_lagg.c @@ -2086,16 +2086,14 @@ lagg_input_ethernet(struct ifnet *ifp, struct mbuf *m) static struct mbuf * lagg_input_infiniband(struct ifnet *ifp, struct mbuf *m) { - struct epoch_tracker et; struct lagg_port *lp = ifp->if_lagg; struct lagg_softc *sc = lp->lp_softc; struct ifnet *scifp = sc->sc_ifp; - NET_EPOCH_ENTER(et); + NET_EPOCH_ASSERT(); if ((scifp->if_drv_flags & IFF_DRV_RUNNING) == 0 || lp->lp_detaching != 0 || sc->sc_proto == LAGG_PROTO_NONE) { - NET_EPOCH_EXIT(et); m_freem(m); return (NULL); } @@ -2110,7 +2108,6 @@ lagg_input_infiniband(struct ifnet *ifp, struct mbuf *m) } } - NET_EPOCH_EXIT(et); return (m); }