aboutsummaryrefslogtreecommitdiff
path: root/sys/netpfil/pf/pf.c
diff options
context:
space:
mode:
authorKristof Provost <kp@FreeBSD.org>2021-09-03 07:36:19 +0000
committerKristof Provost <kp@FreeBSD.org>2021-09-03 07:36:19 +0000
commita0c64a443e4cae67a5eea3a61a47d746866de3ee (patch)
treec1145e5ea573a66c55153135c4fc06f54e8f265b /sys/netpfil/pf/pf.c
parent71611b0c688568d513c665e1af3d95fcd50605fa (diff)
downloadsrc-a0c64a443e4cae67a5eea3a61a47d746866de3ee.tar.gz
src-a0c64a443e4cae67a5eea3a61a47d746866de3ee.zip
pf: ensure states passed to pf_free_state() are always unlinked
In pf_create_state() we can end up deleting the state immediately. This can happen if we fail to map the relevant addresses or fail normalization or fail to insert it into the state table. If that happens we delete the state again with pf_free_state(). However, this asserts that the state must be unlinked. It's correct to simply set the state to PFTM_UNLINKED because we've not yet linked it. Submitted by: Mateusz Guzik <mjg@FreeBSD.org> Reviewed by: scottl MFC after: 1 week Sponsored by: Rubicon Communications, LLC ("Netgate") Differential Revision: https://reviews.freebsd.org/D31752
Diffstat (limited to 'sys/netpfil/pf/pf.c')
-rw-r--r--sys/netpfil/pf/pf.c4
1 files changed, 4 insertions, 0 deletions
diff --git a/sys/netpfil/pf/pf.c b/sys/netpfil/pf/pf.c
index c4b29249ca6a..8a81aeb1c010 100644
--- a/sys/netpfil/pf/pf.c
+++ b/sys/netpfil/pf/pf.c
@@ -3980,6 +3980,7 @@ pf_create_state(struct pf_krule *r, struct pf_krule *nr, struct pf_krule *a,
if (pf_map_addr(pd->af, r, pd->src, &s->rt_addr, NULL, &sn)) {
REASON_SET(&reason, PFRES_MAPFAILED);
pf_src_tree_remove_state(s);
+ s->timeout = PFTM_UNLINKED;
STATE_DEC_COUNTERS(s);
pf_free_state(s);
goto csfailed;
@@ -4002,6 +4003,7 @@ pf_create_state(struct pf_krule *r, struct pf_krule *nr, struct pf_krule *a,
off, pd, th, &s->src, &s->dst)) {
REASON_SET(&reason, PFRES_MEMORY);
pf_src_tree_remove_state(s);
+ s->timeout = PFTM_UNLINKED;
STATE_DEC_COUNTERS(s);
pf_free_state(s);
return (PF_DROP);
@@ -4014,6 +4016,7 @@ pf_create_state(struct pf_krule *r, struct pf_krule *nr, struct pf_krule *a,
("pf_normalize_tcp_stateful failed on first "
"pkt\n"));
pf_src_tree_remove_state(s);
+ s->timeout = PFTM_UNLINKED;
STATE_DEC_COUNTERS(s);
pf_free_state(s);
return (PF_DROP);
@@ -4041,6 +4044,7 @@ pf_create_state(struct pf_krule *r, struct pf_krule *nr, struct pf_krule *a,
(pd->dir == PF_IN) ? nk : sk, s)) {
REASON_SET(&reason, PFRES_STATEINS);
pf_src_tree_remove_state(s);
+ s->timeout = PFTM_UNLINKED;
STATE_DEC_COUNTERS(s);
pf_free_state(s);
return (PF_DROP);