Skip to contentSkip to conversation

evaluate: bogus error when refering to existing non-base chain

PATCH Superseded Pablo Neira Ayuso 4 participants 10 messages Jul 16, 2019 netfilter

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore

Pablo Neira Ayuso

author maintainer
#0 lore raw

PATCH 1/1 evaluate: bogus error when refering to existing non-base chain

add rule ip testNEW test6 jump test8

                                ^^^^^

Error: invalid verdict chain expression value

---
 src/evaluate.c | 14 +++-----------
 1 file changed, 3 insertions(+), 11 deletions(-)
src/evaluate.c +3 -11
index f95f42e1067a..cd566e856a11 100644
@@ -1984,17 +1984,9 @@ static int stmt_evaluate_verdict(struct eval_ctx *ctx, struct stmt *stmt)
 	case EXPR_VERDICT:
 		if (stmt->expr->verdict != NFT_CONTINUE)
 			stmt->flags |= STMT_F_TERMINAL;
-		if (stmt->expr->chain != NULL) {
-			if (expr_evaluate(ctx, &stmt->expr->chain) < 0)
-				return -1;
-			if ((stmt->expr->chain->etype != EXPR_SYMBOL &&
-			    stmt->expr->chain->etype != EXPR_VALUE) ||
-			    stmt->expr->chain->symtype != SYMBOL_VALUE) {
-				return stmt_error(ctx, stmt,
-						  "invalid verdict chain expression %s\n",
-						  expr_name(stmt->expr->chain));
-			}
-		}
+		if (stmt->expr->chain != NULL &&
+		    expr_evaluate(ctx, &stmt->expr->chain) < 0)
+			return -1;
 		break;
 	case EXPR_MAP:
 		break;
Signature · 1 line
2.11.0
reviewer
#1 lore raw

Hi Pablo,

On Tue, Jul 16, 2019 at 01:51:20PM +0200, Pablo Neira Ayuso wrote:
[...]

Quoted 9 lines
src/evaluate.c +0 -1
index f95f42e1067a..cd566e856a11 100644
@@ -1984,17 +1984,9 @@ static int stmt_evaluate_verdict(struct eval_ctx *ctx, struct stmt *stmt)
 	case EXPR_VERDICT:
 		if (stmt->expr->verdict != NFT_CONTINUE)
 			stmt->flags |= STMT_F_TERMINAL;
-		if (stmt->expr->chain != NULL) {

src/evaluate.c static int stmt_evaluate_verdict(struct eval_ctx *ctx, struct stmt *stmt) · line 1997

Quoted 10 lines
src/evaluate.c +0 -10
-			if (expr_evaluate(ctx, &stmt->expr->chain) < 0)
-				return -1;
-			if ((stmt->expr->chain->etype != EXPR_SYMBOL &&
-			    stmt->expr->chain->etype != EXPR_VALUE) ||
-			    stmt->expr->chain->symtype != SYMBOL_VALUE) {
-				return stmt_error(ctx, stmt,
-						  "invalid verdict chain expression %s\n",
-						  expr_name(stmt->expr->chain));
-			}
-		}

According to my logs, this bit was added by Fernando to cover for invalid variable values[1]. So I fear we can't just drop this check.

Cheers, Phil

[1] I didn't check with current sources, but back then the following variable contents were problematic:

* define foo = @set1 (a set named 'set1' must exist)
* define foo = { 1024 }
* define foo = *

#2 lore raw
Quoted 28 lines · Phil Sutter

Hi Pablo,

On Tue, Jul 16, 2019 at 01:51:20PM +0200, Pablo Neira Ayuso wrote:
[...]

