diff options
author | Pablo Neira Ayuso <pablo@netfilter.org> | 2023-07-18 23:10:01 +0200 |
---|---|---|
committer | Pablo Neira Ayuso <pablo@netfilter.org> | 2023-07-19 20:06:34 +0200 |
commit | 5f1676ac9f1aeb36d7695c3c354dade013a1e4f3 (patch) | |
tree | 35af0d12e861771e2f30107f1c79ed78c6dd9ce3 /src/payload.c | |
parent | ae1f506b5b0925dfe07215876f010dd087785ca9 (diff) |
meta: stash context statement length when generating payload/meta dependency
... meta mark set ip dscp
generates an implicit dependency from the inet family to match on meta
nfproto ip.
The length of this implicit expression is incorrectly adjusted to the
statement length, ie. relational to compare meta nfproto takes 4 bytes
instead of 1 byte. The evaluation of 'ip dscp' under the meta mark
statement triggers this implicit dependency which should not consider
the context statement length since it is added before the statement
itself.
This problem shows when listing the ruleset, since netlink_parse_cmp()
where left->len < right->len, hence handling the implicit dependency as
a concatenation, but it is actually a bug in the evaluation step that
leads to incorrect bytecode.
Fixes: 3c64ea7995cb ("evaluate: honor statement length in integer evaluation")
Fixes: edecd58755a8 ("evaluate: support shifts larger than the width of the left operand")
Tested-by: Brian Davidson <davidson.brian@gmail.com>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
Diffstat (limited to 'src/payload.c')
-rw-r--r-- | src/payload.c | 13 |
1 files changed, 13 insertions, 0 deletions
diff --git a/src/payload.c b/src/payload.c index f67b5407..7862745b 100644 --- a/src/payload.c +++ b/src/payload.c @@ -409,6 +409,7 @@ static int payload_add_dependency(struct eval_ctx *ctx, const struct proto_hdr_template *tmpl; struct expr *dep, *left, *right; struct proto_ctx *pctx; + unsigned int stmt_len; struct stmt *stmt; int protocol; @@ -429,11 +430,16 @@ static int payload_add_dependency(struct eval_ctx *ctx, constant_data_ptr(protocol, tmpl->len)); dep = relational_expr_alloc(&expr->location, OP_EQ, left, right); + + stmt_len = ctx->stmt_len; + ctx->stmt_len = 0; + stmt = expr_stmt_alloc(&dep->location, dep); if (stmt_evaluate(ctx, stmt) < 0) { return expr_error(ctx->msgs, expr, "dependency statement is invalid"); } + ctx->stmt_len = stmt_len; if (ctx->inner_desc) { if (tmpl->meta_key) @@ -543,6 +549,7 @@ int payload_gen_dependency(struct eval_ctx *ctx, const struct expr *expr, const struct hook_proto_desc *h; const struct proto_desc *desc; struct proto_ctx *pctx; + unsigned int stmt_len; struct stmt *stmt; uint16_t type; @@ -559,12 +566,18 @@ int payload_gen_dependency(struct eval_ctx *ctx, const struct expr *expr, "protocol specification is invalid " "for this family"); + stmt_len = ctx->stmt_len; + ctx->stmt_len = 0; + stmt = meta_stmt_meta_iiftype(&expr->location, type); if (stmt_evaluate(ctx, stmt) < 0) { return expr_error(ctx->msgs, expr, "dependency statement is invalid"); } *res = stmt; + + ctx->stmt_len = stmt_len; + return 0; } |