Received: by 10.192.165.148 with SMTP id m20csp578352imm; Wed, 25 Apr 2018 04:35:31 -0700 (PDT) X-Google-Smtp-Source: AIpwx4+IUwZMZYodLmF3HoDHA6re7dqRvBXo/AdU8YFx0G+c1IOxctFIDCWb2t9HEvgnn/2Y7NWD X-Received: by 2002:a17:902:70c7:: with SMTP id l7-v6mr28205074plt.165.1524656130984; Wed, 25 Apr 2018 04:35:30 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1524656130; cv=none; d=google.com; s=arc-20160816; b=m+D6L2iqiIuRnqKM5ukcaw3NBeR1lm9IFj4NvJ35Y6bbXaId+SXUcKeXAW1yK/tEDp js+6i3vWE0YCqDYXMGyqQxcHkZOtRBwcfjOukVdc5iIYHCCZf4ehmoYX43OSgm73RoTS Vwz93XYN3aTpLNVzEDX+rNvlONDcMPC8QXxpYLRrJdgk2ghNbiFMDtO3EzeO7OyP81e3 DuxMo06vxJ/CPW3KPOu4N/0lKYRaVPjAs44HtD5x9aBZNmK2onFriyY6hCNKnwc2/Ai8 SOjHgex0LSXzqgf2K6rU234PawjEMDnOOCsaTv2Z/f/moeBhvaLTh5/SFkftAJ+9xuiW Jj0w== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:mime-version:user-agent:references :in-reply-to:message-id:date:subject:cc:to:from :arc-authentication-results; bh=TqZZ/+l+If203eUtv4WVbu/aOIwWieH8owalSMc1GSQ=; b=pkeeYy+d99jDefSoj0oKhG/8gKTNAuV5afvf1OGcueyjiktKi7Jr7PgSwMHsdvPT/b h7gRnzEu3Y7m6gGo+2ipWK/6E6T/vj4WXAsvZklygIDK5lCkJeqM0pDkuNyafPmv8ls/ O4p+KcwE6HlaCzGUokrt2OVxPKGwrBnv7uqczpMlfbOkpy9gNGlMf6QIQ6xKstyDFA3E zpwXpUt7efEpgNi40WwV+PNlU9vT+ZqbIrN2tTvotpzKvT9lrDEmJzB98fD+kOodJxDo 5ZrtuKk+qwwlTMLWap/N72OJb5K/E0pasCBNGU39n3eqWJUjhGTGIbISDp0KsuQ2aPuZ AM7w== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id q124si13594606pgq.215.2018.04.25.04.35.16; Wed, 25 Apr 2018 04:35:30 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752775AbeDYKea (ORCPT + 99 others); Wed, 25 Apr 2018 06:34:30 -0400 Received: from mail.linuxfoundation.org ([140.211.169.12]:50822 "EHLO mail.linuxfoundation.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752418AbeDYKeT (ORCPT ); Wed, 25 Apr 2018 06:34:19 -0400 Received: from localhost (LFbn-1-12247-202.w90-92.abo.wanadoo.fr [90.92.61.202]) by mail.linuxfoundation.org (Postfix) with ESMTPSA id 4805A49B; Wed, 25 Apr 2018 10:34:18 +0000 (UTC) From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Florian Westphal , Pablo Neira Ayuso Subject: [PATCH 4.16 19/26] netfilter: x_tables: add counters allocation wrapper Date: Wed, 25 Apr 2018 12:33:28 +0200 Message-Id: <20180425103315.615148947@linuxfoundation.org> X-Mailer: git-send-email 2.17.0 In-Reply-To: <20180425103314.842517924@linuxfoundation.org> References: <20180425103314.842517924@linuxfoundation.org> User-Agent: quilt/0.65 X-stable: review MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 4.16-stable review patch. If anyone has any objections, please let me know. ------------------ From: Florian Westphal commit c84ca954ac9fa67a6ce27f91f01e4451c74fd8f6 upstream. allows to have size checks in a single spot. This is supposed to reduce oom situations when fuzz-testing xtables. Signed-off-by: Florian Westphal Signed-off-by: Pablo Neira Ayuso Signed-off-by: Greg Kroah-Hartman --- include/linux/netfilter/x_tables.h | 1 + net/ipv4/netfilter/arp_tables.c | 2 +- net/ipv4/netfilter/ip_tables.c | 2 +- net/ipv6/netfilter/ip6_tables.c | 2 +- net/netfilter/x_tables.c | 15 +++++++++++++++ 5 files changed, 19 insertions(+), 3 deletions(-) --- a/include/linux/netfilter/x_tables.h +++ b/include/linux/netfilter/x_tables.h @@ -301,6 +301,7 @@ int xt_data_to_user(void __user *dst, co void *xt_copy_counters_from_user(const void __user *user, unsigned int len, struct xt_counters_info *info, bool compat); +struct xt_counters *xt_counters_alloc(unsigned int counters); struct xt_table *xt_register_table(struct net *net, const struct xt_table *table, --- a/net/ipv4/netfilter/arp_tables.c +++ b/net/ipv4/netfilter/arp_tables.c @@ -895,7 +895,7 @@ static int __do_replace(struct net *net, struct arpt_entry *iter; ret = 0; - counters = vzalloc(num_counters * sizeof(struct xt_counters)); + counters = xt_counters_alloc(num_counters); if (!counters) { ret = -ENOMEM; goto out; --- a/net/ipv4/netfilter/ip_tables.c +++ b/net/ipv4/netfilter/ip_tables.c @@ -1057,7 +1057,7 @@ __do_replace(struct net *net, const char struct ipt_entry *iter; ret = 0; - counters = vzalloc(num_counters * sizeof(struct xt_counters)); + counters = xt_counters_alloc(num_counters); if (!counters) { ret = -ENOMEM; goto out; --- a/net/ipv6/netfilter/ip6_tables.c +++ b/net/ipv6/netfilter/ip6_tables.c @@ -1075,7 +1075,7 @@ __do_replace(struct net *net, const char struct ip6t_entry *iter; ret = 0; - counters = vzalloc(num_counters * sizeof(struct xt_counters)); + counters = xt_counters_alloc(num_counters); if (!counters) { ret = -ENOMEM; goto out; --- a/net/netfilter/x_tables.c +++ b/net/netfilter/x_tables.c @@ -1199,6 +1199,21 @@ static int xt_jumpstack_alloc(struct xt_ return 0; } +struct xt_counters *xt_counters_alloc(unsigned int counters) +{ + struct xt_counters *mem; + + if (counters == 0 || counters > INT_MAX / sizeof(*mem)) + return NULL; + + counters *= sizeof(*mem); + if (counters > XT_MAX_TABLE_SIZE) + return NULL; + + return vzalloc(counters); +} +EXPORT_SYMBOL(xt_counters_alloc); + struct xt_table_info * xt_replace_table(struct xt_table *table, unsigned int num_counters,