Skip to contentSkip to conversation

evaluate: error out if concat expression becomes too large

PATCH New Florian Westphal 1 participant 1 message Dec 12, 2023 netfilter

lore
Share & tools
lore

Florian Westphal

author maintainer
#0 lore raw

PATCH 1/1 evaluate: error out if concat expression becomes too large

Before:

BUG: nld buffer overflow: want to copy 132, max 64

After:
Error: Concatenation of size 544 exceeds maximum size of 512
udp length . @th,0,512 . @th,512,512 { 47-63 . 0xe373135363130 . 0x33131303735353203 }

                             ^^^^^^^^^

---
Pablo, I can merge this with
"[nft] parser_bison: reject large raw payload expressions" if you prefer.

 src/evaluate.c                                               | 4 ++++
 .../bogons/nft-f/stack_overflow_via_large_concat_expr        | 5 +++++
 2 files changed, 9 insertions(+)
 create mode 100644 tests/shell/testcases/bogons/nft-f/stack_overflow_via_large_concat_expr
src/evaluate.c +4 -0
index c7191e8cad08..e2d9a320587e 100644
@@ -1591,6 +1591,10 @@ static int expr_evaluate_concat(struct eval_ctx *ctx, struct expr **expr)
 		}
 
 		ctx->inner_desc = NULL;
+
+		if (size > NFT_REG32_COUNT * sizeof(uint32_t) * BITS_PER_BYTE)
+			return expr_error(ctx->msgs, i, "Concatenation of size %u exceeds maximum size of %u",
+					  size, NFT_REG32_COUNT * sizeof(uint32_t) * BITS_PER_BYTE);
 	}
 
 	(*expr)->flags |= flags;
tests/shell/testcases/bogons/nft-f/stack_overflow_via_large_concat_expr new file +5 -0
new file mode 100644
index 000000000000..8b0d27444c22
@@ -0,0 +1,5 @@
+table t {
+	chain c {
+		udp length . @th,0,512 . @th,512,512 { 47-63 . 0xe373135363130 . 0x33131303735353203 }
+	}
+}
Signature · 1 line
2.41.0