src/evaluate.c static int stmt_evaluate_verdict(struct

Quoted 5 lines
src/evaluate.c +0 -0
index f95f42e1067a..cd566e856a11 100644
@@ -1984,17 +1984,9 @@ static int stmt_evaluate_verdict(struct

eval_ctx *ctx, struct stmt *stmt)

Quoted 4 lines
src/evaluate.c +0 -1
 	case EXPR_VERDICT:
 		if (stmt->expr->verdict != NFT_CONTINUE)
 			stmt->flags |= STMT_F_TERMINAL;
-		if (stmt->expr->chain != NULL) {

src/evaluate.c static int stmt_evaluate_verdict(struct eval_ctx *ctx, struct stmt *stmt) · line 1997

Quoted 10 lines
src/evaluate.c +0 -10
-			if (expr_evaluate(ctx, &stmt->expr->chain) < 0)
-				return -1;
-			if ((stmt->expr->chain->etype != EXPR_SYMBOL &&
-			    stmt->expr->chain->etype != EXPR_VALUE) ||
-			    stmt->expr->chain->symtype != SYMBOL_VALUE) {
-				return stmt_error(ctx, stmt,
-						  "invalid verdict chain expression %s\n",
-						  expr_name(stmt->expr->chain));
-			}
-		}

According to my logs, this bit was added by Fernando to cover for invalid variable values[1]. So I fear we can't just drop this check.

Quoted 8 lines

Cheers, Phil

[1] I didn't check with current sources, but back then the following variable contents were problematic:

* define foo = @set1 (a set named 'set1' must exist)
* define foo = { 1024 }
* define foo = *

Yes I am looking to the report and why current version fails when the jump is to a non-base chain because I tested that some months ago.

I will catch up with more details in a few hours. Sorry for the inconveniences.

maintainer
#3 lore raw
Quoted 34 lines · Fernando Fernandez Mancera
Quoted 33 lines · Phil Sutter

Hi Pablo,

On Tue, Jul 16, 2019 at 01:51:20PM +0200, Pablo Neira Ayuso wrote:
[...]

src/evaluate.c static int stmt_evaluate_verdict(struct

Quoted 5 lines
src/evaluate.c +0 -0
index f95f42e1067a..cd566e856a11 100644
@@ -1984,17 +1984,9 @@ static int stmt_evaluate_verdict(struct

eval_ctx *ctx, struct stmt *stmt)

Quoted 4 lines
src/evaluate.c +0 -1
 	case EXPR_VERDICT:
 		if (stmt->expr->verdict != NFT_CONTINUE)
 			stmt->flags |= STMT_F_TERMINAL;
-		if (stmt->expr->chain != NULL) {

src/evaluate.c static int stmt_evaluate_verdict(struct eval_ctx *ctx, struct stmt *stmt) · line 1997

Quoted 10 lines
src/evaluate.c +0 -10
-			if (expr_evaluate(ctx, &stmt->expr->chain) < 0)
-				return -1;
-			if ((stmt->expr->chain->etype != EXPR_SYMBOL &&
-			    stmt->expr->chain->etype != EXPR_VALUE) ||
-			    stmt->expr->chain->symtype != SYMBOL_VALUE) {
-				return stmt_error(ctx, stmt,
-						  "invalid verdict chain expression %s\n",
-						  expr_name(stmt->expr->chain));
-			}
-		}

According to my logs, this bit was added by Fernando to cover for invalid variable values[1]. So I fear we can't just drop this check.

Cheers, Phil

[1] I didn't check with current sources, but back then the following variable contents were problematic:

Quoted 7 lines
Quoted 3 lines

* define foo = @set1 (a set named 'set1' must exist)
* define foo = { 1024 }
* define foo = *

Yes I am looking to the report and why current version fails when the jump is to a non-base chain because I tested that some months ago.

I will catch up with more details in a few hours. Sorry for the inconveniences.

Fernando, in case Pablos patch v2 fixes the reported bug, could you followup with a test case? It would help when someone tries to remove "unneeded code" in the future ;-)

Thanks,
Florian

author maintainer
#4 lore raw
Quoted 39 lines · Florian Westphal
Quoted 38 lines · Fernando Fernandez Mancera
Quoted 36 lines · Phil Sutter

Hi Pablo,

On Tue, Jul 16, 2019 at 01:51:20PM +0200, Pablo Neira Ayuso wrote:
[...]

src/evaluate.c static int stmt_evaluate_verdict(struct

Quoted 5 lines
src/evaluate.c +0 -0
index f95f42e1067a..cd566e856a11 100644
@@ -1984,17 +1984,9 @@ static int stmt_evaluate_verdict(struct

eval_ctx *ctx, struct stmt *stmt)

Quoted 4 lines
src/evaluate.c +0 -1
 	case EXPR_VERDICT:
 		if (stmt->expr->verdict != NFT_CONTINUE)
 			stmt->flags |= STMT_F_TERMINAL;
-		if (stmt->expr->chain != NULL) {

src/evaluate.c static int stmt_evaluate_verdict(struct eval_ctx *ctx, struct stmt *stmt) · line 1997

Quoted 10 lines
src/evaluate.c +0 -10
-			if (expr_evaluate(ctx, &stmt->expr->chain) < 0)
-				return -1;
-			if ((stmt->expr->chain->etype != EXPR_SYMBOL &&
-			    stmt->expr->chain->etype != EXPR_VALUE) ||
-			    stmt->expr->chain->symtype != SYMBOL_VALUE) {
-				return stmt_error(ctx, stmt,
-						  "invalid verdict chain expression %s\n",
-						  expr_name(stmt->expr->chain));
-			}
-		}

According to my logs, this bit was added by Fernando to cover for invalid variable values[1]. So I fear we can't just drop this check.

Cheers, Phil

[1] I didn't check with current sources, but back then the following variable contents were problematic:

* define foo = @set1 (a set named 'set1' must exist)
* define foo = { 1024 }
* define foo = *

Quoted 7 lines
Quoted 3 lines

Yes I am looking to the report and why current version fails when the jump is to a non-base chain because I tested that some months ago.

I will catch up with more details in a few hours. Sorry for the inconveniences.

Fernando, in case Pablos patch v2 fixes the reported bug, could you followup with a test case? It would help when someone tries to remove "unneeded code" in the future ;-)

I'm not sure it's worth a test for this unlikely corner case.

There are thousands of paths where we're not performing strict expression validation as in this case... and if you really want to get this right.

author maintainer
#5 lore raw
Quoted 48 lines · Pablo Neira Ayuso
Quoted 39 lines · Florian Westphal
Quoted 38 lines · Fernando Fernandez Mancera
Quoted 36 lines · Phil Sutter

Hi Pablo,

On Tue, Jul 16, 2019 at 01:51:20PM +0200, Pablo Neira Ayuso wrote:
[...]

src/evaluate.c static int stmt_evaluate_verdict(struct

Quoted 5 lines
src/evaluate.c +0 -0
index f95f42e1067a..cd566e856a11 100644
@@ -1984,17 +1984,9 @@ static int stmt_evaluate_verdict(struct

eval_ctx *ctx, struct stmt *stmt)

Quoted 4 lines
src/evaluate.c +0 -1
 	case EXPR_VERDICT:
 		if (stmt->expr->verdict != NFT_CONTINUE)
 			stmt->flags |= STMT_F_TERMINAL;
-		if (stmt->expr->chain != NULL) {

src/evaluate.c static int stmt_evaluate_verdict(struct eval_ctx *ctx, struct stmt *stmt) · line 1997

Quoted 10 lines
src/evaluate.c +0 -10
-			if (expr_evaluate(ctx, &stmt->expr->chain) < 0)
-				return -1;
-			if ((stmt->expr->chain->etype != EXPR_SYMBOL &&
-			    stmt->expr->chain->etype != EXPR_VALUE) ||
-			    stmt->expr->chain->symtype != SYMBOL_VALUE) {
-				return stmt_error(ctx, stmt,
-						  "invalid verdict chain expression %s\n",
-						  expr_name(stmt->expr->chain));
-			}
-		}

According to my logs, this bit was added by Fernando to cover for invalid variable values[1]. So I fear we can't just drop this check.

Cheers, Phil

[1] I didn't check with current sources, but back then the following variable contents were problematic:

* define foo = @set1 (a set named 'set1' must exist)
* define foo = { 1024 }
* define foo = *

Quoted 7 lines
Quoted 3 lines

Yes I am looking to the report and why current version fails when the jump is to a non-base chain because I tested that some months ago.

I will catch up with more details in a few hours. Sorry for the inconveniences.

Fernando, in case Pablos patch v2 fixes the reported bug, could you followup with a test case? It would help when someone tries to remove "unneeded code" in the future ;-)

Quoted 5 lines

I'm not sure it's worth a test for this unlikely corner case.

There are thousands of paths where we're not performing strict expression validation as in this case... and if you really want to get this right.

Having said this, if you want a test for this specific case, I really don't mind :-)

maintainer
#6 lore raw
Quoted 2 lines · Pablo Neira Ayuso

Having said this, if you want a test for this specific case, I really don't mind :-)

Fair enough, Fernando, if you think you have more important things to work on then just ignore this.

#7 lore raw
Quoted 6 lines · Florian Westphal
Quoted 2 lines · Pablo Neira Ayuso

Having said this, if you want a test for this specific case, I really don't mind :-)

Fair enough, Fernando, if you think you have more important things to work on then just ignore this.

I am going to send a patch with a test for this case. It should be easy :-)

