From nobody Mon May 06 22:27:52 2024 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 4VYGJ86q3wz5JTkT; Mon, 06 May 2024 22:27:52 +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 4VYGJ84cPnz4Qjl; Mon, 6 May 2024 22:27:52 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1715034472; 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=P0ELmj+gd5Oi9kRRSiUCzAbUN4HLCpwGeBwLud51Cdc=; b=PLpl/2XZ/2y+FnWwkeWUsiu3HDl9PXyVdxyMrtp9aWMDBvscSik9H2WYU0sBRHG11x8a5A NubItH7YCofkVUlrmnAkpjDL9L3Bv2MzwaZPPedCLU9gVSAN3S9qJpUfWZrqCyOuDLkv6m mLTnO1r57YNCFWrYEnyrjXIRfb0zJxDWA9Bb8hIBkWYDk9ScNbT4CaBk0Vv6UjIfCb+viQ UIl22Xx3xFBD0yFyH2OCVnJLsotKXBrPw5I+13EXhoSUH/OzpHPiZ4KJjPPjTMBYMv6Tm7 bNyJMQjgNg50nFO9CKQ9DUgayN0QmNszFQw98f8/380XsGl2vXvg7A6v8FFxHQ== ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1715034472; a=rsa-sha256; cv=none; b=tVvPPV6Tj1uOmakpcCJNzqSeIvPzGmq/j9k2MH5OO9X3E8sOc3Xg/9wi9XUv27BJwnzGGn 2ImX/rmEJSvG5/l6/BkvQxOcHr4OPaODmmwoOiyR/FAZZE3JILbhsY3/By33CSfyNUs83w 2tvFfWkNedvDrnX5fuT4+EbTZtO8ZV6cwOADs3N3G3iI2vPPeUjQ5Vq1+XkFbjTw2cF0pO 8VBS+0h/OTAPtRZ79KM6snIVbz8FNjIjvhOU7lxbTw+E0zfDBMrWF7FMyGmp3rrawAGYZY HD5ybTkPfnTltm2e5ql1BL96sraN9UwcMve/C0Vlqhl62fJ13HJl2/wHyDmc8A== ARC-Authentication-Results: i=1; mx1.freebsd.org; none ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1715034472; 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=P0ELmj+gd5Oi9kRRSiUCzAbUN4HLCpwGeBwLud51Cdc=; b=RH8W9/cIDW4+GDsX8NSSyhttbzL4GcwaP4K0S5ZuSghJ0zALLbsW4wC0qvPsJnP/sZdulv gYX0wF2pzZjCit8GWCeu7k4ViUzmDDCgSBbEc8vP5CRx6GtxH9Utz3lEYy6HEaETgArnmF HzBsmfBDu37+NdzKofqvImLVkVprqU+nN7RpOfrmdZCxXz99H1XBI95lP22rkmbB5LVVsB ++7Z4QnymP4ZI+gpmK6hdoYkhyOpGxZx1XZyO6xsu3Uiowgmk4EMDQ+ZYDZaHUhsPI8XGs 4Tzl7M/IQZiQhih9G8LNcqRsvsQgZy/Dv8fSHIdd4IS8ddFCgZ3GcFns0DXK1w== 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 4VYGJ84CgtzFyG; Mon, 6 May 2024 22:27:52 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from gitrepo.freebsd.org ([127.0.1.44]) by gitrepo.freebsd.org (8.17.1/8.17.1) with ESMTP id 446MRqig052371; Mon, 6 May 2024 22:27:52 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.17.1/8.17.1/Submit) id 446MRqTu052368; Mon, 6 May 2024 22:27:52 GMT (envelope-from git) Date: Mon, 6 May 2024 22:27:52 GMT Message-Id: <202405062227.446MRqTu052368@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-main@FreeBSD.org From: Gleb Smirnoff Subject: git: fadbb6f85a2e - main - lagg: remove use of net epoch in the ioctl paths 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: X-BeenThere: dev-commits-src-all@freebsd.org Sender: owner-dev-commits-src-all@FreeBSD.org MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Git-Committer: glebius X-Git-Repository: src X-Git-Refname: refs/heads/main X-Git-Reftype: branch X-Git-Commit: fadbb6f85a2ea6d804c12848e3fcfdb6f62fc039 Auto-Submitted: auto-generated The branch main has been updated by glebius: URL: https://cgit.FreeBSD.org/src/commit/?id=fadbb6f85a2ea6d804c12848e3fcfdb6f62fc039 commit fadbb6f85a2ea6d804c12848e3fcfdb6f62fc039 Author: Gleb Smirnoff AuthorDate: 2024-05-06 22:25:53 +0000 Commit: Gleb Smirnoff CommitDate: 2024-05-06 22:27:32 +0000 lagg: remove use of net epoch in the ioctl paths Rely on LAGG_SLOCK() instead. The use of network epoch(9) here was added in 6573d7580b851 (later tidied by 87bf9b9cbeebc) as a large sweep that blindly substituted blocking kernel primitives with epoch(9). In these particular code paths use of epoch(9) is incorrect and doesn't provide any protection against a stale pointer. Recent fix 48698ead6ff0, which should actually have removed the epoch use, created a potential sleeping in epoch problem. --- sys/net/if_lagg.c | 33 +++++++++++---------------------- 1 file changed, 11 insertions(+), 22 deletions(-) diff --git a/sys/net/if_lagg.c b/sys/net/if_lagg.c index 1f169ee32696..bb882ac819ad 100644 --- a/sys/net/if_lagg.c +++ b/sys/net/if_lagg.c @@ -1015,7 +1015,6 @@ lagg_port_destroy(struct lagg_port *lp, int rundelport) static int lagg_port_ioctl(struct ifnet *ifp, u_long cmd, caddr_t data) { - struct epoch_tracker et; struct lagg_reqport *rp = (struct lagg_reqport *)data; struct lagg_softc *sc; struct lagg_port *lp = NULL; @@ -1040,17 +1039,13 @@ lagg_port_ioctl(struct ifnet *ifp, u_long cmd, caddr_t data) break; } - NET_EPOCH_ENTER(et); - if ((lp = ifp->if_lagg) == NULL || lp->lp_softc != sc) { - error = ENOENT; - NET_EPOCH_EXIT(et); - break; - } - LAGG_SLOCK(sc); - lagg_port2req(lp, rp); + if (__predict_true((lp = ifp->if_lagg) != NULL && + lp->lp_softc == sc)) + lagg_port2req(lp, rp); + else + error = ENOENT; /* XXXGL: can happen? */ LAGG_SUNLOCK(sc); - NET_EPOCH_EXIT(et); break; case SIOCSIFCAP: @@ -1350,7 +1345,6 @@ lagg_stop(struct lagg_softc *sc) static int lagg_ioctl(struct ifnet *ifp, u_long cmd, caddr_t data) { - struct epoch_tracker et; struct lagg_softc *sc = (struct lagg_softc *)ifp->if_softc; struct lagg_reqall *ra = (struct lagg_reqall *)data; struct lagg_reqopts *ro = (struct lagg_reqopts *)data; @@ -1600,21 +1594,16 @@ lagg_ioctl(struct ifnet *ifp, u_long cmd, caddr_t data) break; } - NET_EPOCH_ENTER(et); - if ((lp = (struct lagg_port *)tpif->if_lagg) == NULL || - lp->lp_softc != sc) { - error = ENOENT; - NET_EPOCH_EXIT(et); - if_rele(tpif); - break; - } - LAGG_SLOCK(sc); - lagg_port2req(lp, rp); + if (__predict_true((lp = tpif->if_lagg) != NULL && + lp->lp_softc == sc)) + lagg_port2req(lp, rp); + else + error = ENOENT; /* XXXGL: can happen? */ LAGG_SUNLOCK(sc); - NET_EPOCH_EXIT(et); if_rele(tpif); break; + case SIOCSLAGGPORT: error = priv_check(td, PRIV_NET_LAGG); if (error)