Received: by 10.192.165.148 with SMTP id m20csp530497imm; Wed, 25 Apr 2018 03:46:11 -0700 (PDT) X-Google-Smtp-Source: AB8JxZoWx4rA3ABdsBo5H8IQoyTYWDgWhVeamPJTKaRCtLultz2BpG0WfLttGWvqoHMHICFPjSGL X-Received: by 10.99.171.5 with SMTP id p5mr4540364pgf.387.1524653171864; Wed, 25 Apr 2018 03:46:11 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1524653171; cv=none; d=google.com; s=arc-20160816; b=wvPt6eprNxsDVDMPIXR3NTi8lqX3PdbYcz6AUpSNzh5BA8199qZw7KUZFANjDcsvDm 2O6tNSHU3b2QigMmT56wqY0qGCeiq7KQgdm+swqD9yozM+nb5MzzOOAV2Lzg0wQ/7QVH mFWmLFV/GjUDLFJ2kfkd0vO2YXfWcy6TemLI6jZeKSMNch9qtLDtbb71oV6RoM/3vW23 dLnFROdzLL1TANauKcB7F7dtARmCQLTSyyy7u02QzOTvm2wwk5jSo1HE1M9Vq3n3FTDH 2xZhJyf8nZAhszRov7o/goTha6SmTGBce3clx+apkBkMpvtJi4FYvJMd9RqZKRTy4DvJ T0Dw== 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=E+zpVQE+wGnCAmhxSb7tut8yoB6cV1rmJoqUSTgglb0=; b=e9dgbLO/3Uf6K4kHdzk7eJcv0AX9tlVyHZChJxehaO/H8eF/vASUjIzBu/E9w22xx4 8wQs3YaTECes77v2JE3cFqXmP9LXJVyotNwViNasgqgIK+y1EvCqZjs727X2lJHMSzso AC0OAH0ZU2BAlbJQ3oKY4eQkhsTADuw7MWNyupRmEauc0sA70iObJM7Oigq+d1MKhT7+ nl8s+zofcrr3vCml3GXd9UESNhndReqIEGznIqEMeL7/hX9dH612/TlOmrq+/wyFjPZW 9GL71motS67dZuXFX1F6D5XpDlqMxfcypE5YkNK66VDxgnK/V2CfXVp48pw0IF+XomWm 6g+Q== 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 o14-v6si16157003pli.13.2018.04.25.03.45.57; Wed, 25 Apr 2018 03:46:11 -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 S1754428AbeDYKoo (ORCPT + 99 others); Wed, 25 Apr 2018 06:44:44 -0400 Received: from mail.linuxfoundation.org ([140.211.169.12]:53378 "EHLO mail.linuxfoundation.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1754416AbeDYKok (ORCPT ); Wed, 25 Apr 2018 06:44:40 -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 EF81C36; Wed, 25 Apr 2018 10:44:39 +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.14 175/183] netfilter: x_tables: add counters allocation wrapper Date: Wed, 25 Apr 2018 12:36:35 +0200 Message-Id: <20180425103249.541249009@linuxfoundation.org> X-Mailer: git-send-email 2.17.0 In-Reply-To: <20180425103242.532713678@linuxfoundation.org> References: <20180425103242.532713678@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.14-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 @@ -883,7 +883,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 @@ -1044,7 +1044,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 @@ -1063,7 +1063,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 @@ -1187,6 +1187,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,