#8 lore raw
In reply to Pablo Neira Ayuso

Hi,

Quoted 40 lines · Pablo Neira Ayuso
Quoted 39 lines · Florian Westphal
Quoted 38 lines · Fernando Fernandez Mancera
Quoted 36 lines · Phil Sutter

Hi Pablo,

On Tue, Jul 16, 2019 at 01:51:20PM +0200, Pablo Neira Ayuso wrote:
[...]

src/evaluate.c static int stmt_evaluate_verdict(struct

Quoted 5 lines
src/evaluate.c +0 -0
index f95f42e1067a..cd566e856a11 100644
@@ -1984,17 +1984,9 @@ static int stmt_evaluate_verdict(struct

eval_ctx *ctx, struct stmt *stmt)

Quoted 4 lines
src/evaluate.c +0 -1
 	case EXPR_VERDICT:
 		if (stmt->expr->verdict != NFT_CONTINUE)
 			stmt->flags |= STMT_F_TERMINAL;
-		if (stmt->expr->chain != NULL) {

src/evaluate.c static int stmt_evaluate_verdict(struct eval_ctx *ctx, struct stmt *stmt) · line 1997

Quoted 10 lines
src/evaluate.c +0 -10
-			if (expr_evaluate(ctx, &stmt->expr->chain) < 0)
-				return -1;
-			if ((stmt->expr->chain->etype != EXPR_SYMBOL &&
-			    stmt->expr->chain->etype != EXPR_VALUE) ||
-			    stmt->expr->chain->symtype != SYMBOL_VALUE) {
-				return stmt_error(ctx, stmt,
-						  "invalid verdict chain expression %s\n",
-						  expr_name(stmt->expr->chain));
-			}
-		}

According to my logs, this bit was added by Fernando to cover for invalid variable values[1]. So I fear we can't just drop this check.

Cheers, Phil

[1] I didn't check with current sources, but back then the following variable contents were problematic:

* define foo = @set1 (a set named 'set1' must exist)
* define foo = { 1024 }
* define foo = *

Quoted 7 lines
Quoted 7 lines
Quoted 3 lines

Yes I am looking to the report and why current version fails when the jump is to a non-base chain because I tested that some months ago.

I will catch up with more details in a few hours. Sorry for the inconveniences.

Fernando, in case Pablos patch v2 fixes the reported bug, could you followup with a test case? It would help when someone tries to remove "unneeded code" in the future ;-)

