From nobody Fri Jan 13 10:16:05 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 4Ntcks6NVFz2p2s9; Fri, 13 Jan 2023 10:16:05 +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 4Ntcks5J3lz3jlb; Fri, 13 Jan 2023 10:16:05 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1673604965; 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=bavUgb76cU9HVeQBGyV7/5Pki7aNOshVLMLxNdEmwS0=; b=XI6fGXrXE61qt/697KVELtVPFDxwyOy4Lbt3pn/dA4hhXxfML3XMkQsNImxADC8tQtJn89 1cs1F4DmSpRhebps1azlsJqQ8JAnJCJ+iWuKMHyj/b+SaeggZg8lqkR12kG/cROEDZKy+5 tRPIKWxmT0GTx+8Jy9mxjwtP0XwOwXKaacWmpJnffFhU8DNirWbqP6GtBHk1mLdmLe6JQI QdHk47UhH+y3oS3YPRSgG+n9DBQzEuxoXLBxwcMHVghIg08dZK/G6doq5taKBhBTM5ErtG nMdEgjgLB2wjtj/1vPGKCQsa2SLmpsp7DnwpoCtdMPBes/Q8tU+aT3kiGmcEZA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1673604965; 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=bavUgb76cU9HVeQBGyV7/5Pki7aNOshVLMLxNdEmwS0=; b=oRDnLSlUva40WZTe5m71yl4iV0/bxmvPzicCMQVFaYHj+ZU7OvdNa1GKUPjNQiAJi09MeK x6IEsPiMU/eGzXd2tO4/NscyxaT98mE6gDnp/qhqWGjIZbr0nwHmhlN/CqsnuVyIuZtF2U ooq/ZgHV+edl46BMzcxyBP6BQZ7QI2c355fYRrP7p/eJ532FbvL5wpnEOmH6c5THZjIWm/ iSEdbFt+uLy6baqYrPqXShWuaPBh+KZkoHbpOiXuA07VXqESdoWcaoig/Ix28JbuANObHy 9hzmn1YVOIRKmRLAR7CDizcJUT4E5QYth4G+UzQhQuvbdivKOVGajcTrA6PBSw== ARC-Authentication-Results: i=1; mx1.freebsd.org; none ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1673604965; a=rsa-sha256; cv=none; b=PlJzYQT66KfJWvv3UrdAJ0wQIMe81IZmhQJ1Qj2nLqbgT8FuOCSnP1Gue78DIlAth1y/9c g7HLJTsoBzm9bNyw2c6uRrz3PrFG1IUDA99tU6aWsW+UUfyHx2ZUvapEDKTGkm3ExCz8gu MwKfqY/u6cLj5wT5EmE2bsl6lCnrcADy2aNUyqrJMpvLHu2k4nvk/fpa90HIaIFO9muiAQ fCU7zR78Hx7n3D4i6uy/mcnmFJQiq5lSRyNIkuLRrXwULbuPyyKRe2V1LEFb9/E4B5R97+ NJWvDamf4x6JdfAxThTsZ//m49uCW6mEaLrQCjOBI0XOmYup7rGhx1a7M05Oug== 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 4Ntcks4D4rz13bV; Fri, 13 Jan 2023 10:16:05 +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 30DAG5Yb081338; Fri, 13 Jan 2023 10:16:05 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.16.1/8.16.1/Submit) id 30DAG5Wp081337; Fri, 13 Jan 2023 10:16:05 GMT (envelope-from git) Date: Fri, 13 Jan 2023 10:16:05 GMT Message-Id: <202301131016.30DAG5Wp081337@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-main@FreeBSD.org From: Kristof Provost Subject: git: dc698b2cd59e - main - 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/main X-Git-Reftype: branch X-Git-Commit: dc698b2cd59ebc08b05a261dbba8ee5707450d28 Auto-Submitted: auto-generated X-ThisMailContainsUnwantedMimeParts: N The branch main has been updated by kp: URL: https://cgit.FreeBSD.org/src/commit/?id=dc698b2cd59ebc08b05a261dbba8ee5707450d28 commit dc698b2cd59ebc08b05a261dbba8ee5707450d28 Author: Kristof Provost AuthorDate: 2022-12-31 18:23:15 +0000 Commit: Kristof Provost CommitDate: 2023-01-13 22:14:17 +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 --- 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 9ef20fad4554..6d0991393fe1 100644 --- a/tests/sys/netpfil/pf/syncookie.sh +++ b/tests/sys/netpfil/pf/syncookie.sh @@ -279,6 +279,62 @@ limits_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" @@ -286,4 +342,5 @@ atf_init_test_cases() atf_add_test_case "nostate" atf_add_test_case "adaptive" atf_add_test_case "limits" + atf_add_test_case "port_reuse" }