Blame SOURCES/0031-src-Set-NFT_SET_CONCAT-flag-for-sets-with-concatenat.patch

f3c8d0
From 5566405cc171c8fa84e0a13ea96b89245a3fb512 Mon Sep 17 00:00:00 2001
f3c8d0
From: Phil Sutter <psutter@redhat.com>
f3c8d0
Date: Sat, 8 Aug 2020 00:05:48 +0200
f3c8d0
Subject: [PATCH] src: Set NFT_SET_CONCAT flag for sets with concatenated
f3c8d0
 ranges
f3c8d0
f3c8d0
Bugzilla: https://bugzilla.redhat.com/show_bug.cgi?id=1820684
f3c8d0
Upstream Status: nftables commit 09441b5e92cee
f3c8d0
f3c8d0
commit 09441b5e92ceea60198a35cd657904fa7a10ee54
f3c8d0
Author: Stefano Brivio <sbrivio@redhat.com>
f3c8d0
Date:   Mon Apr 13 21:48:03 2020 +0200
f3c8d0
f3c8d0
    src: Set NFT_SET_CONCAT flag for sets with concatenated ranges
f3c8d0
f3c8d0
    Pablo reports that nft, after commit 8ac2f3b2fca3 ("src: Add support
f3c8d0
    for concatenated set ranges"), crashes with older kernels (< 5.6)
f3c8d0
    without support for concatenated set ranges: those sets will be sent
f3c8d0
    to the kernel, which adds them without notion of the fact that
f3c8d0
    different concatenated fields are actually included, and nft crashes
f3c8d0
    while trying to list this kind of malformed concatenation.
f3c8d0
f3c8d0
    Use the NFT_SET_CONCAT flag introduced by kernel commit ef516e8625dd
f3c8d0
    ("netfilter: nf_tables: reintroduce the NFT_SET_CONCAT flag") when
f3c8d0
    sets including concatenated ranges are sent to the kernel, so that
f3c8d0
    older kernels (with no knowledge of this flag itself) will refuse set
f3c8d0
    creation.
f3c8d0
f3c8d0
    Note that, in expr_evaluate_set(), we have to check for the presence
f3c8d0
    of the flag, also on empty sets that might carry it in context data,
f3c8d0
    and actually set it in the actual set flags.
f3c8d0
f3c8d0
    Reported-by: Pablo Neira Ayuso <pablo@netfilter.org>
f3c8d0
    Signed-off-by: Stefano Brivio <sbrivio@redhat.com>
f3c8d0
    Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
f3c8d0
---
f3c8d0
 src/evaluate.c | 9 ++++++++-
f3c8d0
 1 file changed, 8 insertions(+), 1 deletion(-)
f3c8d0
f3c8d0
diff --git a/src/evaluate.c b/src/evaluate.c
f3c8d0
index 0c84816..f66251b 100644
f3c8d0
--- a/src/evaluate.c
f3c8d0
+++ b/src/evaluate.c
f3c8d0
@@ -1360,10 +1360,16 @@ static int expr_evaluate_set(struct eval_ctx *ctx, struct expr **expr)
f3c8d0
 			set->size      += i->size - 1;
f3c8d0
 			set->set_flags |= i->set_flags;
f3c8d0
 			expr_free(i);
f3c8d0
-		} else if (!expr_is_singleton(i))
f3c8d0
+		} else if (!expr_is_singleton(i)) {
f3c8d0
 			set->set_flags |= NFT_SET_INTERVAL;
f3c8d0
+			if (i->key->etype == EXPR_CONCAT)
f3c8d0
+				set->set_flags |= NFT_SET_CONCAT;
f3c8d0
+		}
f3c8d0
 	}
f3c8d0
 
f3c8d0
+	if (ctx->set && (ctx->set->flags & NFT_SET_CONCAT))
f3c8d0
+		set->set_flags |= NFT_SET_CONCAT;
f3c8d0
+
f3c8d0
 	set->set_flags |= NFT_SET_CONSTANT;
f3c8d0
 
f3c8d0
 	datatype_set(set, ctx->ectx.dtype);
f3c8d0
@@ -3336,6 +3342,7 @@ static int set_evaluate(struct eval_ctx *ctx, struct set *set)
f3c8d0
 		memcpy(&set->desc.field_len, &set->key->field_len,
f3c8d0
 		       sizeof(set->desc.field_len));
f3c8d0
 		set->desc.field_count = set->key->field_count;
f3c8d0
+		set->flags |= NFT_SET_CONCAT;
f3c8d0
 	}
f3c8d0
 
f3c8d0
 	if (set_is_datamap(set->flags)) {
f3c8d0
-- 
bfbb76
2.31.1
f3c8d0