netfilter-devel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH nft] intervals: BUG on prefix expressions without value
@ 2023-12-19 11:14 Florian Westphal
  0 siblings, 0 replies; only message in thread
From: Florian Westphal @ 2023-12-19 11:14 UTC (permalink / raw)
  To: netfilter-devel; +Cc: Florian Westphal

Its possible to end up with prefix expressions that have
a symbolic expression, e.g.:

table t {
        set s {
                type inet_service
                flags interval
                elements = { 0-1024, 8080-8082, 10000-40000 }
                elements = { 172.16.0.0/16 }
        }

        set s {
                type inet_service
                flags interval
                elements = { 0-1024, 8080-8082, 10000-40000 }
        }
}

Without this change, nft will crash.  We end up in setelem_expr_to_range()
with prefix "/16" for the symbolic expression "172.16.0.0".

We than pass invalid mpz_t pointer into libgmp.

This isn't the right fix (see next patch), but instead of blindly assuming
that the attached expression has a gmp value die with at least some info.

Its possible there are more ways than one to feed such
"symbol-with-prefix" down into the interval code, so also add this
assertion.

Signed-off-by: Florian Westphal <fw@strlen.de>
---
 src/intervals.c | 3 +++
 1 file changed, 3 insertions(+)

diff --git a/src/intervals.c b/src/intervals.c
index e535fc34afda..5a88a8eb20bd 100644
--- a/src/intervals.c
+++ b/src/intervals.c
@@ -28,6 +28,9 @@ static void setelem_expr_to_range(struct expr *expr)
 	case EXPR_RANGE:
 		break;
 	case EXPR_PREFIX:
+		if (expr->key->prefix->etype != EXPR_VALUE)
+			BUG("Prefix for unexpected type %d", expr->key->prefix->etype);
+
 		mpz_init(rop);
 		mpz_bitmask(rop, expr->key->len - expr->key->prefix_len);
 		if (expr_basetype(expr)->type == TYPE_STRING)
-- 
2.41.0


^ permalink raw reply related	[flat|nested] only message in thread

only message in thread, other threads:[~2023-12-19 11:14 UTC | newest]

Thread overview: (only message) (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2023-12-19 11:14 [PATCH nft] intervals: BUG on prefix expressions without value 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).