nat44_cfg() only checked that the redirs of an IP_FW_NAT44_XCONFIG
request fit into it, not the spool (LSNAT) entries that follow each
redir. add_redir_spool_cfg() then walked up to 65535 spool entries
per redir past the end of the request buffer and stored what it read
as LSNAT servers, which IP_FW_NAT44_XGETCONFIG later copied out to
the caller. The request needs PRIV_NETINET_IPFW, which root in a
VNET jail has.
Add nat44_check_cfg(), which walks all redirs and their spool entries
and rejects a request that does not hold them, and call it before the
instance is touched. This also replaces the redir_cnt multiplication,
which could wrap on 32-bit platforms.
Do the same in the legacy IP_FW_NAT_CFG path, which does not convert
spool entries at all, and make its redir_cnt check overflow-safe.
That path is no longer reachable on main, but it is on stable/14.
Add tests/sys/netpfil/ipfw/nat44_config:
spool_missing a redir without its spool entries is rejected
spool_short a request one spool entry short is rejected
redir_cnt_overflow a redir_cnt that wraps on 32-bit is rejected
spool_roundtrip a complete LSNAT redir is accepted and read back
reject_keeps_config truncated requests for an existing instance are
rejected and leave its configuration unchangedspool_missing, spool_short and reject_keeps_config fail without the
fix.
Fixes: d6164b77f8b ("Make ipfw_nat module use IP_FW3 codes.")
MFC after: 1 week
Co-Authored-By: Claude Opus 5.5