Blame SOURCES/0049-nft-Fix-bitwise-expression-avoidance-detection.patch

082114
From f2d177c3a7a6a7154aabfab6047c510e0cee428e Mon Sep 17 00:00:00 2001
082114
From: Phil Sutter <phil@nwl.cc>
082114
Date: Fri, 19 Feb 2021 16:54:57 +0100
082114
Subject: [PATCH] nft: Fix bitwise expression avoidance detection
082114
082114
Byte-boundary prefix detection was too sloppy: Any data following the
082114
first zero-byte was ignored. Add a follow-up loop making sure there are
082114
no stray bits in the designated host part.
082114
082114
Fixes: 323259001d617 ("nft: Optimize class-based IP prefix matches")
082114
Signed-off-by: Phil Sutter <phil@nwl.cc>
082114
(cherry picked from commit 330f5df03ad589b46865ceedf2a54cf10a4225ba)
082114
Signed-off-by: Phil Sutter <psutter@redhat.com>
082114
---
082114
 iptables/nft-shared.c                         |  4 +++-
082114
 .../testcases/ip6tables/0004-address-masks_0  | 24 +++++++++++++++++++
082114
 2 files changed, 27 insertions(+), 1 deletion(-)
082114
 create mode 100755 iptables/tests/shell/testcases/ip6tables/0004-address-masks_0
082114
082114
diff --git a/iptables/nft-shared.c b/iptables/nft-shared.c
082114
index 2aae0a3a49dfe..7f757d38ecaec 100644
082114
--- a/iptables/nft-shared.c
082114
+++ b/iptables/nft-shared.c
082114
@@ -166,7 +166,7 @@ void add_addr(struct nftnl_rule *r, enum nft_payload_bases base, int offset,
082114
 {
082114
 	const unsigned char *m = mask;
082114
 	bool bitwise = false;
082114
-	int i;
082114
+	int i, j;
082114
 
082114
 	for (i = 0; i < len; i++) {
082114
 		if (m[i] != 0xff) {
082114
@@ -174,6 +174,8 @@ void add_addr(struct nftnl_rule *r, enum nft_payload_bases base, int offset,
082114
 			break;
082114
 		}
082114
 	}
082114
+	for (j = i + 1; !bitwise && j < len; j++)
082114
+		bitwise = !!m[j];
082114
 
082114
 	if (!bitwise)
082114
 		len = i;
082114
diff --git a/iptables/tests/shell/testcases/ip6tables/0004-address-masks_0 b/iptables/tests/shell/testcases/ip6tables/0004-address-masks_0
082114
new file mode 100755
082114
index 0000000000000..7eb42f08da975
082114
--- /dev/null
082114
+++ b/iptables/tests/shell/testcases/ip6tables/0004-address-masks_0
082114
@@ -0,0 +1,24 @@
082114
+#!/bin/bash
082114
+
082114
+set -e
082114
+
082114
+$XT_MULTI ip6tables-restore <
082114
+*filter
082114
+-A FORWARD -s feed:babe::/ffff::0
082114
+-A FORWARD -s feed:babe::/ffff:ff00::0
082114
+-A FORWARD -s feed:babe::/ffff:fff0::0
082114
+-A FORWARD -s feed:babe::/ffff:ffff::0
082114
+-A FORWARD -s feed:babe::/0:ffff::0
082114
+-A FORWARD -s feed:c0ff::babe:f00/ffff::ffff:0
082114
+COMMIT
082114
+EOF
082114
+
082114
+EXPECT='-P FORWARD ACCEPT
082114
+-A FORWARD -s feed::/16
082114
+-A FORWARD -s feed:ba00::/24
082114
+-A FORWARD -s feed:bab0::/28
082114
+-A FORWARD -s feed:babe::/32
082114
+-A FORWARD -s 0:babe::/0:ffff::
082114
+-A FORWARD -s feed::babe:0/ffff::ffff:0'
082114
+
082114
+diff -u -Z <(echo -e "$EXPECT") <($XT_MULTI ip6tables -S FORWARD)
082114
-- 
082114
2.31.1
082114