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