HomeFreeBSD

pf: fix udp_mapping cleanup

Description

pf: fix udp_mapping cleanup

If we fail to obtain a new source port (pf_get_sport()) while we've
created a udp_mapping (for 'endpoint independent nat') we must free the
udp_mapping in pf_get_sport(). Otherwise the calling function will call
pf_udp_mapping_release(). This will then attempt to remove the udp_mapping from
a list it's not in, and crash.

Actually free the udp_mapping in all failure cases. While here sprinkle in a few
more assertions to ensure we don't forget leak udp_mappings and add a test case
to provoke this problem.

Reviewed by: thj
MFC after: 1 week
See also: https://redmine.pfsense.org/issues/16517
Sponsored by: Rubicon Communications, LLC ("Netgate")
Differential Revision: https://reviews.freebsd.org/D53737

(cherry picked from commit c12013f5bb3819e64499f02ecd199a635003c7ce)

Details

Provenance
kpAuthored on Nov 13 2025, 1:54 PM
Reviewer
thj
Differential Revision
D53737: pf: fix udp_mapping cleanup
Parents
rG7799b57146cd: if_ovpn: use IFT_TUNNEL
Branches
Unknown
Tags
Unknown