netfilter-devel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [nft PATCH] evaluate: prevent using sets in payload statements
@ 2017-05-24 13:11 Arturo Borrero Gonzalez
  2017-05-24 15:48 ` Pablo Neira Ayuso
  0 siblings, 1 reply; 3+ messages in thread
From: Arturo Borrero Gonzalez @ 2017-05-24 13:11 UTC (permalink / raw)
  To: netfilter-devel

Prevent this assert:

% nft [..] tcp dport set { 0 , 1 }
BUG: unknown expression type set reference
nft: netlink_linearize.c:696: netlink_gen_expr: Assertion `0' failed.
Aborted

We can't use a set here because we will not known what value to use.

With this patch, this is produced:

% nft [..] tcp dport set {1, 2 }
<cmdline>:1:19-27: Error: you cannot use a set here
add rule ip nat c tcp dport set {1, 2 }
                  ^^^^^^^^^~~~~~~~~~~~~
% nft [..] tcp dport set @s
<cmdline>:1:19-27: Error: you cannot reference a set here
add rule ip nat c tcp dport set @s
                  ^^^^^^^^^~~~~~~~

Using maps is still allowed:

% nft [..] tcp dport set numgen inc mod 2 map { 0 : 4040 , 1 : 4050 }

Signed-off-by: Arturo Borrero Gonzalez <arturo@debian.org>
---
 0 files changed

diff --git a/src/evaluate.c b/src/evaluate.c
index 27cee98..f307f64 100644
--- a/src/evaluate.c
+++ b/src/evaluate.c
@@ -1807,6 +1807,17 @@ static int stmt_evaluate_payload(struct eval_ctx *ctx, struct stmt *stmt)
 			      payload->byteorder, &stmt->payload.val) < 0)
 		return -1;
 
+	switch (stmt->payload.val->ops->type) {
+	case EXPR_SET:
+		return stmt_binary_error(ctx, stmt->payload.expr, stmt,
+					 "you cannot use a set here");
+	case EXPR_SET_REF:
+		return stmt_binary_error(ctx, stmt->payload.expr, stmt,
+					 "you cannot reference a set here");
+	default:
+		break;
+	}
+
 	need_csum = stmt_evaluate_payload_need_csum(payload);
 
 	if (!payload_needs_adjustment(payload)) {


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

* Re: [nft PATCH] evaluate: prevent using sets in payload statements
  2017-05-24 13:11 [nft PATCH] evaluate: prevent using sets in payload statements Arturo Borrero Gonzalez
@ 2017-05-24 15:48 ` Pablo Neira Ayuso
  2017-05-24 15:49   ` Pablo Neira Ayuso
  0 siblings, 1 reply; 3+ messages in thread
From: Pablo Neira Ayuso @ 2017-05-24 15:48 UTC (permalink / raw)
  To: Arturo Borrero Gonzalez; +Cc: netfilter-devel

On Wed, May 24, 2017 at 03:11:04PM +0200, Arturo Borrero Gonzalez wrote:
> Prevent this assert:
> 
> % nft [..] tcp dport set { 0 , 1 }
> BUG: unknown expression type set reference
> nft: netlink_linearize.c:696: netlink_gen_expr: Assertion `0' failed.
> Aborted
> 
> We can't use a set here because we will not known what value to use.
> 
> With this patch, this is produced:
> 
> % nft [..] tcp dport set {1, 2 }
> <cmdline>:1:19-27: Error: you cannot use a set here
> add rule ip nat c tcp dport set {1, 2 }
>                   ^^^^^^^^^~~~~~~~~~~~~
> % nft [..] tcp dport set @s
> <cmdline>:1:19-27: Error: you cannot reference a set here
> add rule ip nat c tcp dport set @s
>                   ^^^^^^^^^~~~~~~~
> 
> Using maps is still allowed:
> 
> % nft [..] tcp dport set numgen inc mod 2 map { 0 : 4040 , 1 : 4050 }

Good catch.

I think we should reject this more generically, ie.

nft add rule x y meta mark set {1, 2 }

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

* Re: [nft PATCH] evaluate: prevent using sets in payload statements
  2017-05-24 15:48 ` Pablo Neira Ayuso
@ 2017-05-24 15:49   ` Pablo Neira Ayuso
  0 siblings, 0 replies; 3+ messages in thread
From: Pablo Neira Ayuso @ 2017-05-24 15:49 UTC (permalink / raw)
  To: Arturo Borrero Gonzalez; +Cc: netfilter-devel

On Wed, May 24, 2017 at 05:48:20PM +0200, Pablo Neira Ayuso wrote:
> On Wed, May 24, 2017 at 03:11:04PM +0200, Arturo Borrero Gonzalez wrote:
> > Prevent this assert:
> > 
> > % nft [..] tcp dport set { 0 , 1 }
> > BUG: unknown expression type set reference
> > nft: netlink_linearize.c:696: netlink_gen_expr: Assertion `0' failed.
> > Aborted
> > 
> > We can't use a set here because we will not known what value to use.
> > 
> > With this patch, this is produced:
> > 
> > % nft [..] tcp dport set {1, 2 }
> > <cmdline>:1:19-27: Error: you cannot use a set here
> > add rule ip nat c tcp dport set {1, 2 }
> >                   ^^^^^^^^^~~~~~~~~~~~~
> > % nft [..] tcp dport set @s
> > <cmdline>:1:19-27: Error: you cannot reference a set here
> > add rule ip nat c tcp dport set @s
> >                   ^^^^^^^^^~~~~~~~
> > 
> > Using maps is still allowed:
> > 
> > % nft [..] tcp dport set numgen inc mod 2 map { 0 : 4040 , 1 : 4050 }
> 
> Good catch.
> 
> I think we should reject this more generically, ie.
> 
> nft add rule x y meta mark set {1, 2 }

I mean, the example above is not payload, but it should be rejected
too.

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

end of thread, other threads:[~2017-05-24 15:49 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2017-05-24 13:11 [nft PATCH] evaluate: prevent using sets in payload statements Arturo Borrero Gonzalez
2017-05-24 15:48 ` Pablo Neira Ayuso
2017-05-24 15:49   ` Pablo Neira Ayuso

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).