From nobody Thu Oct 07 08:41:26 2021 X-Original-To: net@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 74AF417E0619 for ; Thu, 7 Oct 2021 08:41:26 +0000 (UTC) (envelope-from bugzilla-noreply@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 4HQ4YL2fNzz4YLr for ; Thu, 7 Oct 2021 08:41:26 +0000 (UTC) (envelope-from bugzilla-noreply@freebsd.org) Received: from kenobi.freebsd.org (kenobi.freebsd.org [IPv6:2610:1c1:1:606c::50:1d]) (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 3BC0510AD6 for ; Thu, 7 Oct 2021 08:41:26 +0000 (UTC) (envelope-from bugzilla-noreply@freebsd.org) Received: from kenobi.freebsd.org ([127.0.1.5]) by kenobi.freebsd.org (8.15.2/8.15.2) with ESMTP id 1978fQ89015602 for ; Thu, 7 Oct 2021 08:41:26 GMT (envelope-from bugzilla-noreply@freebsd.org) Received: (from www@localhost) by kenobi.freebsd.org (8.15.2/8.15.2/Submit) id 1978fQOe015601 for net@FreeBSD.org; Thu, 7 Oct 2021 08:41:26 GMT (envelope-from bugzilla-noreply@freebsd.org) X-Authentication-Warning: kenobi.freebsd.org: www set sender to bugzilla-noreply@freebsd.org using -f From: bugzilla-noreply@freebsd.org To: net@FreeBSD.org Subject: [Bug 258849] IPSec may generate duplicate SPIs Date: Thu, 07 Oct 2021 08:41:26 +0000 X-Bugzilla-Reason: AssignedTo X-Bugzilla-Type: changed X-Bugzilla-Watch-Reason: None X-Bugzilla-Product: Base System X-Bugzilla-Component: kern X-Bugzilla-Version: CURRENT X-Bugzilla-Keywords: X-Bugzilla-Severity: Affects Some People X-Bugzilla-Who: mjg@FreeBSD.org X-Bugzilla-Status: In Progress X-Bugzilla-Resolution: X-Bugzilla-Priority: --- X-Bugzilla-Assigned-To: net@FreeBSD.org X-Bugzilla-Flags: X-Bugzilla-Changed-Fields: Message-ID: In-Reply-To: References: Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable X-Bugzilla-URL: https://bugs.freebsd.org/bugzilla/ Auto-Submitted: auto-generated List-Id: Networking and TCP/IP with FreeBSD List-Archive: https://lists.freebsd.org/archives/freebsd-net List-Help: List-Post: List-Subscribe: List-Unsubscribe: Sender: owner-freebsd-net@freebsd.org MIME-Version: 1.0 X-ThisMailContainsUnwantedMimeParts: N https://bugs.freebsd.org/bugzilla/show_bug.cgi?id=3D258849 --- Comment #4 from Mateusz Guzik --- So I don't think this is fixable in a clean manner without significant=20 refactoring in the area. I think the pragmatic thing to do here is to try to hoist the sahtree lock = out of key_do_getnewspi. The problem is that there are several callers and call= ees to be adjusted which may end up being rather hairy. As a cop out one can slap an additional lock around all of this, in this manner: diff --git a/sys/netipsec/key.c b/sys/netipsec/key.c index 72c598586d8e..f5da63d7b8f1 100644 --- a/sys/netipsec/key.c +++ b/sys/netipsec/key.c @@ -5628,6 +5628,7 @@ key_add(struct socket *so, struct mbuf *m, const stru= ct sadb_msghdr *mhp) * secasindex. * XXXAE: IPComp seems also doesn't use SPI. */ + SPI_ALLOC_LOCK(); if (proto =3D=3D IPPROTO_TCP) { sav =3D key_getsav_tcpmd5(&saidx, &spi); if (sav =3D=3D NULL && spi =3D=3D 0) { @@ -5648,6 +5649,7 @@ key_add(struct socket *so, struct mbuf *m, const stru= ct sadb_msghdr *mhp) } sav =3D key_newsav(mhp, &saidx, spi, &error); + SPI_ALLOC_UNLOCK(); if (sav =3D=3D NULL) return key_senderror(so, m, error); KEYDBG(KEY_STAMP, Note this may be turn out to not be a big problem as key_newsav takes rm lo= ck for writing which already comes with drastic overhead. Any thoughts on this, ae? --=20 You are receiving this mail because: You are the assignee for the bug.=