* [PATCH nft] evaluate: avoid double-free on error handling of bogus objref maps
@ 2025-06-24 21:20 Florian Westphal
2025-06-25 21:19 ` Pablo Neira Ayuso
0 siblings, 1 reply; 2+ messages in thread
From: Florian Westphal @ 2025-06-24 21:20 UTC (permalink / raw)
To: netfilter-devel; +Cc: Florian Westphal
commit 98c51aaac42b ("evaluate: bail out if anonymous concat set defines a non concat expression")
clears set->init to avoid a double-free.
Extend this to also handle object maps.
The included bogon triggers a double-free of set->init expression:
Error: unqualified type invalid specified in map definition. Try "typeof expression" instead of "type datatype".
ct helper set ct saddr map { 1c3:: : "p", dead::beef : "myftp" }
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
This might not crash, depending on libc/malloc, but ASAN reports this:
==17728==ERROR: AddressSanitizer: heap-use-after-free on address 0x50b0000005e8 at ..
READ of size 4 at 0x50b0000005e8 thread T0
#0 0x7f1be3cb7526 in expr_free src/expression.c:87
#1 0x7f1be3cbdf29 in map_expr_destroy src/expression.c:1488
#2 0x7f1be3cb74d5 in expr_destroy src/expression.c:80
#3 0x7f1be3cb75c6 in expr_free src/expression.c:96
#4 0x7f1be3d5925e in objref_stmt_destroy src/statement.c:331
#5 0x7f1be3d5831f in stmt_free src/statement.c:56
#6 0x7f1be3d583c2 in stmt_list_free src/statement.c:66
#7 0x7f1be3d42805 in rule_free src/rule.c:495
#8 0x7f1be3d48329 in cmd_free src/rule.c:1417
#9 0x7f1be3cd2c7c in __nft_run_cmd_from_filename src/libnftables.c:759
#10 0x7f1be3cd340c in nft_run_cmd_from_filename src/libnftables.c:847
#11 0x55dcde0440be in main src/main.c:535
Signed-off-by: Florian Westphal <fw@strlen.de>
---
src/evaluate.c | 2 +-
tests/shell/testcases/bogons/objref_double_free_crash | 10 ++++++++++
2 files changed, 11 insertions(+), 1 deletion(-)
create mode 100644 tests/shell/testcases/bogons/objref_double_free_crash
diff --git a/src/evaluate.c b/src/evaluate.c
index 699891106cb9..204796d00800 100644
--- a/src/evaluate.c
+++ b/src/evaluate.c
@@ -137,7 +137,7 @@ static struct expr *implicit_set_declaration(struct eval_ctx *ctx,
handle_merge(&set->handle, &ctx->cmd->handle);
if (set_evaluate(ctx, set) < 0) {
- if (set->flags & NFT_SET_MAP)
+ if (set->flags & (NFT_SET_MAP|NFT_SET_OBJECT))
set->init = NULL;
set_free(set);
return NULL;
diff --git a/tests/shell/testcases/bogons/objref_double_free_crash b/tests/shell/testcases/bogons/objref_double_free_crash
new file mode 100644
index 000000000000..52b0435bfddc
--- /dev/null
+++ b/tests/shell/testcases/bogons/objref_double_free_crash
@@ -0,0 +1,10 @@
+table arp test {
+ ct helper myftp {
+ type "ftp" protocol tcp
+ l3proto inet
+ }
+
+ chain y {
+ ct helper set ct saddr map { 1c3:: : "p", dead::beef : "myftp" }
+ }
+}
--
2.49.0
^ permalink raw reply related [flat|nested] 2+ messages in thread* Re: [PATCH nft] evaluate: avoid double-free on error handling of bogus objref maps
2025-06-24 21:20 [PATCH nft] evaluate: avoid double-free on error handling of bogus objref maps Florian Westphal
@ 2025-06-25 21:19 ` Pablo Neira Ayuso
0 siblings, 0 replies; 2+ messages in thread
From: Pablo Neira Ayuso @ 2025-06-25 21:19 UTC (permalink / raw)
To: Florian Westphal; +Cc: netfilter-devel
On Tue, Jun 24, 2025 at 11:20:58PM +0200, Florian Westphal wrote:
> commit 98c51aaac42b ("evaluate: bail out if anonymous concat set defines a non concat expression")
> clears set->init to avoid a double-free.
>
> Extend this to also handle object maps.
> The included bogon triggers a double-free of set->init expression:
>
> Error: unqualified type invalid specified in map definition. Try "typeof expression" instead of "type datatype".
> ct helper set ct saddr map { 1c3:: : "p", dead::beef : "myftp" }
> ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
>
> This might not crash, depending on libc/malloc, but ASAN reports this:
> ==17728==ERROR: AddressSanitizer: heap-use-after-free on address 0x50b0000005e8 at ..
> READ of size 4 at 0x50b0000005e8 thread T0
> #0 0x7f1be3cb7526 in expr_free src/expression.c:87
> #1 0x7f1be3cbdf29 in map_expr_destroy src/expression.c:1488
> #2 0x7f1be3cb74d5 in expr_destroy src/expression.c:80
> #3 0x7f1be3cb75c6 in expr_free src/expression.c:96
> #4 0x7f1be3d5925e in objref_stmt_destroy src/statement.c:331
> #5 0x7f1be3d5831f in stmt_free src/statement.c:56
> #6 0x7f1be3d583c2 in stmt_list_free src/statement.c:66
> #7 0x7f1be3d42805 in rule_free src/rule.c:495
> #8 0x7f1be3d48329 in cmd_free src/rule.c:1417
> #9 0x7f1be3cd2c7c in __nft_run_cmd_from_filename src/libnftables.c:759
> #10 0x7f1be3cd340c in nft_run_cmd_from_filename src/libnftables.c:847
> #11 0x55dcde0440be in main src/main.c:535
>
> Signed-off-by: Florian Westphal <fw@strlen.de>
Reviewed-by: Pablo Neira Ayuso <pablo@netfilter.org>
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2025-06-25 21:19 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-06-24 21:20 [PATCH nft] evaluate: avoid double-free on error handling of bogus objref maps Florian Westphal
2025-06-25 21:19 ` Pablo Neira Ayuso
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.