git: a009793a5e5f - stable/14 - pf: handle divert packets
- Go to: [ bottom of page ] [ top of archives ] [ this month ]
Date: Sun, 30 Nov 2025 10:30:53 UTC
The branch stable/14 has been updated by kp:
URL: https://cgit.FreeBSD.org/src/commit/?id=a009793a5e5fad0b42cb0a158dcbccd5eff40d9f
commit a009793a5e5fad0b42cb0a158dcbccd5eff40d9f
Author: Kristof Provost <kp@FreeBSD.org>
AuthorDate: 2025-11-15 13:44:54 +0000
Commit: Kristof Provost <kp@FreeBSD.org>
CommitDate: 2025-11-30 10:26:28 +0000
pf: handle divert packets
In a divert setup pf_test_state() may return PF_PASS, but not set the state
pointer. We didn't handle that, and as a result crashed immediately afterwards
trying to dereference that NULL state pointer.
Add a test case to provoke the problem.
PR: 260867
MFC after: 2 weeks
Submitted by: Phil Budne <phil.budne@gmail.com>
Sponsored by: Rubicon Communications, LLC ("Netgate")
(cherry picked from commit 66f2f1c83247f05a3a599d7e88c7e7efbedd16b5)
---
sys/netpfil/pf/pf.c | 20 +++++++++++-------
tests/sys/netpfil/pf/divert-to.sh | 44 +++++++++++++++++++++++++++++++++++++--
2 files changed, 54 insertions(+), 10 deletions(-)
diff --git a/sys/netpfil/pf/pf.c b/sys/netpfil/pf/pf.c
index f067c2b6bdf4..44d72d228104 100644
--- a/sys/netpfil/pf/pf.c
+++ b/sys/netpfil/pf/pf.c
@@ -8558,10 +8558,12 @@ pf_test(int dir, int pflags, struct ifnet *ifp, struct mbuf **m0,
goto done;
action = pf_test_state_tcp(&s, kif, m, off, h, &pd, &reason);
if (action == PF_PASS) {
- if (V_pfsync_update_state_ptr != NULL)
- V_pfsync_update_state_ptr(s);
- r = s->rule.ptr;
- a = s->anchor.ptr;
+ if (s != NULL) {
+ if (V_pfsync_update_state_ptr != NULL)
+ V_pfsync_update_state_ptr(s);
+ r = s->rule.ptr;
+ a = s->anchor.ptr;
+ }
} else if (s == NULL) {
/* Validate remote SYN|ACK, re-create original SYN if
* valid. */
@@ -8621,10 +8623,12 @@ pf_test(int dir, int pflags, struct ifnet *ifp, struct mbuf **m0,
}
action = pf_test_state_udp(&s, kif, m, off, h, &pd);
if (action == PF_PASS) {
- if (V_pfsync_update_state_ptr != NULL)
- V_pfsync_update_state_ptr(s);
- r = s->rule.ptr;
- a = s->anchor.ptr;
+ if (s != NULL) {
+ if (V_pfsync_update_state_ptr != NULL)
+ V_pfsync_update_state_ptr(s);
+ r = s->rule.ptr;
+ a = s->anchor.ptr;
+ }
} else if (s == NULL)
action = pf_test_rule(&r, &s, kif, m, off, &pd,
&a, &ruleset, inp);
diff --git a/tests/sys/netpfil/pf/divert-to.sh b/tests/sys/netpfil/pf/divert-to.sh
index 965464b35810..8c76ffd35bfe 100644
--- a/tests/sys/netpfil/pf/divert-to.sh
+++ b/tests/sys/netpfil/pf/divert-to.sh
@@ -509,6 +509,47 @@ ipfwon_in_dn_in_div_in_out_dn_out_div_out_cleanup()
pft_cleanup
}
+atf_test_case "pr260867" "cleanup"
+pr260867_head()
+{
+ atf_set descr 'Test for the loop reported in PR260867'
+ atf_set require.user root
+}
+
+pr260867_body()
+{
+ pft_init
+ divert_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
+
+ # Sanity check
+ atf_check -s exit:0 -o ignore ping -c3 192.0.2.2
+
+ jexec alcatraz /usr/sbin/inetd -p ${PWD}/inetd-echo.pid $(atf_get_srcdir)/echo_inetd.conf
+ jexec alcatraz $(atf_get_srcdir)/../common/divapp 1001 divert-back &
+
+ jexec alcatraz pfctl -e
+ pft_set_rules alcatraz \
+ "pass in on ${epair}b proto tcp from any to port 7 divert-to 0.0.0.0 port 1001"
+
+ reply=$(echo "foo" | nc -N 192.0.2.2 7)
+ if ["${reply}" != "foo" ];
+ then
+ atf_fail "Did not receive echo reply"
+ fi
+}
+
+pr260867_cleanup()
+{
+ pft_cleanup
+}
+
atf_init_test_cases()
{
atf_add_test_case "ipfwoff_in_div"
@@ -524,6 +565,5 @@ atf_init_test_cases()
atf_add_test_case "ipfwoff_in_div_in_fwd_out_div_out"
atf_add_test_case "ipfwon_in_div_in_fwd_out_div_out"
- atf_add_test_case "ipfwoff_in_dn_in_div_in_out_dn_out_div_out"
- atf_add_test_case "ipfwon_in_dn_in_div_in_out_dn_out_div_out"
+ atf_add_test_case "pr260867"
}