Commit 81a86f15 authored by Patrick McHardy's avatar Patrick McHardy Committed by Chris Wright

[PATCH] NETFILTER: xt_connbytes: fix division by zero

When the packet counter of a connection is zero a division by zero
occurs in div64_64(). Fix that by using zero as average value, which
is correct as long as the packet counter didn't overflow, at which
point we have lost anyway.

Additionally we're probably going to go back to 64 bit counters
in 2.6.21.

Based on patch from Jonas Berlin <xkr47@outerspace.dyndns.org>,
with suggestions from KOVACS Krisztian <hidden@balabit.hu>.
Signed-off-by: default avatarPatrick McHardy <kaber@trash.net>
Signed-off-by: default avatarChris Wright <chrisw@sous-sol.org>
parent 6e3e53bb
...@@ -52,6 +52,8 @@ match(const struct sk_buff *skb, ...@@ -52,6 +52,8 @@ match(const struct sk_buff *skb,
{ {
const struct xt_connbytes_info *sinfo = matchinfo; const struct xt_connbytes_info *sinfo = matchinfo;
u_int64_t what = 0; /* initialize to make gcc happy */ u_int64_t what = 0; /* initialize to make gcc happy */
u_int64_t bytes = 0;
u_int64_t pkts = 0;
const struct ip_conntrack_counter *counters; const struct ip_conntrack_counter *counters;
if (!(counters = nf_ct_get_counters(skb))) if (!(counters = nf_ct_get_counters(skb)))
...@@ -89,29 +91,22 @@ match(const struct sk_buff *skb, ...@@ -89,29 +91,22 @@ match(const struct sk_buff *skb,
case XT_CONNBYTES_AVGPKT: case XT_CONNBYTES_AVGPKT:
switch (sinfo->direction) { switch (sinfo->direction) {
case XT_CONNBYTES_DIR_ORIGINAL: case XT_CONNBYTES_DIR_ORIGINAL:
what = div64_64(counters[IP_CT_DIR_ORIGINAL].bytes, bytes = counters[IP_CT_DIR_ORIGINAL].bytes;
counters[IP_CT_DIR_ORIGINAL].packets); pkts = counters[IP_CT_DIR_ORIGINAL].packets;
break; break;
case XT_CONNBYTES_DIR_REPLY: case XT_CONNBYTES_DIR_REPLY:
what = div64_64(counters[IP_CT_DIR_REPLY].bytes, bytes = counters[IP_CT_DIR_REPLY].bytes;
counters[IP_CT_DIR_REPLY].packets); pkts = counters[IP_CT_DIR_REPLY].packets;
break; break;
case XT_CONNBYTES_DIR_BOTH: case XT_CONNBYTES_DIR_BOTH:
{ bytes = counters[IP_CT_DIR_ORIGINAL].bytes +
u_int64_t bytes; counters[IP_CT_DIR_REPLY].bytes;
u_int64_t pkts; pkts = counters[IP_CT_DIR_ORIGINAL].packets +
bytes = counters[IP_CT_DIR_ORIGINAL].bytes + counters[IP_CT_DIR_REPLY].packets;
counters[IP_CT_DIR_REPLY].bytes;
pkts = counters[IP_CT_DIR_ORIGINAL].packets+
counters[IP_CT_DIR_REPLY].packets;
/* FIXME_THEORETICAL: what to do if sum
* overflows ? */
what = div64_64(bytes, pkts);
}
break; break;
} }
if (pkts != 0)
what = div64_64(bytes, pkts);
break; break;
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment