From nobody Sat Jan 28 01:39:22 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 4P3cYl0Xhxz3bpvq; Sat, 28 Jan 2023 01:39:23 +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 4P3cYk6m6Pz3nK3; Sat, 28 Jan 2023 01:39:22 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1674869962; 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=pJfDXftZ+HKuBTzye8eyXDwYN5NDMIlPp9FzhdfcH2M=; b=CvnqBR/WivcRPsfcEu7U5QBagVzVFiNB3Fd6YMe1qjANj1nmxVDqXuYa0oz3OtLd+QOT7n 2mvypVQGplHJd5071urcdNNa7w2qPBZCMRpakMVGnGZ9sNhVs1jXuu2jwwsxV2PYiodi2V fGSGxuSJom+uxKOgWzAeQGUx3ERBP+BbCTx5GDDP8Z0dlkAJM7TDeRNnAlTCuxX35qc/KB u9Q+x1lz5m0m12QrH/3Qa58/OvW+IOSvLWmCS+HT0GwQt+7Bk7KCf/A0+HVHkr/2YSpiJZ m3RclVR/tgNgbpV/ptlYfkUyT60/Dcx0okAJAC1KllAT7VjFHj7cDZqL8JWQ9Q== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1674869962; 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=pJfDXftZ+HKuBTzye8eyXDwYN5NDMIlPp9FzhdfcH2M=; b=SG2qvy/8kWAku3Ko6Tx4LINeMSGINjCWoP/BIp9Qd6J7HhxaRrb8oNq2BIUzs0iZdoe4qC GzA+YXflJhlMHbm+BGKhWAjy/sXaqSXvapRKNGrYxyTamjhWloK5lts2+HZmQEwnKz5l+N /T1WFq38kSWLtzfS82nl9sM/kMtAOzt3pacO3XHHWT3t7ju23j1Q+6HPdxxp9hViWgchFY Ydq1PbxN2dmC0aUE0194fz2gzD1ARIki5mJSpYLghkXbW0oZS7aYA96ITi2yxF880KzZJI 6FcgQ4ft36StjUhb8ulguLMTHpTS+SrdxFtHpGvgXh2HBFbNwattLeV0dKzTEA== ARC-Authentication-Results: i=1; mx1.freebsd.org; none ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1674869962; a=rsa-sha256; cv=none; b=tUgkOMxVGkebmQmudvDv1WwtNS3q7dTS740hUDInJULR7Tj63ND2jz0TLsMCYhsERTI9Zs gorYSlau8MY7l4emTx44FQL/rf7sQEVEgiedlu/Pa6jIIg0+GAh2ab/V3zAZNlfQAXlE8h +CMKDheXGQXPt/aSFtbGGA1R96OlyLyK7Q0it2BpLvgoV2ijhw2yEAY5rUAAO80lSygtEn CUxe+g+4RphYIYtSe6FKrazkYT9GW7XG1YKXzRRvglaS6rKh7/L4X+8kv7KDnS5JdpVK/+ TKr2agCqOa2MvO7u/VjEcASEDobLoIiVCxtS+QSCPYGBHG2Gs83JO/G4SVyrTg== 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 4P3cYk5snqzWDg; Sat, 28 Jan 2023 01:39:22 +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 30S1dM4b056102; Sat, 28 Jan 2023 01:39:22 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.16.1/8.16.1/Submit) id 30S1dMKc056098; Sat, 28 Jan 2023 01:39:22 GMT (envelope-from git) Date: Sat, 28 Jan 2023 01:39:22 GMT Message-Id: <202301280139.30S1dMKc056098@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-branches@FreeBSD.org From: Kristof Provost Subject: git: 1279c260c053 - stable/12 - pf tests: test fast port re-use with syncookies 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: kp X-Git-Repository: src X-Git-Refname: refs/heads/stable/12 X-Git-Reftype: branch X-Git-Commit: 1279c260c05320854cddead34a52dfcea34576ea Auto-Submitted: auto-generated X-ThisMailContainsUnwantedMimeParts: N The branch stable/12 has been updated by kp: URL: https://cgit.FreeBSD.org/src/commit/?id=1279c260c05320854cddead34a52dfcea34576ea commit 1279c260c05320854cddead34a52dfcea34576ea Author: Kristof Provost AuthorDate: 2022-12-31 18:23:15 +0000 Commit: Kristof Provost CommitDate: 2023-01-27 09:50:40 +0000 pf tests: test fast port re-use with syncookies When a src/dst ip/port tuple is re-used before the pf state fully expires we clean up the state and create a new one, unless syncookies are enabled. Test this, by running two back-to-back nc sessions, with a fixed source port. Move the interface and IP to a different (vnet) jail, to trick the network stack into letting us do this. MFC after: 2 weeks Event: Aberdeen hackathon 2022 Differential Revision: https://reviews.freebsd.org/D36886 (cherry picked from commit dc698b2cd59ebc08b05a261dbba8ee5707450d28) --- tests/sys/netpfil/pf/syncookie.sh | 57 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 57 insertions(+) diff --git a/tests/sys/netpfil/pf/syncookie.sh b/tests/sys/netpfil/pf/syncookie.sh index d85beac1a4d1..dbb6407e9c38 100644 --- a/tests/sys/netpfil/pf/syncookie.sh +++ b/tests/sys/netpfil/pf/syncookie.sh @@ -217,10 +217,67 @@ adaptive_cleanup() pft_cleanup } +atf_test_case "port_reuse" "cleanup" +port_reuse_head() +{ + atf_set descr 'Test rapid port re-use' + atf_set require.user root +} + +port_reuse_body() +{ + pft_init + + epair=$(vnet_mkepair) + + vnet_mkjail alcatraz ${epair}b + vnet_mkjail singsing + jexec alcatraz ifconfig ${epair}b 192.0.2.1/24 up + jexec alcatraz /usr/sbin/inetd -p ${HOME}/inetd-alcatraz.pid \ + $(atf_get_srcdir)/echo_inetd.conf + + ifconfig ${epair}a 192.0.2.2/24 up + + jexec alcatraz pfctl -e + jexec alcatraz pfctl -x loud + pft_set_rules alcatraz \ + "set syncookies always" \ + "pass in" \ + "pass out" + + # Sanity check + atf_check -s exit:0 -o ignore ping -c 1 192.0.2.1 + + reply=$(echo foo | nc -p 1234 -N -w 5 192.0.2.1 7) + if [ "${reply}" != "foo" ]; + then + atf_fail "Failed to connect to syncookie protected echo daemon" + fi + + # We can't re-use the source IP/port combo quickly enough, so we're + # going to play a really dirty trick, and move our interface to a new + # jail, and do it from there. + ifconfig ${epair}a vnet singsing + jexec singsing ifconfig ${epair}a 192.0.2.2/24 up + atf_check -s exit:0 -o ignore jexec singsing ping -c 1 192.0.2.1 + + reply=$(echo bar | jexec singsing nc -p 1234 -N -w 5 192.0.2.1 7) + if [ "${reply}" != "bar" ]; + then + atf_fail "Failed to connect to syncookie protected echo daemon (2)" + fi +} + +port_reuse_cleanup() +{ + pft_cleanup +} + atf_init_test_cases() { atf_add_test_case "basic" atf_add_test_case "forward" atf_add_test_case "nostate" atf_add_test_case "adaptive" + atf_add_test_case "port_reuse" }