From patchwork Mon May 14 14:36:35 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Pablo Neira Ayuso X-Patchwork-Id: 159029 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by ozlabs.org (Postfix) with ESMTP id 2D4A7B7034 for ; Tue, 15 May 2012 00:36:46 +1000 (EST) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1755682Ab2ENOgo (ORCPT ); Mon, 14 May 2012 10:36:44 -0400 Received: from mail.us.es ([193.147.175.20]:48989 "EHLO mail.us.es" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1755354Ab2ENOgn (ORCPT ); Mon, 14 May 2012 10:36:43 -0400 Received: (qmail 13263 invoked from network); 14 May 2012 16:36:41 +0200 Received: from unknown (HELO us.es) (192.168.2.11) by us.es with SMTP; 14 May 2012 16:36:41 +0200 Received: (qmail 28050 invoked by uid 507); 14 May 2012 14:36:40 -0000 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on antivirus1 X-Spam-Level: X-Spam-Status: No, score=-99.2 required=7.5 tests=BAYES_50,SPF_HELO_FAIL, USER_IN_WHITELIST autolearn=disabled version=3.3.1 Received: from 127.0.0.1 by antivirus1 (envelope-from , uid 501) with qmail-scanner-2.08 (clamdscan: 0.97.4/14915. Clear:RC:1(127.0.0.1):. Processed in 0.051217 secs); 14 May 2012 14:36:40 -0000 Received: from unknown (HELO antivirus1) (127.0.0.1) by us.es with SMTP; 14 May 2012 14:36:40 -0000 Received: from 192.168.1.13 (192.168.1.13) by antivirus1 (F-Secure/fsigk_smtp/407/antivirus1); Mon, 14 May 2012 16:36:40 +0200 (CEST) X-Virus-Status: clean(F-Secure/fsigk_smtp/407/antivirus1) Received: (qmail 7033 invoked from network); 14 May 2012 16:36:58 +0200 Received: from 1984.lsi.us.es (HELO us.es) (1984lsi@150.214.188.80) by us.es with AES128-SHA encrypted SMTP; 14 May 2012 16:36:58 +0200 Date: Mon, 14 May 2012 16:36:35 +0200 From: Pablo Neira Ayuso To: David Laight Cc: netfilter-devel@vger.kernel.org, davem@davemloft.net, netdev@vger.kernel.org, Jozsef Kadlecsik Subject: Re: [PATCH 1/4] netfilter: ipset: fix timeout value overflow bug Message-ID: <20120514143635.GA12992@1984> References: <1336996023-20249-2-git-send-email-pablo@netfilter.org> MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: User-Agent: Mutt/1.5.20 (2009-06-14) Sender: netfilter-devel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: netfilter-devel@vger.kernel.org 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 ? From bcb0e955ae5ea5acb1b59fb59e4fcb1c8364994d Mon Sep 17 00:00:00 2001 From: Jozsef Kadlecsik 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 Signed-off-by: Pablo Neira Ayuso --- 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