fix state key reference underflow, when sk == skrev
authorsashan <sashan@openbsd.org>
Mon, 17 May 2021 23:01:26 +0000 (23:01 +0000)
committersashan <sashan@openbsd.org>
Mon, 17 May 2021 23:01:26 +0000 (23:01 +0000)
commit83714fa12aa34703bf2fcc5e2d25f7f8a463dae7
tree2bd1d69eff87f2ebe473c86f4723e566e1a734b7
parente2b29ba52666d7a1574b1fa2c4b0738d6264fd5d
fix state key reference underflow, when sk == skrev

the bug has been reported by Sebastien and Olivier Cherrier.
it has turned out the pf_state_key_link_reverse() does not
grab enough references when both state keys (sk and skrev)
are identical. This makes pf to trip assert later, when
references are being dropped:

panic(ffffffff81dfbc8e) at panic+0x11d
__assert(ffffffff81e64b54,ffffffff81e0a6ee,33a,ffffffff81e03b7f)
refcnt_rele(fffffd810bf02458) at refcnt_rele+0x6f
pf_state_key_unref(fffffd810bf023f0) at pf_state_key_unref+0x21
pf_remove_state(fffffd810c0c4578) at pf_remove_state+0x1fa
pf_purge_expired_states(2) at pf_purge_expired_states+0x232
pf_purge(ffffffff82236a30) at pf_purge+0x33
taskq_thread(ffff800000032080) at taskq_thread+0x81

fixed tested by Olivier Cherrier and semarie@

OK semarie@
sys/net/pf.c