From nobody Wed Sep 11 11:18:28 2024 X-Original-To: dev-commits-src-main@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 4X3dNj3dzFz5WRkT; Wed, 11 Sep 2024 11:18:29 +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 4X3dNh6w0Lz4XqL; Wed, 11 Sep 2024 11:18:28 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1726053509; 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=R3SdlxiDBt7A+BOvLU7b/tZIBIe0cgGqNWYLmiz5BJI=; b=vQmFIRuI4ALM2+B04ubsva0P1GHeWD6EAphKiL6z6Mo9zvCZwCX2zCuIv01HH2KS48AbUA Obb4a1ezeDqcro1JNKOgDIyLe0DtWth967x1WRFvr+RUVLE0H2kyTllY8H+Dba7fw182nY asEbl/CMB/UTiCuEa1E6TdqZNj7HJTrCmun7YtFTM+YYNwIvdTdGFkWDeMBXI2c03yvK3n v5XpfyqD+kdz8IyI0eEb5I0bww9MOn5xh+7Qgfu4ZNaral5nUfMSy6WT6eiFEmHUYmWMna KNe4Pc0PNbGzAtLSqJiub0cxdu0I8zT/I3VI/lHYCi5QjXZbdwsji0noGAmSjg== ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1726053509; a=rsa-sha256; cv=none; b=xC47UHHhuSmab7EyO1I4ZjItHl8jwnogvff7hNTrG8S7+shecXVZ8azY7inxmG7qI4KFaz m0D6j7c4L0ykrqS7u7uPpTnEu9gibtKK+xPY91CnvAR/BfanaXm6piw+nZ7sKCPAdPya5H wwf8xbJeEq3Y1tg6oqJkb176p6Pcu/AIouZ/uE/d9hXe/m7npydOMdkQkPeJdqkCQA904t 5Rk6Aje4QXb+Stiv1e6+F6opoAUppgZZyeqBYp3ChpcjFhL4J4Mcq8lU4sdBEHrk/7Syza 2N+s7pv3OJK+PKJYj4fDcQqQuWxKsUsPpVVpf02ScINQr21e6Cf6B2K/8nsUmw== 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=1726053509; 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=R3SdlxiDBt7A+BOvLU7b/tZIBIe0cgGqNWYLmiz5BJI=; b=kFAHoEgrC4KzdOlurPM+t960Z66OGgfa1NExK0aZtRLdQurpWZFEKEqsSExfb87JtKg+2S AdFJt1k6P1Dsx7noPQktsl+ojC/bQHl2ohMb+esXJ6Ekt2lh+DWzf6skf4y9/w7rEmHyDo KTqRcSluI/LgBlIf/VqlfTqOaLXqbRHyM0qqFlgivSHN+iiq1I7HZQWvA3jl5ENCLc6Ftb niDvDgzoQdVa7g5sbhkXfLUJ6fFSnaFaXo9OZPFEWY82bg6T8mx22U/c0ynFvd6L7rNyEu a6Mo8O5oOA3G0NEjiIBfPAxmL/JGQS0mEd3jRqz/NZ5b5EQRYxL08AENiREl3A== 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 4X3dNh6XGjzSvd; Wed, 11 Sep 2024 11:18:28 +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 48BBISkG065184; Wed, 11 Sep 2024 11:18:28 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.18.1/8.18.1/Submit) id 48BBISqf065181; Wed, 11 Sep 2024 11:18:28 GMT (envelope-from git) Date: Wed, 11 Sep 2024 11:18:28 GMT Message-Id: <202409111118.48BBISqf065181@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: b27d3f71c2ad - main - pf tests: improved test for CVE-2019-5598 List-Id: Commit messages for the main branch of the src repository List-Archive: https://lists.freebsd.org/archives/dev-commits-src-main List-Help: List-Post: List-Subscribe: List-Unsubscribe: X-BeenThere: dev-commits-src-main@freebsd.org Sender: owner-dev-commits-src-main@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: b27d3f71c2ad05e1b18e8bdce75194330e0925e4 Auto-Submitted: auto-generated The branch main has been updated by kp: URL: https://cgit.FreeBSD.org/src/commit/?id=b27d3f71c2ad05e1b18e8bdce75194330e0925e4 commit b27d3f71c2ad05e1b18e8bdce75194330e0925e4 Author: Kristof Provost AuthorDate: 2024-08-28 08:03:42 +0000 Commit: Kristof Provost CommitDate: 2024-09-11 11:17:49 +0000 pf tests: improved test for CVE-2019-5598 Ensure that we verify that the inner and outer IP address matches for ICMP error messages. This is a more detailed test for CVE-2019-5598, which was fixed back in 2019. Sponsored by: Rubicon Communications, LLC ("Netgate") Differential Revision: https://reviews.freebsd.org/D46573 --- tests/sys/netpfil/pf/Makefile | 1 + tests/sys/netpfil/pf/icmp.py | 126 ++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 127 insertions(+) diff --git a/tests/sys/netpfil/pf/Makefile b/tests/sys/netpfil/pf/Makefile index 2b3cb9fbd858..8444c92fb8d5 100644 --- a/tests/sys/netpfil/pf/Makefile +++ b/tests/sys/netpfil/pf/Makefile @@ -53,6 +53,7 @@ ATF_TESTS_SH+= altq \ tos ATF_TESTS_PYTEST+= frag6.py +ATF_TESTS_PYTEST+= icmp.py ATF_TESTS_PYTEST+= nat66.py ATF_TESTS_PYTEST+= sctp.py diff --git a/tests/sys/netpfil/pf/icmp.py b/tests/sys/netpfil/pf/icmp.py new file mode 100644 index 000000000000..cb9de2bf0f36 --- /dev/null +++ b/tests/sys/netpfil/pf/icmp.py @@ -0,0 +1,126 @@ +# +# SPDX-License-Identifier: BSD-2-Clause +# +# Copyright (c) 2024 Rubicon Communications, LLC (Netgate) +# +# Redistribution and use in source and binary forms, with or without +# modification, are permitted provided that the following conditions +# are met: +# 1. Redistributions of source code must retain the above copyright +# notice, this list of conditions and the following disclaimer. +# 2. Redistributions in binary form must reproduce the above copyright +# notice, this list of conditions and the following disclaimer in the +# documentation and/or other materials provided with the distribution. +# +# THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND +# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE +# ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE +# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL +# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS +# OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) +# HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT +# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY +# OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF +# SUCH DAMAGE. + +import pytest +import subprocess +import re +from atf_python.sys.net.tools import ToolsHelper +from atf_python.sys.net.vnet import VnetTestTemplate + +def check(cmd): + ps = subprocess.Popen(cmd, shell=True) + ret = ps.wait() + if ret != 0: + raise Exception("Command %s returned %d" % (cmd, ret)) + +class TestICMP(VnetTestTemplate): + REQUIRED_MODULES = [ "pf" ] + TOPOLOGY = { + "vnet1": {"ifaces": ["if1"]}, + "vnet2": {"ifaces": ["if1", "if2"]}, + "vnet3": {"ifaces": ["if2"]}, + "if1": {"prefixes4": [("192.0.2.2/24", "192.0.2.1/24")]}, + "if2": {"prefixes4": [("198.51.100.1/24", "198.51.100.2/24")]}, + } + + def vnet2_handler(self, vnet): + ifname = vnet.iface_alias_map["if1"].name + + ToolsHelper.print_output("/sbin/pfctl -e") + ToolsHelper.pf_rules([ + "set reassemble yes", + "block", + "pass inet proto icmp icmp-type echoreq", + ]) + + ToolsHelper.print_output("/sbin/sysctl net.inet.ip.forwarding=1") + ToolsHelper.print_output("/sbin/pfctl -x loud") + + def vnet3_handler(self, vnet): + # Import in the correct vnet, so at to not confuse Scapy + import scapy.all as sp + + ifname = vnet.iface_alias_map["if2"].name + ToolsHelper.print_output("/sbin/route add default 198.51.100.1") + ToolsHelper.print_output("/sbin/ifconfig %s inet alias 198.51.100.3/24" % ifname) + + def checkfn(packet): + icmp = packet.getlayer(sp.ICMP) + if not icmp: + return False + + if icmp.type != 3: + return False + + packet.show() + return True + + sp.sniff(iface=ifname, stop_filter=checkfn) + vnet.pipe.send("Got ICMP destination unreachable packet") + + @pytest.mark.require_user("root") + def test_inner_match(self): + vnet = self.vnet_map["vnet1"] + dst_vnet = self.vnet_map["vnet3"] + sendif = vnet.iface_alias_map["if1"].name + + our_mac = ToolsHelper.get_output("/sbin/ifconfig %s ether | awk '/ether/ { print $2; }'" % sendif) + dst_mac = re.sub("0a$", "0b", our_mac) + + # Import in the correct vnet, so at to not confuse Scapy + import scapy.all as sp + + ToolsHelper.print_output("/sbin/route add default 192.0.2.1") + + # Sanity check + check("/sbin/ping -c 1 192.0.2.1") + check("/sbin/ping -c 1 198.51.100.1") + check("/sbin/ping -c 2 198.51.100.3") + + # Establish a state + pkt = sp.Ether(src=our_mac, dst=dst_mac) \ + / sp.IP(src="192.0.2.2", dst="198.51.100.2") \ + / sp.ICMP(type='echo-request') \ + / "PAYLOAD" + sp.sendp(pkt, sendif, verbose=False) + + # Now try to pass an ICMP error message piggy-backing on that state, but + # use a different source address + pkt = sp.Ether(src=our_mac, dst=dst_mac) \ + / sp.IP(src="192.0.2.2", dst="198.51.100.3") \ + / sp.ICMP(type='dest-unreach') \ + / sp.IP(src="198.51.100.2", dst="192.0.2.2") \ + / sp.ICMP(type='echo-reply') + sp.sendp(pkt, sendif, verbose=False) + + try: + rcvd = self.wait_object(dst_vnet.pipe, timeout=1) + if rcvd: + raise Exception(rcvd) + except TimeoutError as e: + # We expect the timeout here. It means we didn't get the destination + # unreachable packet in vnet3 + pass