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

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