From nobody Tue Jun 28 08:43:43 2022 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 88E9086E2B7; Tue, 28 Jun 2022 08:43:44 +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 4LXJ680Pzlz4lfQ; Tue, 28 Jun 2022 08:43:43 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1656405824; 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=e11Xyk+KcPENPNVwl1CBBU972ACpZ/Ek7xXZjYlW+6s=; b=I94xJdGjStCrFTqQde9zyF9oySxouNoFtz5BabHmdK51g0zuMLgaOBBtePBqcO2BNrdZTg ZB3yZWUgs3HhojJzHASzEkW6g3Fk4FDfnA3tdhVyROOH72gY4CVPcK62EjEc83WZZRF1qH eEwrRDe+aimoaHx6KMrV379Ues5No+PW5y7xw6zBbVIH1iYVZ5TUZjOdkNoF6ttR4WkHbX 7eTpRQVL550qmSLVif0WOaC864p+65Wgu0cENeBWhKvxQRTeNhZGItefaEWG8p75Nlcy2x X8XGbZf5TrablL7tBc70KqSv0HhV/v3mD6VvGTA6WEqrAP18FTxQIQKs3i+CLQ== 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 604F719DA5; Tue, 28 Jun 2022 08:43:43 +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 25S8hhWq097876; Tue, 28 Jun 2022 08:43:43 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.16.1/8.16.1/Submit) id 25S8hhwp097875; Tue, 28 Jun 2022 08:43:43 GMT (envelope-from git) Date: Tue, 28 Jun 2022 08:43:43 GMT Message-Id: <202206280843.25S8hhwp097875@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: 07ffa50ba075 - main - pf tests: test short packets 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: Sender: owner-dev-commits-src-main@freebsd.org X-BeenThere: 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: 07ffa50ba075d450287e22385f110e3c319470e9 Auto-Submitted: auto-generated ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1656405824; 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=e11Xyk+KcPENPNVwl1CBBU972ACpZ/Ek7xXZjYlW+6s=; b=GkmnWg9BFb22OZIoWv+5QdqmygQcbBVKXmzlxQmwdTGEnUaMNT5BUQX1SESr3olz9ZDcxq n0MXaOKadL8wBMYb9COmciWqv9FgZWXzo3SdMo7zGnn9TDHQx0wwdbNiMkf42dUwDze+0k n/R9pYeSj/+L2jki6h+hjNhQrd/U1BATn1pErRLC/x5UCrxutWSc4PQKUKBiuiImBL++DO NwSPGgOHAZdsRuFBfIA2Q3An2x5oKj7sy74MoCT8S801WCZDWsghvsDY0M3wk3ymfoJWaR h0fHA9YU/Du+QBSKULj0bTmMDLaQuxMyRaGL9vcR80E00qGwYaJJUupkfy3mPQ== ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1656405824; a=rsa-sha256; cv=none; b=FoOfR8x2nnk+05D3r5F8SSMbA7NIW7/g5rraQ297/30j19B9i2Px9mRdKttTgI3l783hck 3jx4s278X6Ir0/BqfMzYMcdlGDH9qOspLdN4ZwBMtmXEvbqvFTwfwetdaSFlwaxfmsVups gYK3Zsll4tBjvumsdG0lWZk0EzHab5wjTNodEceAUOXQaMLr/u3pGLOb33HwjbsjHr016M DZ72/DCFVjdnJMW97bJnI/ih3+zZufIOuaRWxorwcZ+InGHUOksibulKex+cm57oZAitCb agXZgBF6FxAB3OfdKAh9uq+LH3hS5B6cMiodPkkPZdTh6iqESwEtrslvyWsSng== ARC-Authentication-Results: i=1; mx1.freebsd.org; none X-ThisMailContainsUnwantedMimeParts: N The branch main has been updated by kp: URL: https://cgit.FreeBSD.org/src/commit/?id=07ffa50ba075d450287e22385f110e3c319470e9 commit 07ffa50ba075d450287e22385f110e3c319470e9 Author: Kristof Provost AuthorDate: 2022-06-23 15:52:52 +0000 Commit: Kristof Provost CommitDate: 2022-06-28 08:31:23 +0000 pf tests: test short packets Test sending very short packets (i.e. too short for an IP header) packets in the Ethernet filtering code. Sponsored by: Rubicon Communications, LLC ("Netgate") --- tests/sys/netpfil/pf/Makefile | 2 ++ tests/sys/netpfil/pf/ether.sh | 46 +++++++++++++++++++++++++++ tests/sys/netpfil/pf/pft_ether.py | 67 +++++++++++++++++++++++++++++++++++++++ 3 files changed, 115 insertions(+) diff --git a/tests/sys/netpfil/pf/Makefile b/tests/sys/netpfil/pf/Makefile index 45eaec2f8ddc..83f0d94e952e 100644 --- a/tests/sys/netpfil/pf/Makefile +++ b/tests/sys/netpfil/pf/Makefile @@ -45,6 +45,7 @@ ${PACKAGE}FILES+= CVE-2019-5597.py \ frag-overlimit.py \ frag-overreplace.py \ pfsync_defer.py \ + pft_ether.py \ utils.subr ${PACKAGE}FILESMODE_CVE-2019-5597.py= 0555 @@ -54,5 +55,6 @@ ${PACKAGE}FILESMODE_frag-overindex.py= 0555 ${PACKAGE}FILESMODE_frag-overlimit.py= 0555 ${PACKAGE}FILESMODE_frag-overreplace.py= 0555 ${PACKAGE}FILESMODE_pfsync_defer.py= 0555 +${PACKAGE}FILESMODE_pft_ether.py= 0555 .include diff --git a/tests/sys/netpfil/pf/ether.sh b/tests/sys/netpfil/pf/ether.sh index 283267b98c54..549fbf22ab7b 100644 --- a/tests/sys/netpfil/pf/ether.sh +++ b/tests/sys/netpfil/pf/ether.sh @@ -634,6 +634,51 @@ match_tag_cleanup() pft_cleanup } +atf_test_case "short_pkt" "cleanup" +short_pkt_head() +{ + atf_set descr 'Test overly short Ethernet packets' + atf_set require.user root +} + +short_pkt_body() +{ + pft_init + + epair=$(vnet_mkepair) + ifconfig ${epair}a 192.0.2.1/24 up + + vnet_mkjail alcatraz ${epair}b + jexec alcatraz ifconfig ${epair}b 192.0.2.2/24 up + + jexec alcatraz pfctl -e + pft_set_rules alcatraz \ + "ether pass in" \ + "ether pass out" \ + "ether pass in l3 from 192.0.2.1" + + # Sanity check + atf_check -s exit:0 -o ignore ping -c 1 192.0.2.2 + + jexec alcatraz pfctl -se -v + + # Try sending ever shorter ping requests + # BPF won't let us send anything shorter than an Ethernet header, but + # that's good enough for this test + for i in `seq 46 14` + do + $(atf_get_srcdir)/pft_ether.py \ + --sendif ${epair}a \ + --to 192.0.2.2 \ + --len ${i} + done +} + +short_pkt_cleanup() +{ + pft_cleanup +} + atf_init_test_cases() { atf_add_test_case "mac" @@ -646,4 +691,5 @@ atf_init_test_cases() atf_add_test_case "ip" atf_add_test_case "tag" atf_add_test_case "match_tag" + atf_add_test_case "short_pkt" } diff --git a/tests/sys/netpfil/pf/pft_ether.py b/tests/sys/netpfil/pf/pft_ether.py new file mode 100644 index 000000000000..1892e0a8f95e --- /dev/null +++ b/tests/sys/netpfil/pf/pft_ether.py @@ -0,0 +1,67 @@ +#!/usr/bin/env python3 +# +# SPDX-License-Identifier: BSD-2-Clause +# +# Copyright © 2022. Rubicon Communications, LLC (Netgate). All Rights Reserved. +# +# 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 argparse +import logging +logging.getLogger("scapy").setLevel(logging.CRITICAL) +import scapy.all as sp +import socket +import sys + +PAYLOAD_MAGIC = bytes.fromhex('42c0ffee') + +def ping(send_if, dst_ip, length): + ether = sp.Ether() + ip = sp.IP(dst=dst_ip) + icmp = sp.ICMP(type='echo-request') + raw = sp.raw(PAYLOAD_MAGIC) + + req = ether / ip / icmp / raw + req = req.build()[0:length] + + sp.sendp(req, iface=send_if, verbose=False) + +def main(): + parser = argparse.ArgumentParser("pft_ether.py", + description="Ethernet test tool") + parser.add_argument('--sendif', nargs=1, + required=True, + help='The interface through which the packet(s) will be sent') + parser.add_argument('--to', nargs=1, + required=True, + help='The destination IP address for the ICMP echo request') + parser.add_argument('--len', nargs=1, + required=True, + help='The length of the packet') + + args = parser.parse_args() + + ping(args.sendif[0], args.to[0], int(args.len[0])) + +if __name__ == '__main__': + main()