commit 5ce9cc4a6850d5011a427c167a496c35b1714ff1 Author: Andrey V. Elsukov Date: Tue Nov 17 13:03:51 2026 +0300 ipfw: fix value index allocation on shared value storage resize alloc_table_vidx() treated a successful resize_shared_value_storage() as complete success and returned an uninitialized vidx instead of allocating a new index in the grown bitmap. The removed restart machinery in b0c13e7e2446 used to handle this case by restarting the whole operation. Also refresh pval pointer in ipfw_link_table_values() after the resize, otherwise the new value object is registered against the freed old storage. PR: 300802 diff --git a/sys/netpfil/ipfw/ip_fw_table_value.c b/sys/netpfil/ipfw/ip_fw_table_value.c index 09e2ead6ec2c..554fd97b91dd 100644 --- a/sys/netpfil/ipfw/ip_fw_table_value.c +++ b/sys/netpfil/ipfw/ip_fw_table_value.c @@ -330,9 +330,19 @@ alloc_table_vidx(struct ip_fw_chain *ch, struct table_config *tc, IPFW_UH_WLOCK_ASSERT(ch); - if ((error = ipfw_objhash_alloc_idx(vi, &vidx)) != 0 && - (error = resize_shared_value_storage(ch)) != 0) - return (error); + error = ipfw_objhash_alloc_idx(vi, &vidx); + if (error != 0) { + /* + * Shared value storage is full. Grow it and retry + * index allocation. Note that resize replaces + * ch->valuestate pointer, so callers should re-fetch + * value pointers after this call. + */ + if ((error = resize_shared_value_storage(ch)) != 0) + return (error); + if ((error = ipfw_objhash_alloc_idx(vi, &vidx)) != 0) + return (error); + } vlimit = tc->ta->vlimit; if (vlimit != 0 && vidx >= vlimit && !(flags & IPFW_CTF_ATOMIC)) { @@ -499,6 +509,14 @@ ipfw_link_table_values(struct ip_fw_chain *ch, struct table_config *tc, if ((error = alloc_table_vidx(ch, tc, vi, &vidx, flags)) != 0) return (error); + /* + * Shared value storage might have been resized inside + * alloc_table_vidx(), refetch pointers to point to + * the actual data. + */ + if (pval != (struct table_value *)ch->valuestate) + get_value_ptrs(ch, tc, &pval, &vi); + /* Finally, we have allocated valid index, let's add entry */ ptei->value = vidx; ptv = (struct table_val_link *)ptei->ptv;