I have been taking a look to the shell tests and we already have some tests that cover these cases "tests/shell/testcases/chains/0001jumps_0", "tests/shell/testcases/nft-f/0018jump_variable_0", "tests/shell/testcases/nft-f/0019jump_variable_1", "tests/shell/testcases/nft-f/0020jump_variable_1".

Also I have tested Pablo's v2 patch and it works fine for me.

I would like to know how could I prevent this kind of situations in the future. Is there a way to automatically test your patch with other relevant kernel versions?

Thanks! :-)

Quoted 7 lines

I'm not sure it's worth a test for this unlikely corner case.

There are thousands of paths where we're not performing strict expression validation as in this case... and if you really want to get this right.

reviewer
#9 lore raw
In reply to Pablo Neira Ayuso
Quoted 3 lines · Pablo Neira Ayuso

add rule ip testNEW test6 jump test8

                                ^^^^^

Error: invalid verdict chain expression value

Note that I can't reproduce this issue locally.

[...]

src/evaluate.c static int stmt_evaluate_verdict(struct eval_ctx *ctx, struct stmt *stmt) · line 1996

Quoted 7 lines
src/evaluate.c +0 -7
-			if ((stmt->expr->chain->etype != EXPR_SYMBOL &&
-			    stmt->expr->chain->etype != EXPR_VALUE) ||
-			    stmt->expr->chain->symtype != SYMBOL_VALUE) {
-				return stmt_error(ctx, stmt,
-						  "invalid verdict chain expression %s\n",
-						  expr_name(stmt->expr->chain));
-			}

So I guess the problem is that for an etype of EXPR_VALUE, symtype is still checked. The latter is used by EXPR_SYMBOL only, but since SYMBOL_VALUE is 0 (implicitly, it's the first item in enum symbol_types) this probably works by accident.

I still don't understand why it doesn't work for you, but I guess the bug is found. So probably

| if ((stmt->expr->chain->etype != EXPR_SYMBOL ||
|       stmt->expr->chain->symtype != SYMBOL_VALUE) &&
|     stmt->expr->chain->etype != EXPR_VALUE)) {

is right.

Cheers, Phil