nat44_config() drops the upper half lock while it allocates and
configures an instance. When it takes the lock again, it looks for
an instance of the same name that a concurrent request has added in
the meantime. If there is one, it unlinks that instance and links in
its own, but then calls free_nat_instance() on its own instance, the
one it has just put on chain->nat. The list is left pointing at
freed memory, and the unlinked instance is leaked while rules that
cached a pointer to it keep using it.
Clear the cached pointers to the unlinked instance and free it instead
of the new one.
Since e3caa360d5d0 the upper half lock on main is sleepable and held
across the whole function, so the check never finds another instance
here. The stable branches still drop the lock, and two concurrent
"ipfw nat N config" requests for the same N can leave a freed instance
on the list.
Fixes: 1a458088fff7 ("Use free_nat_instance() for nat instance deletion.")
MFC after: 2 weeks
Assisted-by: Claude Opus 5.5