Skip to contentSkip to conversation

evaluate: Reject quoted strings containing only wildcard

PATCH In review Phil Sutter 2 participants 5 messages Sep 24, 2020 – Dec 17, 2020 netfilter

lore
Share & tools
lore

Phil Sutter

author reviewer
#0 lore raw

PATCH 1/1 evaluate: Reject quoted strings containing only wildcard

Fix for an assertion fail when trying to match against an all-wildcard interface name:

| % nft add rule t c iifname '"*"'
| nft: expression.c:402: constant_expr_alloc: Assertion `(((len) + (8) - 1) / (8)) > 0' failed.
| zsh: abort      nft add rule t c iifname '"*"'

Fix this by detecting the string in expr_evaluate_string() and returning an error message:

| % nft add rule t c iifname '"*"'
| Error: All-wildcard strings are not supported
| add rule t c iifname "*"
|                      ^^^

While being at it, drop the 'datalen >= 1' clause from the following conditional as together with the added check for 'datalen == 0', all possible other values have been caught already.

---
 src/evaluate.c | 7 +++++--
 1 file changed, 5 insertions(+), 2 deletions(-)
src/evaluate.c +5 -2
index c8045e5ded729..5f17d7501ac0e 100644
@@ -324,8 +324,11 @@ static int expr_evaluate_string(struct eval_ctx *ctx, struct expr **exprp)
 		return 0;
 	}
 
-	if (datalen >= 1 &&
-	    data[datalen - 1] == '\\') {
+	if (datalen == 0)
+		return expr_error(ctx->msgs, expr,
+				  "All-wildcard strings are not supported");
+
+	if (data[datalen - 1] == '\\') {
 		char unescaped_str[data_len];
 
 		memset(unescaped_str, 0, sizeof(unescaped_str));
Signature · 1 line
2.28.0
author reviewer
#1 lore raw
Quoted 7 lines · Phil Sutter

Fix for an assertion fail when trying to match against an all-wildcard interface name:

| % nft add rule t c iifname '"*"'
| nft: expression.c:402: constant_expr_alloc: Assertion `(((len) + (8) - 1) / (8)) > 0' failed.
| zsh: abort      nft add rule t c iifname '"*"'
Quoted 8 lines

Fix this by detecting the string in expr_evaluate_string() and returning an error message:

| % nft add rule t c iifname '"*"'
| Error: All-wildcard strings are not supported
| add rule t c iifname "*"
|                      ^^^

Note that all this is pretty inconsistent: The above happens only for quoted asterisks. Unquoted ones cause a different error (at least no assertion fail):

| % nft add rule t c iifname '*'
| Error: datatype mismatch, expected network interface name, expression has type integer
| add rule t c iifname *
|              ~~~~~~~ ^

What puzzles me is that we have:

| wildcard_expr           :       ASTERISK
|                         {
|                                 struct expr *expr;
| 
|                                 expr = constant_expr_alloc(&@$, &integer_type,
|                                                            BYTEORDER_HOST_ENDIAN,
|                                                            0, NULL);
|                                 $$ = prefix_expr_alloc(&@$, expr, 0);
|                         }
|                         ;

Yet when trying to use it as a prefix, it is rejected:

| % nft add rule t c ip saddr '*'
| Error: datatype mismatch, expected IPv4 address, expression has type integer
| add rule t c ip saddr *
|              ~~~~~~~~ ^

So is this wildcard_expr simply broken or didn't I find correct way to use it yet?

Cheers, Phil

#2 lore raw
Quoted 41 lines · Phil Sutter
Quoted 7 lines · Phil Sutter

Fix for an assertion fail when trying to match against an all-wildcard interface name:

