]> git.ipfire.org Git - thirdparty/nftables.git/commit
evaluate: reset statement length context before evaluating statement
authorPablo Neira Ayuso <pablo@netfilter.org>
Wed, 6 Dec 2023 17:48:29 +0000 (18:48 +0100)
committerFlorian Westphal <fw@strlen.de>
Fri, 8 Dec 2023 18:33:28 +0000 (19:33 +0100)
commit8d3de823b622136e1d05a6fed11ff2dc0e804f8a
treedd000055fb4d59f77aebc15c9f640feedbc68102
parent94fd162ea4d25fe6b0b4d58dcb7ff66dc55f3247
evaluate: reset statement length context before evaluating statement

This patch consolidates ctx->stmt_len reset in stmt_evaluate() to avoid
this problem. Note that stmt_evaluate_meta() and stmt_evaluate_ct()
already reset it after the statement evaluation.

Moreover, statement dependency can be generated while evaluating a meta
and ct statement. Payload statement dependency already manually stashes
this before calling stmt_evaluate(). Add a new stmt_dependency_evaluate()
function to stash statement length context when evaluating a new statement
dependency and use it for all of the existing statement dependencies.

Florian also says:

'meta mark set vlan id map { 1 : 0x00000001, 4095 : 0x00004095 }' will
crash. Reason is that the l2 dependency generated here is errounously
expanded to a 32bit-one, so the evaluation path won't recognize this
as a L2 dependency.  Therefore, pctx->stacked_ll_count is 0 and
__expr_evaluate_payload() crashes with a null deref when
dereferencing pctx->stacked_ll[0].

nft-test.py gains a fugly hack to tolerate '!map typeof vlan id : meta mark'.
For more generic support we should find something more acceptable, e.g.

!map typeof( everything here is a key or data ) timeout ...

tests/py update and assert(pctx->stacked_ll_count) by Florian Westphal.

Fixes: edecd58755a8 ("evaluate: support shifts larger than the width of the left operand")
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
Signed-off-by: Florian Westphal <fw@strlen.de>
include/statement.h
src/evaluate.c
src/payload.c
tests/py/any/meta.t
tests/py/any/meta.t.payload
tests/py/any/meta.t.payload.bridge [new file with mode: 0644]
tests/py/nft-test.py