From nobody Sun Aug 25 06:36:11 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 4Ws3wq6VZpz5VQyT; Sun, 25 Aug 2024 06:36:11 +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 "R11" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 4Ws3wq5nD0z4kCQ; Sun, 25 Aug 2024 06:36:11 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1724567771; 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=6oMDf7gs8JnUiXxJ5Br6RakATYsMX+GMzfTmA2XOEuU=; b=nDOkyWMICJspQKBvZudOpxwLfWR7OhMH7GvVy5KV/JpK5pQUc95Jdb8YaR7uwYjoDIJO9+ xTppB8dAQB9CRglHBvHFMBTPcZJ0i/8pgPA4XzXJZ/yadb3dDXvuoVHWvbFxwxKIJqFyXP pphLRxRssbYbTmQN+R3IcBV43rxMQdk7Ezv0RGUjli1ytSfygctRhlhoyy54ye6E8yAMuy NgejhbnjAmwPFBk1+/aWRZR0/U+PpMkf0dphTe0seDSsDe4Uxvn1HB7pJWHLAoS833cNCh XP/idY50QYT+AeqcZVwhpVy/YYHgnssdz49inZg84bHeabVIZo5NA0DbGCQHQg== ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1724567771; a=rsa-sha256; cv=none; b=uecgv4a7+vDuVuYh8Kk2/KPO5Qp+yonxT2kle9obX/FFd0BQwPe6Z7e3D0wAG3kHvPkLJS DhxKgBqnRDYsgsPKKPIGCbbqvFjD0Z1YTaFlbWbumpbYrzxZsXNuuhHzH4jdG0DU5Dl/FP SjVlZPuX/Sb+Ryha1NKKsCayri79/kuQLLLN7HZO30eVAwFG53MX8ZW7cFTONpY6oBBSWa l6tqyxFDZyVv8BcBGtgPRb6eNFVd9jSwOffJ0c+D9Y8u590FQLNH1tkfjrNMVlC67T0m0v qENdV0gwE8JprBN1yeJDihMyqy1MUKuNax5DXvP9zeiHfbMCGzqCcsU4UX5laQ== 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=1724567771; 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=6oMDf7gs8JnUiXxJ5Br6RakATYsMX+GMzfTmA2XOEuU=; b=S7R9fcOzFbvw6QGtLh+Nq02uLUXSI5GYGmBaB5312N3oLamXI2r/oOIiNHUDjMS0OipAVl HUIHDv3KOcsWzfrzq8MOqwm14bDOl7jr/o/9IeABHx/ktt4mVpwboIfHHqYd/OxPs++zok F+ZwjCElzPGdAiGx6nOPJNL0Trp/kt2575DdYt9YpqJxQlZczu92He12W5+PS3XdaMGBS1 YDqIQ/WCAbKvYX0lmCSiNit6Y069MHAkCHHL2JKkzCITQfNAkRBI4qjniPwmSSKkGpIdyG 4wYhXJzD0pxHX2c76uvRk2hHScSeN/YgWtUBiDdaOWZuM7Z0q1/IgJ6cna7/UA== 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 4Ws3wq5MlDz1R6j; Sun, 25 Aug 2024 06:36:11 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from gitrepo.freebsd.org ([127.0.1.44]) by gitrepo.freebsd.org (8.18.1/8.18.1) with ESMTP id 47P6aBhX026740; Sun, 25 Aug 2024 06:36:11 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.18.1/8.18.1/Submit) id 47P6aBvO026737; Sun, 25 Aug 2024 06:36:11 GMT (envelope-from git) Date: Sun, 25 Aug 2024 06:36:11 GMT Message-Id: <202408250636.47P6aBvO026737@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-branches@FreeBSD.org From: Eugene Grosbein Subject: git: 244118026550 - stable/14 - libalias: fix subtle racy problem in outside-inside forwarding 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: eugen X-Git-Repository: src X-Git-Refname: refs/heads/stable/14 X-Git-Reftype: branch X-Git-Commit: 2441180265509a7efe8c20ee72585757e7bb9d1c Auto-Submitted: auto-generated The branch stable/14 has been updated by eugen: URL: https://cgit.FreeBSD.org/src/commit/?id=2441180265509a7efe8c20ee72585757e7bb9d1c commit 2441180265509a7efe8c20ee72585757e7bb9d1c Author: Eugene Grosbein AuthorDate: 2024-08-19 03:34:37 +0000 Commit: Eugene Grosbein CommitDate: 2024-08-25 06:31:24 +0000 libalias: fix subtle racy problem in outside-inside forwarding sys/netinet/libalias/alias_db.c has internal static function UseLink() that passes a link to CleanupLink() to verify if the link has expired. If so, UseLink() may return NULL. _FindLinkIn()'s usage of UseLink() is not quite correct. Assume there is "redirect_port udp" configured to forward incoming traffic for specific port to some internal address. Such a rule creates partially specified permanent link. After first such incoming packet libalias creates new fully specifiled temporary LINK_UDP with default timeout of 60 seconds. Also, in case of low traffic libalias may assign "timestamp" for this new temporary link way in the past because LibAliasTime is updated seldom and can keep old value for tens of seconds, and it will be used for the temporary link. It may happen that next incoming packet for redirected port passed to _FindLinkIn() results in a call to UseLink() that returns NULL due to detected expiration. Immediate return of NULL results in broken translation: either a packet is dropped (deny_incoming mode) or delivered to original destination address instead of internal one. Fix it with additional check for NULL to proceed with a search for original partially specified link. In case of UDP, it also recreates temporary fully specified link with a call to ReLink(). Practical examples are "redirect_port udp" rules for unidirectional SYSLOG protocol (port 514) or some low volume VPN encapsulated in UDP. Thanks to Peter Much for initial analysis and first version of a patch. Reported by: Peter Much PR: 269770 (cherry picked from commit 8132e959099f0c533f698d8fbc17386f9144432f) (cherry picked from commit e5b85380836378c9e321a4e6d300591e6faf622a) --- sys/netinet/libalias/alias_db.c | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/sys/netinet/libalias/alias_db.c b/sys/netinet/libalias/alias_db.c index 167201fa1b8f..4bb95549aaaf 100644 --- a/sys/netinet/libalias/alias_db.c +++ b/sys/netinet/libalias/alias_db.c @@ -868,8 +868,18 @@ _FindLinkIn(struct libalias *la, struct in_addr dst_addr, case 0: LIST_FOREACH(lnk, &grp->full, all.in) { if (lnk->dst_addr.s_addr == dst_addr.s_addr && - lnk->dst_port == dst_port) - return (UseLink(la, lnk)); + lnk->dst_port == dst_port) { + struct alias_link *found; + + found = UseLink(la, lnk); + if (found != NULL) + return (found); + /* link expired */ + grp = StartPointIn(la, alias_addr, alias_port, link_type, 0); + if (grp == NULL) + return (NULL); + break; + } } break; case LINK_UNKNOWN_DEST_PORT: