Since 4a77657cbc01 skipto and call targets, and the skipto value of a
table entry, are 32-bit, but nothing limits them to rule numbers:
- jump_lookup_pos() keeps the target in an int and clamps it with a signed compare, so with the skipto cache enabled a target of 2^31 or more turns negative and indexes chain->idxmap[] out of bounds.
- Without the skipto cache, a target above 65535 makes ipfw_find_rule() return the default rule, which trips the MPASS in the call/return handler on INVARIANTS kernels. Landing on the default rule is legitimate; skipto has always allowed it.
Treat any target above IPFW_DEFAULT_RULE as IPFW_DEFAULT_RULE for both
lookup methods, keep the target and the rule index unsigned, reject
skipto and call instructions with an out-of-range target when a rule
is added, and relax the MPASS to the bounds of the rule map. With the
skipto cache, a target of 65535 now lands on the first 65535 rule
again, the same as without the cache.
New tests:
skipto:skipto_tablearg_range skipto tablearg to 150, which lands
on a rule, and to 65535, 70000, 2^31
and 2^32 - 1, with and without the
skipto cache
skipto:call_tablearg_range the same for call tablearg
rule_check:skipto_range static skipto targets above
IPFW_DEFAULT_RULE are rejected
rule_check:call_range the same for call; return is not
affected
rule_check:setmark_value setmark, which shares the check, still
takes any 32-bit valueWithout the fix skipto_tablearg_range crashes the kernel,
call_tablearg_range crashes INVARIANTS kernels, and skipto_range and
call_range fail; setmark_value passes either way.
Co-authored-by: Claude Opus 5.5
Fixes: 4a77657cbc01 ("ipfw: migrate ipfw to 32-bit size rule numbers")
MFC after: 2 weeks