All of lore.kernel.org
 help / color / mirror / Atom feed
* [nft PATCH] dynset: avoid errouneous assert with ipv6 concat data
@ 2024-04-07 12:47 Son Dinh
  2024-04-07 17:17 ` Florian Westphal
  0 siblings, 1 reply; 5+ messages in thread
From: Son Dinh @ 2024-04-07 12:47 UTC (permalink / raw)
  To: netfilter-devel, pablo; +Cc: Son Dinh

Fix assert bug of map dynset having ipv6 concat data

 nft add rule ip6 table-test chain-1 update @map-X { ip6 saddr : 1000::1 . 5001 }
 nft: src/netlink_linearize.c:873: netlink_gen_expr: Assertion `dreg < ctx->reg_low' failed.
 Aborted (core dumped)

The current code allocates upto 4 registers for map dynset data, but ipv6 concat
data of a dynset requires more than 4 registers, resulting in the assert in
netlink_gen_expr when generating netlink info for the dynset data.

Signed-off-by: Son Dinh <dinhtrason@gmail.com>
---
 src/netlink_linearize.c | 11 ++++++++---
 1 file changed, 8 insertions(+), 3 deletions(-)

diff --git src/netlink_linearize.c src/netlink_linearize.c
index 6204d8fd..11b4bc2d 100644
--- src/netlink_linearize.c
+++ src/netlink_linearize.c
@@ -1588,15 +1588,20 @@ static void netlink_gen_map_stmt(struct netlink_linearize_ctx *ctx,
 	struct nftnl_expr *nle;
 	int num_stmts = 0;
 	struct stmt *this;
+	int regspace = 0;
+	struct expr *expr_data = stmt->map.data;
 
 	sreg_key = get_register(ctx, stmt->map.key->key);
 	netlink_gen_expr(ctx, stmt->map.key->key, sreg_key);
 
-	sreg_data = get_register(ctx, stmt->map.data);
-	netlink_gen_expr(ctx, stmt->map.data, sreg_data);
+	/* Adjust ctx->reg_low to the real size of stmt->map.data */
+	regspace = netlink_register_space(expr_data->map->len);
+	sreg_data = ctx->reg_low;
+	ctx->reg_low += regspace;
+	netlink_gen_expr(ctx, expr_data, sreg_data);
 
+	ctx->reg_low -= regspace;
 	release_register(ctx, stmt->map.key->key);
-	release_register(ctx, stmt->map.data);
 
 	nle = alloc_nft_expr("dynset");
 	netlink_put_register(nle, NFTNL_EXPR_DYNSET_SREG_KEY, sreg_key);
-- 
2.44.0.windows.1


^ permalink raw reply related	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2024-04-09  6:24 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2024-04-07 12:47 [nft PATCH] dynset: avoid errouneous assert with ipv6 concat data Son Dinh
2024-04-07 17:17 ` Florian Westphal
2024-04-08  4:32   ` Son Tra Dinh
2024-04-09  3:02     ` [nft PATCH v2] " Son Dinh
2024-04-09  6:23     ` [nft PATCH v3] " Son Dinh

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.