| % nft add rule t c iifname '"*"'
| nft: expression.c:402: constant_expr_alloc: Assertion `(((len) + (8) - 1) / (8)) > 0' failed.
| zsh: abort      nft add rule t c iifname '"*"'
Quoted 8 lines

Fix this by detecting the string in expr_evaluate_string() and returning an error message:

| % nft add rule t c iifname '"*"'
| Error: All-wildcard strings are not supported
| add rule t c iifname "*"
|                      ^^^

Note that all this is pretty inconsistent: The above happens only for quoted asterisks. Unquoted ones cause a different error (at least no assertion fail):

| % nft add rule t c iifname '*'
| Error: datatype mismatch, expected network interface name, expression has type integer
| add rule t c iifname *
|              ~~~~~~~ ^

What puzzles me is that we have:

| wildcard_expr           :       ASTERISK
|                         {
|                                 struct expr *expr;
| 
|                                 expr = constant_expr_alloc(&@$, &integer_type,
|                                                            BYTEORDER_HOST_ENDIAN,
|                                                            0, NULL);
|                                 $$ = prefix_expr_alloc(&@$, expr, 0);
|                         }
|                         ;

Yet when trying to use it as a prefix, it is rejected:

Quoted 7 lines
| % nft add rule t c ip saddr '*'
| Error: datatype mismatch, expected IPv4 address, expression has type integer
| add rule t c ip saddr *
|              ~~~~~~~~ ^

So is this wildcard_expr simply broken or didn't I find correct way to use it yet?

This looks like some preliminary support for wildcard matching in set elements, but my impression is that this is broken. I don't remember to have seen any tests covering this.

author reviewer
#3 lore raw
Quoted 47 lines · Pablo Neira Ayuso
Quoted 46 lines · Phil Sutter
Quoted 7 lines · Phil Sutter

Fix for an assertion fail when trying to match against an all-wildcard interface name:

| % nft add rule t c iifname '"*"'
| nft: expression.c:402: constant_expr_alloc: Assertion `(((len) + (8) - 1) / (8)) > 0' failed.
| zsh: abort      nft add rule t c iifname '"*"'
Quoted 8 lines

Fix this by detecting the string in expr_evaluate_string() and returning an error message:

| % nft add rule t c iifname '"*"'
| Error: All-wildcard strings are not supported
| add rule t c iifname "*"
|                      ^^^

Note that all this is pretty inconsistent: The above happens only for quoted asterisks. Unquoted ones cause a different error (at least no assertion fail):

| % nft add rule t c iifname '*'
| Error: datatype mismatch, expected network interface name, expression has type integer
| add rule t c iifname *
|              ~~~~~~~ ^

What puzzles me is that we have:

| wildcard_expr           :       ASTERISK
|                         {
|                                 struct expr *expr;
| 
|                                 expr = constant_expr_alloc(&@$, &integer_type,
|                                                            BYTEORDER_HOST_ENDIAN,
|                                                            0, NULL);
|                                 $$ = prefix_expr_alloc(&@$, expr, 0);
|                         }
|                         ;

Yet when trying to use it as a prefix, it is rejected:

| % nft add rule t c ip saddr '*'
| Error: datatype mismatch, expected IPv4 address, expression has type integer
| add rule t c ip saddr *
|              ~~~~~~~~ ^
Quoted 6 lines
Quoted 2 lines

So is this wildcard_expr simply broken or didn't I find correct way to use it yet?

This looks like some preliminary support for wildcard matching in set elements, but my impression is that this is broken. I don't remember to have seen any tests covering this.

OK. If it needs fixing, I guess that's a different issue. Are you fine with the "fix" for asterisk-only interface names for the time being?

Thanks, Phil

#4 lore raw
Quoted 51 lines · Phil Sutter
Quoted 50 lines · Pablo Neira Ayuso
Quoted 48 lines · Phil Sutter
Quoted 7 lines · Phil Sutter

Fix for an assertion fail when trying to match against an all-wildcard interface name:

| % nft add rule t c iifname '"*"'
| nft: expression.c:402: constant_expr_alloc: Assertion `(((len) + (8) - 1) / (8)) > 0' failed.
| zsh: abort      nft add rule t c iifname '"*"'
Quoted 8 lines

Fix this by detecting the string in expr_evaluate_string() and returning an error message:

| % nft add rule t c iifname '"*"'
| Error: All-wildcard strings are not supported
| add rule t c iifname "*"
|                      ^^^

Note that all this is pretty inconsistent: The above happens only for quoted asterisks. Unquoted ones cause a different error (at least no assertion fail):

| % nft add rule t c iifname '*'
| Error: datatype mismatch, expected network interface name, expression has type integer
| add rule t c iifname *
|              ~~~~~~~ ^

What puzzles me is that we have:

| wildcard_expr           :       ASTERISK
|                         {
|                                 struct expr *expr;
| 
|                                 expr = constant_expr_alloc(&@$, &integer_type,
|                                                            BYTEORDER_HOST_ENDIAN,
|                                                            0, NULL);
|                                 $$ = prefix_expr_alloc(&@$, expr, 0);
|                         }
|                         ;

Yet when trying to use it as a prefix, it is rejected:

| % nft add rule t c ip saddr '*'
| Error: datatype mismatch, expected IPv4 address, expression has type integer
| add rule t c ip saddr *
|              ~~~~~~~~ ^

So is this wildcard_expr simply broken or didn't I find correct way to use it yet?

Quoted 6 lines
Quoted 3 lines

This looks like some preliminary support for wildcard matching in set elements, but my impression is that this is broken. I don't remember to have seen any tests covering this.

OK. If it needs fixing, I guess that's a different issue. Are you fine with the "fix" for asterisk-only interface names for the time being?

I think so, yes.