Skip site navigation (1)Skip section navigation (2)
Date:      Fri, 5 Sep 2025 19:54:59 GMT
From:      Kristof Provost <kp@FreeBSD.org>
To:        src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-main@FreeBSD.org
Subject:   git: c23eda976a8a - main - pf: fix possible pd->pcksum NULL deref
Message-ID:  <202509051954.585JsxwK031691@gitrepo.freebsd.org>

next in thread | raw e-mail | index | archive | help
The branch main has been updated by kp:

URL: https://cgit.FreeBSD.org/src/commit/?id=c23eda976a8aad6bbd6c2042fa2ba1f0bc640e19

commit c23eda976a8aad6bbd6c2042fa2ba1f0bc640e19
Author:     Kristof Provost <kp@FreeBSD.org>
AuthorDate: 2025-09-02 13:14:49 +0000
Commit:     Kristof Provost <kp@FreeBSD.org>
CommitDate: 2025-09-05 19:54:12 +0000

    pf: fix possible pd->pcksum NULL deref
    
    Ensure that we always populate pcksum, not just for TCP/UDP/SCTP/ICMP.
    We may end up using it (through pf_change_ap()) if we're doing NAT, so
    ensure it's available even if it's sometimes just a dummy variable.
    
    Reported-by: syzbot+3e73a7cba8cb6cd46f90@syzkaller.appspotmail.com
    MFC after:      1 week
    Sponsored by:   Rubicon Communications, LLC ("Netgate")
---
 sys/netpfil/pf/pf.c           | 14 ++++++++
 tests/sys/netpfil/pf/Makefile |  1 +
 tests/sys/netpfil/pf/nat44.py | 76 +++++++++++++++++++++++++++++++++++++++++++
 3 files changed, 91 insertions(+)

diff --git a/sys/netpfil/pf/pf.c b/sys/netpfil/pf/pf.c
index 242152f17db0..3a047ea44c47 100644
--- a/sys/netpfil/pf/pf.c
+++ b/sys/netpfil/pf/pf.c
@@ -8854,6 +8854,11 @@ pf_test_state_icmp(struct pf_kstate **state, struct pf_pdesc *pd,
 		default: {
 			int	action;
 
+			/*
+			 * Placeholder value, so future calls to pf_change_ap()
+			 * don't try to update a NULL checksum pointer.
+			 */
+			pd->pcksum = &pd->sctp_dummy_sum;
 			key.af = pd2.af;
 			key.proto = pd2.proto;
 			pf_addrcpy(&key.addr[pd2.sidx], pd2.src, key.af);
@@ -10614,6 +10619,13 @@ pf_setup_pdesc(sa_family_t af, int dir, struct pf_pdesc *pd, struct mbuf **m0,
 		break;
 	}
 #endif /* INET6 */
+	default:
+		/*
+		 * Placeholder value, so future calls to pf_change_ap() don't
+		 * try to update a NULL checksum pointer.
+		*/
+		pd->pcksum = &pd->sctp_dummy_sum;
+		break;
 	}
 
 	if (pd->sport)
@@ -10621,6 +10633,8 @@ pf_setup_pdesc(sa_family_t af, int dir, struct pf_pdesc *pd, struct mbuf **m0,
 	if (pd->dport)
 		pd->odport = pd->ndport = *pd->dport;
 
+	MPASS(pd->pcksum != NULL);
+
 	return (0);
 }
 
diff --git a/tests/sys/netpfil/pf/Makefile b/tests/sys/netpfil/pf/Makefile
index 616ffe560b3a..9f993eec61d0 100644
--- a/tests/sys/netpfil/pf/Makefile
+++ b/tests/sys/netpfil/pf/Makefile
@@ -61,6 +61,7 @@ ATF_TESTS_PYTEST+=	header.py
 ATF_TESTS_PYTEST+=	icmp.py
 ATF_TESTS_PYTEST+=	igmp.py
 ATF_TESTS_PYTEST+=	mld.py
+ATF_TESTS_PYTEST+=	nat44.py
 ATF_TESTS_PYTEST+=	nat64.py
 ATF_TESTS_PYTEST+=	nat66.py
 ATF_TESTS_PYTEST+=	return.py
diff --git a/tests/sys/netpfil/pf/nat44.py b/tests/sys/netpfil/pf/nat44.py
new file mode 100644
index 000000000000..d69e794a62c3
--- /dev/null
+++ b/tests/sys/netpfil/pf/nat44.py
@@ -0,0 +1,76 @@
+#
+# SPDX-License-Identifier: BSD-2-Clause
+#
+# Copyright (c) 2025 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
+from atf_python.sys.net.tools import ToolsHelper
+from atf_python.sys.net.vnet import VnetTestTemplate
+
+class TestNAT44(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")]},
+    }
+
+    def vnet2_handler(self, vnet):
+        outifname = vnet.iface_alias_map["if2"].name
+        ToolsHelper.print_output("/sbin/sysctl net.inet.ip.forwarding=1")
+
+        ToolsHelper.print_output("/sbin/pfctl -e")
+        ToolsHelper.print_output("/sbin/pfctl -x loud")
+        ToolsHelper.pf_rules([
+            "set reassemble yes",
+            "nat on {} inet from 192.0.2.0/24 -> ({})".format(outifname, outifname),
+            "pass"])
+
+    def vnet3_handler(self, vnet):
+        pass
+
+    @pytest.mark.require_user("root")
+    @pytest.mark.require_progs(["scapy"])
+    def test_nat_igmp(self):
+        "Verify that NAT translation of !(TCP|UDP|SCTP|ICMP) doesn't panic"
+        ToolsHelper.print_output("/sbin/route add default 192.0.2.1")
+        ToolsHelper.print_output("ping -c 3 198.51.100.2")
+
+        # Import in the correct vnet, so at to not confuse Scapy
+        import scapy.all as sp
+        import scapy.contrib as sc
+        import scapy.contrib.igmp
+
+        pkt = sp.IP(dst="198.51.100.2", ttl=64) \
+            / sc.igmp.IGMP(type=0x11, mrcode=1)
+        sp.send(pkt)
+
+        # This time we'll hit an existing state
+        pkt = sp.IP(dst="198.51.100.2", ttl=64) \
+            / sc.igmp.IGMP(type=0x11, mrcode=1)
+        reply = sp.sr1(pkt, timeout=3)
+        if reply:
+            reply.show()



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?202509051954.585JsxwK031691>