From nobody Sun Nov 14 20:17:46 2021 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 20E82184D8C6; Sun, 14 Nov 2021 20:17:47 +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 4HskCH0LC6z3jY9; Sun, 14 Nov 2021 20:17:47 +0000 (UTC) (envelope-from git@FreeBSD.org) 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 DBEE84BB8; Sun, 14 Nov 2021 20:17:46 +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 1AEKHkPH082348; Sun, 14 Nov 2021 20:17:46 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.16.1/8.16.1/Submit) id 1AEKHkTx082347; Sun, 14 Nov 2021 20:17:46 GMT (envelope-from git) Date: Sun, 14 Nov 2021 20:17:46 GMT Message-Id: <202111142017.1AEKHkTx082347@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-main@FreeBSD.org From: Mateusz Guzik Subject: git: e469b16d0b91 - main - ipsec: fix edge case detection in key_getnewspid 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: mjg X-Git-Repository: src X-Git-Refname: refs/heads/main X-Git-Reftype: branch X-Git-Commit: e469b16d0b91c0c37427a19d574c112c9eaba6e5 Auto-Submitted: auto-generated X-ThisMailContainsUnwantedMimeParts: N The branch main has been updated by mjg: URL: https://cgit.FreeBSD.org/src/commit/?id=e469b16d0b91c0c37427a19d574c112c9eaba6e5 commit e469b16d0b91c0c37427a19d574c112c9eaba6e5 Author: Mateusz Guzik AuthorDate: 2021-11-03 18:50:41 +0000 Commit: Mateusz Guzik CommitDate: 2021-11-14 20:17:34 +0000 ipsec: fix edge case detection in key_getnewspid Same comparison problem as in key_do_getnewspi. Reviewed by: ae Sponsored by: Rubicon Communications, LLC ("Netgate") Differential Revision: https://reviews.freebsd.org/D32827 --- sys/netipsec/key.c | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/sys/netipsec/key.c b/sys/netipsec/key.c index 9a810fa49931..e2e1d76911ec 100644 --- a/sys/netipsec/key.c +++ b/sys/netipsec/key.c @@ -2147,10 +2147,12 @@ key_getnewspid(void) { struct secpolicy *sp; uint32_t newid = 0; - int count = V_key_spi_trycnt; /* XXX */ + int tries, limit; SPTREE_WLOCK_ASSERT(); - while (count--) { + + limit = atomic_load_int(&V_key_spi_trycnt); + for (tries = 0; tries < limit; tries++) { if (V_policy_id == ~0) /* overflowed */ newid = V_policy_id = 1; else @@ -2162,7 +2164,7 @@ key_getnewspid(void) if (sp == NULL) break; } - if (count == 0 || newid == 0) { + if (tries == limit || newid == 0) { ipseclog((LOG_DEBUG, "%s: failed to allocate policy id.\n", __func__)); return (0);