Received: by 10.213.65.68 with SMTP id h4csp30016imn; Mon, 12 Mar 2018 16:16:11 -0700 (PDT) X-Google-Smtp-Source: AG47ELvLwamP3Mb+er/FnOBIcui/4kitRGNaV75RXSVtGDIoiRkSKz7VzJyCx1hJTAH4prXJCHg0 X-Received: by 10.167.129.67 with SMTP id d3mr9604559pfn.108.1520896571006; Mon, 12 Mar 2018 16:16:11 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1520896570; cv=none; d=google.com; s=arc-20160816; b=mzbKT157s4FsH496Hgg6x0dsYkCBMoxvdpsu/XCe53Hr7W+qn+jAy7sN3jZx/Pnv31 uNYS+ztsCA6VX9oZzqaadZ+yQvkFkDk6peifGJVPp5LNUBc5w/J1pbO3m1CD/733TGXZ kx7sUXcV/rht1gSstpQuklZvIJTyUyR2g1BXrt11aMdhbCTSoQiYwX2uyskIjnjE0MSA 4I25vNRLA9z5jI55PXMkKl476QHHeT1bwBndzhGxu6AusCcvcQXvk1sZdsPTpVs6DDvT M81EpjqE/j+75WcQdXrIR/2UTJaf9UCn9pxhaU0RZZ6ddqe2fHQvdqA1n2RC+v1almzP 4eSA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:user-agent:content-disposition :mime-version:message-id:subject:cc:to:from:date :arc-authentication-results; bh=Lm+i3Sec4jyGmNMjmYuFo1mr+GiziO7V8zD2PJyFvlw=; b=yIJCYA0BfFb9CPeSSM1aAFVpIQxvV9P21iEIuVYBrtrblP1eouIYcWh+iBY7qhZlHH 0wheakvJ0dQBjBFnsrFcLrS3nTYXfsHrBQxR4f1Uyr01FJCybltLt1PPubGTUz2/DEiA nnlyc57fg7er+69eC8C3cL3np6AgB0EnrwcIPvuz+PG2FmPmRu2OZPuxRmrjQJKDzWcw gWb3svcbW6vDpKlAlbiS53YjIw45aYW5LYblcKpJRhAP02UnZl1EE7n+RJsl5c+0iBSq 8DPgvu4Ks+fBkF+TC1u1XLxgY5Oc7O9xzJyGaGnvYrrdDGOYNNmNako9bW+4ISM0d43Z hstg== 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 r8si5588777pgv.414.2018.03.12.16.15.57; Mon, 12 Mar 2018 16:16:10 -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 S1751603AbeCLXOq (ORCPT + 99 others); Mon, 12 Mar 2018 19:14:46 -0400 Received: from gateway20.websitewelcome.com ([192.185.47.18]:18429 "EHLO gateway20.websitewelcome.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751327AbeCLXOp (ORCPT ); Mon, 12 Mar 2018 19:14:45 -0400 Received: from cm17.websitewelcome.com (cm17.websitewelcome.com [100.42.49.20]) by gateway20.websitewelcome.com (Postfix) with ESMTP id 02038400E1634 for ; Mon, 12 Mar 2018 18:14:45 -0500 (CDT) Received: from gator4166.hostgator.com ([108.167.133.22]) by cmsmtp with SMTP id vWeSeUk7Fy2aLvWeSeyEZ3; Mon, 12 Mar 2018 18:14:44 -0500 Received: from [189.175.117.58] (port=45314 helo=embeddedgus) by gator4166.hostgator.com with esmtpa (Exim 4.89_1) (envelope-from ) id 1evWeS-0041Qd-4P; Mon, 12 Mar 2018 18:14:44 -0500 Date: Mon, 12 Mar 2018 18:14:42 -0500 From: "Gustavo A. R. Silva" To: Pablo Neira Ayuso , Jozsef Kadlecsik , Florian Westphal , "David S. Miller" Cc: netfilter-devel@vger.kernel.org, coreteam@netfilter.org, netdev@vger.kernel.org, linux-kernel@vger.kernel.org, Kernel Hardening , Kees Cook , "Gustavo A. R. Silva" Subject: [PATCH] netfilter: cttimeout: remove VLA usage Message-ID: <20180312231442.GA22071@embeddedgus> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline User-Agent: Mutt/1.5.24 (2015-08-30) X-AntiAbuse: This header was added to track abuse, please include it with any abuse report X-AntiAbuse: Primary Hostname - gator4166.hostgator.com X-AntiAbuse: Original Domain - vger.kernel.org X-AntiAbuse: Originator/Caller UID/GID - [47 12] / [47 12] X-AntiAbuse: Sender Address Domain - embeddedor.com X-BWhitelist: no X-Source-IP: 189.175.117.58 X-Source-L: No X-Exim-ID: 1evWeS-0041Qd-4P X-Source: X-Source-Args: X-Source-Dir: X-Source-Sender: (embeddedgus) [189.175.117.58]:45314 X-Source-Auth: gustavo@embeddedor.com X-Email-Count: 8 X-Source-Cap: Z3V6aWRpbmU7Z3V6aWRpbmU7Z2F0b3I0MTY2Lmhvc3RnYXRvci5jb20= X-Local-Domain: yes Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org In preparation to enabling -Wvla, remove VLA and replace it with dynamic memory allocation. From a security viewpoint, the use of Variable Length Arrays can be a vector for stack overflow attacks. Also, in general, as the code evolves it is easy to lose track of how big a VLA can get. Thus, we can end up having segfaults that are hard to debug. Also, fixed as part of the directive to remove all VLAs from the kernel: https://lkml.org/lkml/2018/3/7/621 Signed-off-by: Gustavo A. R. Silva --- net/netfilter/nfnetlink_cttimeout.c | 26 +++++++++++++++++--------- 1 file changed, 17 insertions(+), 9 deletions(-) diff --git a/net/netfilter/nfnetlink_cttimeout.c b/net/netfilter/nfnetlink_cttimeout.c index 6819300..dcd7bd3 100644 --- a/net/netfilter/nfnetlink_cttimeout.c +++ b/net/netfilter/nfnetlink_cttimeout.c @@ -51,19 +51,27 @@ ctnl_timeout_parse_policy(void *timeouts, const struct nf_conntrack_l4proto *l4proto, struct net *net, const struct nlattr *attr) { + struct nlattr **tb; int ret = 0; - if (likely(l4proto->ctnl_timeout.nlattr_to_obj)) { - struct nlattr *tb[l4proto->ctnl_timeout.nlattr_max+1]; + if (!l4proto->ctnl_timeout.nlattr_to_obj) + return 0; - ret = nla_parse_nested(tb, l4proto->ctnl_timeout.nlattr_max, - attr, l4proto->ctnl_timeout.nla_policy, - NULL); - if (ret < 0) - return ret; + tb = kcalloc(l4proto->ctnl_timeout.nlattr_max + 1, sizeof(*tb), + GFP_KERNEL); - ret = l4proto->ctnl_timeout.nlattr_to_obj(tb, net, timeouts); - } + if (!tb) + return -ENOMEM; + + ret = nla_parse_nested(tb, l4proto->ctnl_timeout.nlattr_max, attr, + l4proto->ctnl_timeout.nla_policy, NULL); + if (ret < 0) + goto err; + + ret = l4proto->ctnl_timeout.nlattr_to_obj(tb, net, timeouts); + +err: + kfree(tb); return ret; } -- 2.7.4