From: Pablo Neira Ayuso <pablo@netfilter.org>
To: David Laight <David.Laight@ACULAB.COM>
Cc: netfilter-devel@vger.kernel.org, davem@davemloft.net,
netdev@vger.kernel.org,
Jozsef Kadlecsik <kadlec@blackhole.kfki.hu>
Subject: Re: [PATCH 1/4] netfilter: ipset: fix timeout value overflow bug
Date: Mon, 14 May 2012 16:36:35 +0200 [thread overview]
Message-ID: <20120514143635.GA12992@1984> (raw)
In-Reply-To: <AE90C24D6B3A694183C094C60CF0A2F6026B6F0B@saturn3.aculab.com>
[-- Attachment #1: Type: text/plain, Size: 782 bytes --]
On Mon, May 14, 2012 at 03:19:49PM +0100, David Laight wrote:
>
> > --- a/include/linux/netfilter/ipset/ip_set_timeout.h
> > +++ b/include/linux/netfilter/ipset/ip_set_timeout.h
> > @@ -30,6 +30,10 @@ ip_set_timeout_uget(struct nlattr *tb)
> > {
> > unsigned int timeout = ip_set_get_h32(tb);
> >
> > + /* Normalize to fit into jiffies */
> > + if (timeout > UINT_MAX/1000)
> > + timeout = UINT_MAX/1000;
> > +
>
> Doesn't that rather assume that HZ is 1000 ?
Indeed. I overlooked that. Thanks David.
New patch attached fixing this. I've rebased my tree.
@Jozsef: BTW, why do we have
include/linux/netfilter/ipset/ip_set_timeout.h
living under include/linux ?
All definitions are private to the kernel. Why not moving that header
(and other similar) to include/net ?
[-- Attachment #2: 0001-netfilter-ipset-fix-timeout-value-overflow-bug.patch --]
[-- Type: text/x-diff, Size: 2645 bytes --]
>From bcb0e955ae5ea5acb1b59fb59e4fcb1c8364994d Mon Sep 17 00:00:00 2001
From: Jozsef Kadlecsik <kadlec@blackhole.kfki.hu>
Date: Mon, 7 May 2012 02:35:44 +0000
Subject: [PATCH] netfilter: ipset: fix timeout value overflow bug
Large timeout parameters could result wrong timeout values due to
an overflow at msec to jiffies conversion (reported by Andreas Herz)
[ This patch was mangled by Pablo Neira Ayuso since David Laight notices
that we were using hardcode 1000 instead of HZ to calculate the timeout ]
Signed-off-by: Jozsef Kadlecsik <kadlec@blackhole.kfki.hu>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
---
include/linux/netfilter/ipset/ip_set_timeout.h | 4 ++++
net/netfilter/xt_set.c | 15 +++++++++++++--
2 files changed, 17 insertions(+), 2 deletions(-)
diff --git a/include/linux/netfilter/ipset/ip_set_timeout.h b/include/linux/netfilter/ipset/ip_set_timeout.h
index 4792320..40a85b1 100644
--- a/include/linux/netfilter/ipset/ip_set_timeout.h
+++ b/include/linux/netfilter/ipset/ip_set_timeout.h
@@ -30,6 +30,10 @@ ip_set_timeout_uget(struct nlattr *tb)
{
unsigned int timeout = ip_set_get_h32(tb);
+ /* Normalize to fit into jiffies */
+ if (timeout > UINT_MAX/HZ)
+ timeout = UINT_MAX/HZ;
+
/* Userspace supplied TIMEOUT parameter: adjust crazy size */
return timeout == IPSET_NO_TIMEOUT ? IPSET_NO_TIMEOUT - 1 : timeout;
}
diff --git a/net/netfilter/xt_set.c b/net/netfilter/xt_set.c
index 0ec8138..15275e9 100644
--- a/net/netfilter/xt_set.c
+++ b/net/netfilter/xt_set.c
@@ -44,6 +44,14 @@ const struct ip_set_adt_opt n = { \
.cmdflags = cfs, \
.timeout = t, \
}
+#define ADT_MOPT(n, f, d, fs, cfs, t) \
+struct ip_set_adt_opt n = { \
+ .family = f, \
+ .dim = d, \
+ .flags = fs, \
+ .cmdflags = cfs, \
+ .timeout = t, \
+}
/* Revision 0 interface: backward compatible with netfilter/iptables */
@@ -296,11 +304,14 @@ static unsigned int
set_target_v2(struct sk_buff *skb, const struct xt_action_param *par)
{
const struct xt_set_info_target_v2 *info = par->targinfo;
- ADT_OPT(add_opt, par->family, info->add_set.dim,
- info->add_set.flags, info->flags, info->timeout);
+ ADT_MOPT(add_opt, par->family, info->add_set.dim,
+ info->add_set.flags, info->flags, info->timeout);
ADT_OPT(del_opt, par->family, info->del_set.dim,
info->del_set.flags, 0, UINT_MAX);
+ /* Normalize to fit into jiffies */
+ if (add_opt.timeout > UINT_MAX/HZ)
+ add_opt.timeout = UINT_MAX/HZ;
if (info->add_set.index != IPSET_INVALID_ID)
ip_set_add(info->add_set.index, skb, par, &add_opt);
if (info->del_set.index != IPSET_INVALID_ID)
--
1.7.10
next prev parent reply other threads:[~2012-05-14 14:36 UTC|newest]
Thread overview: 20+ messages / expand[flat|nested] mbox.gz Atom feed top
2012-05-14 11:46 [PATCH 0/4] netfilter fixes for 3.4-rc7 pablo
2012-05-14 11:47 ` [PATCH 1/4] netfilter: ipset: fix timeout value overflow bug pablo
2012-05-14 14:19 ` David Laight
2012-05-14 14:36 ` Pablo Neira Ayuso [this message]
2012-05-14 14:47 ` Eric Dumazet
2012-05-14 17:45 ` Jozsef Kadlecsik
2012-05-14 19:00 ` Pablo Neira Ayuso
2012-05-14 20:10 ` Pablo Neira Ayuso
2012-05-14 21:45 ` Jozsef Kadlecsik
2012-05-15 8:21 ` David Laight
2012-05-14 11:47 ` [PATCH 2/4] netfilter: ipset: fix hash size checking in kernel pablo
2012-05-14 11:47 ` [PATCH 3/4] netfilter: xt_CT: remove redundant header include pablo
2012-05-14 11:47 ` [PATCH 4/4] netfilter: nf_ct_h323: fix usage of MODULE_ALIAS_NFCT_HELPER pablo
2012-05-14 22:56 ` [PATCH 0/4] netfilter fixes for 3.4-rc7 David Miller
2012-05-14 23:25 ` Pablo Neira Ayuso
2012-05-16 18:41 ` Jozsef Kadlecsik
2012-05-16 19:18 ` David Miller
2012-05-16 19:34 ` Jozsef Kadlecsik
2012-05-16 19:39 ` David Miller
2012-05-16 19:48 ` Jozsef Kadlecsik
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20120514143635.GA12992@1984 \
--to=pablo@netfilter.org \
--cc=David.Laight@ACULAB.COM \
--cc=davem@davemloft.net \
--cc=kadlec@blackhole.kfki.hu \
--cc=netdev@vger.kernel.org \
--cc=netfilter-devel@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.