netfilter-devel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH nft] parser_bison: reject non-serializeable typeof expressions
@ 2025-03-19 16:22 Florian Westphal
  2025-03-19 23:50 ` Pablo Neira Ayuso
  0 siblings, 1 reply; 3+ messages in thread
From: Florian Westphal @ 2025-03-19 16:22 UTC (permalink / raw)
  To: netfilter-devel; +Cc: Florian Westphal

Included bogon asserts with:
BUG: unhandled key type 13
nft: src/intervals.c:73: setelem_expr_to_range: Assertion `0' failed.

This should be rejected at parser stage, but the check for udata
support was only done on the first item in a concatenation.

After fix, parser rejects this with:
Error: primary expression type 'symbol' lacks typeof serialization

Signed-off-by: Florian Westphal <fw@strlen.de>
---
 src/parser_bison.y                                 | 14 ++++++++++----
 .../nft-f/typeof_map_with_plain_integer_assert     |  7 +++++++
 2 files changed, 17 insertions(+), 4 deletions(-)
 create mode 100644 tests/shell/testcases/bogons/nft-f/typeof_map_with_plain_integer_assert

diff --git a/src/parser_bison.y b/src/parser_bison.y
index 4d4d39342bf7..cc3c908593a0 100644
--- a/src/parser_bison.y
+++ b/src/parser_bison.y
@@ -816,8 +816,8 @@ int nft_lex(void *, void *, void *);
 
 %type <expr>			symbol_expr verdict_expr integer_expr variable_expr chain_expr policy_expr
 %destructor { expr_free($$); }	symbol_expr verdict_expr integer_expr variable_expr chain_expr policy_expr
-%type <expr>			primary_expr shift_expr and_expr typeof_expr typeof_data_expr typeof_key_expr typeof_verdict_expr
-%destructor { expr_free($$); }	primary_expr shift_expr and_expr typeof_expr typeof_data_expr typeof_key_expr typeof_verdict_expr
+%type <expr>			primary_expr shift_expr and_expr primary_typeof_expr typeof_expr typeof_data_expr typeof_key_expr typeof_verdict_expr
+%destructor { expr_free($$); }	primary_expr shift_expr and_expr primary_typeof_expr typeof_expr typeof_data_expr typeof_key_expr typeof_verdict_expr
 %type <expr>			exclusive_or_expr inclusive_or_expr
 %destructor { expr_free($$); }	exclusive_or_expr inclusive_or_expr
 %type <expr>			basic_expr
@@ -2142,7 +2142,7 @@ typeof_data_expr	:	INTERVAL	typeof_expr
 			}
 			;
 
-typeof_expr		:	primary_expr
+primary_typeof_expr	:	primary_expr
 			{
 				if (expr_ops($1)->build_udata == NULL) {
 					erec_queue(error(&@1, "primary expression type '%s' lacks typeof serialization", expr_ops($1)->name),
@@ -2153,7 +2153,13 @@ typeof_expr		:	primary_expr
 
 				$$ = $1;
 			}
-			|	typeof_expr		DOT		primary_expr
+			;
+
+typeof_expr		:	primary_typeof_expr
+			{
+				$$ = $1;
+			}
+			|	typeof_expr		DOT		primary_typeof_expr
 			{
 				struct location rhs[] = {
 					[1]	= @2,
diff --git a/tests/shell/testcases/bogons/nft-f/typeof_map_with_plain_integer_assert b/tests/shell/testcases/bogons/nft-f/typeof_map_with_plain_integer_assert
new file mode 100644
index 000000000000..f1dc12f699ec
--- /dev/null
+++ b/tests/shell/testcases/bogons/nft-f/typeof_map_with_plain_integer_assert
@@ -0,0 +1,7 @@
+table ip t {
+        map m {
+                typeof ip saddr . meta mark  . 0: verdict
+                flags interval
+                elements = { 127.0.0.1-127.0.0.4 . 0x00123434-0x00b00122 : accept }
+        }
+}
-- 
2.48.1


^ permalink raw reply related	[flat|nested] 3+ messages in thread

* Re: [PATCH nft] parser_bison: reject non-serializeable typeof expressions
  2025-03-19 16:22 [PATCH nft] parser_bison: reject non-serializeable typeof expressions Florian Westphal
@ 2025-03-19 23:50 ` Pablo Neira Ayuso
  2025-03-20  8:20   ` Florian Westphal
  0 siblings, 1 reply; 3+ messages in thread
From: Pablo Neira Ayuso @ 2025-03-19 23:50 UTC (permalink / raw)
  To: Florian Westphal; +Cc: netfilter-devel

On Wed, Mar 19, 2025 at 05:22:40PM +0100, Florian Westphal wrote:
> Included bogon asserts with:
> BUG: unhandled key type 13
> nft: src/intervals.c:73: setelem_expr_to_range: Assertion `0' failed.
> 
> This should be rejected at parser stage, but the check for udata
> support was only done on the first item in a concatenation.
> 
> After fix, parser rejects this with:
> Error: primary expression type 'symbol' lacks typeof serialization

Maybe... otherwise, please correct me.

Fixes: 4ab1e5e60779 ("src: allow use of 'verdict' in typeof definitions")

> Signed-off-by: Florian Westphal <fw@strlen.de>

Thanks.

> ---
>  src/parser_bison.y                                 | 14 ++++++++++----
>  .../nft-f/typeof_map_with_plain_integer_assert     |  7 +++++++
>  2 files changed, 17 insertions(+), 4 deletions(-)
>  create mode 100644 tests/shell/testcases/bogons/nft-f/typeof_map_with_plain_integer_assert
> 
> diff --git a/src/parser_bison.y b/src/parser_bison.y
> index 4d4d39342bf7..cc3c908593a0 100644
> --- a/src/parser_bison.y
> +++ b/src/parser_bison.y
> @@ -816,8 +816,8 @@ int nft_lex(void *, void *, void *);
>  
>  %type <expr>			symbol_expr verdict_expr integer_expr variable_expr chain_expr policy_expr
>  %destructor { expr_free($$); }	symbol_expr verdict_expr integer_expr variable_expr chain_expr policy_expr
> -%type <expr>			primary_expr shift_expr and_expr typeof_expr typeof_data_expr typeof_key_expr typeof_verdict_expr
> -%destructor { expr_free($$); }	primary_expr shift_expr and_expr typeof_expr typeof_data_expr typeof_key_expr typeof_verdict_expr
> +%type <expr>			primary_expr shift_expr and_expr primary_typeof_expr typeof_expr typeof_data_expr typeof_key_expr typeof_verdict_expr
> +%destructor { expr_free($$); }	primary_expr shift_expr and_expr primary_typeof_expr typeof_expr typeof_data_expr typeof_key_expr typeof_verdict_expr
>  %type <expr>			exclusive_or_expr inclusive_or_expr
>  %destructor { expr_free($$); }	exclusive_or_expr inclusive_or_expr
>  %type <expr>			basic_expr
> @@ -2142,7 +2142,7 @@ typeof_data_expr	:	INTERVAL	typeof_expr
>  			}
>  			;
>  
> -typeof_expr		:	primary_expr
> +primary_typeof_expr	:	primary_expr
>  			{
>  				if (expr_ops($1)->build_udata == NULL) {
>  					erec_queue(error(&@1, "primary expression type '%s' lacks typeof serialization", expr_ops($1)->name),
> @@ -2153,7 +2153,13 @@ typeof_expr		:	primary_expr
>  
>  				$$ = $1;
>  			}
> -			|	typeof_expr		DOT		primary_expr
> +			;
> +
> +typeof_expr		:	primary_typeof_expr
> +			{
> +				$$ = $1;
> +			}
> +			|	typeof_expr		DOT		primary_typeof_expr
>  			{
>  				struct location rhs[] = {
>  					[1]	= @2,
> diff --git a/tests/shell/testcases/bogons/nft-f/typeof_map_with_plain_integer_assert b/tests/shell/testcases/bogons/nft-f/typeof_map_with_plain_integer_assert
> new file mode 100644
> index 000000000000..f1dc12f699ec
> --- /dev/null
> +++ b/tests/shell/testcases/bogons/nft-f/typeof_map_with_plain_integer_assert
> @@ -0,0 +1,7 @@
> +table ip t {
> +        map m {
> +                typeof ip saddr . meta mark  . 0: verdict
> +                flags interval
> +                elements = { 127.0.0.1-127.0.0.4 . 0x00123434-0x00b00122 : accept }
> +        }
> +}
> -- 
> 2.48.1
> 
> 

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH nft] parser_bison: reject non-serializeable typeof expressions
  2025-03-19 23:50 ` Pablo Neira Ayuso
@ 2025-03-20  8:20   ` Florian Westphal
  0 siblings, 0 replies; 3+ messages in thread
From: Florian Westphal @ 2025-03-20  8:20 UTC (permalink / raw)
  To: Pablo Neira Ayuso; +Cc: Florian Westphal, netfilter-devel

Pablo Neira Ayuso <pablo@netfilter.org> wrote:
> > After fix, parser rejects this with:
> > Error: primary expression type 'symbol' lacks typeof serialization
> 
> Maybe... otherwise, please correct me.
> 
> Fixes: 4ab1e5e60779 ("src: allow use of 'verdict' in typeof definitions")

I wasn't sure.  I'll add

Fixes: 6e48df5329ea ("src: add "typeof" build/parse/print support")

which added the 'no udata -> error' test (but only for the first
part of a concatenation instead of all subtypes).

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2025-03-20  8:20 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-03-19 16:22 [PATCH nft] parser_bison: reject non-serializeable typeof expressions Florian Westphal
2025-03-19 23:50 ` Pablo Neira Ayuso
2025-03-20  8:20   ` Florian Westphal

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).