Blame SOURCES/0031-nft-Fix-for-broken-address-mask-match-detection.patch

87db66
From 74a62264d4615ae7f76454e7ca406c46a62c7999 Mon Sep 17 00:00:00 2001
87db66
From: Phil Sutter <phil@nwl.cc>
87db66
Date: Mon, 28 Sep 2020 18:57:18 +0200
87db66
Subject: [PATCH] nft: Fix for broken address mask match detection
87db66
87db66
Trying to decide whether a bitwise expression is needed to match parts
87db66
of a source or destination address only, add_addr() checks if all bytes
87db66
in 'mask' are 0xff or not. The check is apparently broken though as each
87db66
byte in 'mask' is cast to a signed char before comparing against 0xff,
87db66
therefore the bitwise is always added:
87db66
87db66
| # ./bad/iptables-nft -A foo -s 10.0.0.1 -j ACCEPT
87db66
| # ./good/iptables-nft -A foo -s 10.0.0.2 -j ACCEPT
87db66
| # nft --debug=netlink list chain ip filter foo
87db66
| ip filter foo 5
87db66
|   [ payload load 4b @ network header + 12 => reg 1 ]
87db66
|   [ bitwise reg 1 = (reg=1 & 0xffffffff ) ^ 0x00000000 ]
87db66
|   [ cmp eq reg 1 0x0100000a ]
87db66
|   [ counter pkts 0 bytes 0 ]
87db66
|   [ immediate reg 0 accept ]
87db66
|
87db66
| ip filter foo 6 5
87db66
|   [ payload load 4b @ network header + 12 => reg 1 ]
87db66
|   [ cmp eq reg 1 0x0200000a ]
87db66
|   [ counter pkts 0 bytes 0 ]
87db66
|   [ immediate reg 0 accept ]
87db66
|
87db66
| table ip filter {
87db66
| 	chain foo {
87db66
| 		ip saddr 10.0.0.1 counter packets 0 bytes 0 accept
87db66
| 		ip saddr 10.0.0.2 counter packets 0 bytes 0 accept
87db66
| 	}
87db66
| }
87db66
87db66
Fix the cast, safe an extra op and gain 100% performance in ideal cases.
87db66
87db66
Fixes: 56859380eb328 ("xtables-compat: avoid unneeded bitwise ops")
87db66
Signed-off-by: Phil Sutter <phil@nwl.cc>
87db66
(cherry picked from commit 72ed608bf1ea550ac13b5b880afc7ad3ffa0afd0)
87db66
Signed-off-by: Phil Sutter <psutter@redhat.com>
87db66
---
87db66
 iptables/nft-shared.c | 2 +-
87db66
 1 file changed, 1 insertion(+), 1 deletion(-)
87db66
87db66
diff --git a/iptables/nft-shared.c b/iptables/nft-shared.c
87db66
index 78e422781723f..f60f5df97fb86 100644
87db66
--- a/iptables/nft-shared.c
87db66
+++ b/iptables/nft-shared.c
87db66
@@ -165,7 +165,7 @@ void add_outiface(struct nftnl_rule *r, char *iface, uint32_t op)
87db66
 void add_addr(struct nftnl_rule *r, int offset,
87db66
 	      void *data, void *mask, size_t len, uint32_t op)
87db66
 {
87db66
-	const char *m = mask;
87db66
+	const unsigned char *m = mask;
87db66
 	int i;
87db66
 
87db66
 	add_payload(r, offset, len, NFT_PAYLOAD_NETWORK_HEADER);
87db66
-- 
87db66
2.28.0
87db66