Skip to contentSkip to conversation

netfilter: xt_connbytes: handle negation correctly

PATCH Applied Florian Westphal 2 participants 2 messages Dec 16, 2011 – Dec 23, 2011

Subsystems (2)
lore
Share & tools
lore

Florian Westphal

author maintainer
#0 lore raw

PATCH 1/1 netfilter: xt_connbytes: handle negation correctly

"! --connbytes 23:42" should match if the packet/byte count is not in range.

As there is no explict "invert match" toggle in the match structure, userspace swaps the from and to arguments
(i.e., as if "--connbytes 42:23" were given).

However, "what <= 23 && what >= 42" will always be false.

Change things so we use "||" in case "from" is larger than "to".

This change may look like it breaks backwards compatibility when "to" is 0. However, older iptables binaries will refuse "connbytes 42:0", and current releases treat it to mean "! --connbytes 0:42",
so we should be fine.

---
 net/netfilter/xt_connbytes.c |    6 +++---
 1 files changed, 3 insertions(+), 3 deletions(-)
net/netfilter/xt_connbytes.c +3 -3
index 5b13850..9ddf1c3 100644
@@ -87,10 +87,10 @@ connbytes_mt(const struct sk_buff *skb, struct xt_action_param *par)
 		break;
 	}
 
-	if (sinfo->count.to)
+	if (sinfo->count.to >= sinfo->count.from)
 		return what <= sinfo->count.to && what >= sinfo->count.from;
-	else
-		return what >= sinfo->count.from;
+	else /* inverted */
+		return what < sinfo->count.to || what > sinfo->count.from;
 }
 
 static int connbytes_mt_check(const struct xt_mtchk_param *par)
Signature · 1 line
1.7.3.4
maintainer Applied
#1 lore raw
Quoted 6 lines · Florian Westphal

"! --connbytes 23:42" should match if the packet/byte count is not in range.

As there is no explict "invert match" toggle in the match structure, userspace swaps the from and to arguments
(i.e., as if "--connbytes 42:23" were given).

Quoted 8 lines

However, "what <= 23 && what >= 42" will always be false.

Change things so we use "||" in case "from" is larger than "to".

This change may look like it breaks backwards compatibility when "to" is 0. However, older iptables binaries will refuse "connbytes 42:0", and current releases treat it to mean "! --connbytes 0:42",
so we should be fine.

Applied, thanks Florian. I'll pass this for 3.2-rc inclusion.