git: e6e4e05afb96 - main - ipfw: fix value index allocation on shared value storage resize

From: Andrey V. Elsukov <ae_at_FreeBSD.org>
Date: Mon, 23 Nov 2026 12:10:16 UTC
The branch main has been updated by ae:

URL: https://cgit.FreeBSD.org/src/commit/?id=e6e4e05afb96ab8ccd0473a13ce5b23dc573390b

commit e6e4e05afb96ab8ccd0473a13ce5b23dc573390b
Author:     Andrey V. Elsukov <ae@FreeBSD.org>
AuthorDate: 2026-11-23 12:06:03 +0000
Commit:     Andrey V. Elsukov <ae@FreeBSD.org>
CommitDate: 2026-11-23 12:06:03 +0000

    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, 300803
    Reported by:    pouria
    Tested by:      pouria
---
 sys/netpfil/ipfw/ip_fw_table_value.c | 24 +++++++++++++++++++++---
 1 file changed, 21 insertions(+), 3 deletions(-)

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;