Received: by 10.213.65.68 with SMTP id h4csp44477imn; Mon, 12 Mar 2018 17:00:11 -0700 (PDT) X-Google-Smtp-Source: AG47ELtOsi9Vbl6xsBrHtoj2pGqUyddAjTkqM6BSYi/FIwEzyqAzrAbSP496sG/AYHH+pTByKt0h X-Received: by 2002:a17:902:64cf:: with SMTP id y15-v6mr5763298pli.49.1520899211561; Mon, 12 Mar 2018 17:00:11 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1520899211; cv=none; d=google.com; s=arc-20160816; b=CQpvQ9giJy+lls4LU/U1qvW5uSs2YfaZF/rX+njEaEmgfJhk8IzAxbgI7TQC/Sj9a5 X+2XQKMSSBv3myXRtNGbPMshEpc6N0YB/CBc+rzy6bZ0Wp/t+0VCC/oZ8Z1wBWd//kNN th7EFGj9t6yy0zo2IXhgLqBT/urRvYf7C2noP4rEys/Ng0GtwC3eIhgDg3NWvqVZn0kP 8G5sglGZC94IacQbGn+YlDiP2MgJHinN+JoIKwwwKce3qud1IyWMgOKpI0tv4E+SUUWR zmnC1WGmrQH5Pc8Dw1RdcnpdZ3As/KX7wZVrNbltho4ukfxOI+BqHJoFV/JbDQQLHvBI ugiQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :references:in-reply-to:date:cc:to:from:subject:message-id :arc-authentication-results; bh=dDx7SwBioHGGfE2CLD5rT5Z2mZ+9BJEYQOy99qg5x40=; b=un8TKJ2ACziA0/0ZXx4S851nyw0OaBhXQyRhAm0WxGt8xkqAWMxqULY/xQ830Zo6HY AsY4ZTm3Mwi7J6nt9dwClt3GDY3gUqG/RbDv2PAMagFeOz+2wldXp+edoEGvzew9v9cT 1nOGAx6P2qfF0S0DDQmcUiSLGDvr0Vzy1EKH4i99BqJJv+8sFTQm6iH2YCERQ2n9qmBj r1xVE9a5x/2PhEws/BkGN4qS4FcX5Uv3MkzW2pbrzPsTorKQ0Kt0HZYT+L1swqUS3Ee0 JNTdG8eT6sUdY+6o7If3E893dZPyUVIgzklLY1LIZrfZw7cRNAs5C+nX9w2x2YxPpFZi MESA== 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 e13si5704425pgu.821.2018.03.12.16.59.57; Mon, 12 Mar 2018 17:00: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 S932359AbeCLX6n (ORCPT + 99 others); Mon, 12 Mar 2018 19:58:43 -0400 Received: from smtprelay0190.hostedemail.com ([216.40.44.190]:56956 "EHLO smtprelay.hostedemail.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1751390AbeCLX6m (ORCPT ); Mon, 12 Mar 2018 19:58:42 -0400 Received: from filter.hostedemail.com (clb03-v110.bra.tucows.net [216.40.38.60]) by smtprelay04.hostedemail.com (Postfix) with ESMTP id 6C6AC180A68AE; Mon, 12 Mar 2018 23:58:41 +0000 (UTC) X-Session-Marker: 6A6F6540706572636865732E636F6D X-Spam-Summary: 2,0,0,,d41d8cd98f00b204,joe@perches.com,:::::::::::::::::::::::,RULES_HIT:41:355:379:541:599:960:966:968:973:988:989:1260:1277:1311:1313:1314:1345:1359:1373:1437:1515:1516:1518:1534:1541:1593:1594:1711:1730:1747:1777:1792:2196:2199:2393:2559:2562:2828:2894:3138:3139:3140:3141:3142:3353:3622:3865:3866:3867:3868:3870:3871:3872:3874:4250:4321:4385:4605:5007:6119:10004:10400:10848:11026:11232:11233:11658:11914:12043:12048:12438:12740:12760:12895:13069:13311:13357:13439:14096:14097:14659:14721:21080:21627:30012:30054:30070:30091,0,RBL:47.151.150.235:@perches.com:.lbl8.mailshell.net-62.8.0.100 64.201.201.201,CacheIP:none,Bayesian:0.5,0.5,0.5,Netcheck:none,DomainCache:0,MSF:not bulk,SPF:fn,MSBL:0,DNSBL:neutral,Custom_rules:0:0:0,LFtime:20,LUA_SUMMARY:none X-HE-Tag: range77_115edfc0a7f46 X-Filterd-Recvd-Size: 2836 Received: from XPS-9350 (unknown [47.151.150.235]) (Authenticated sender: joe@perches.com) by omf12.hostedemail.com (Postfix) with ESMTPA; Mon, 12 Mar 2018 23:58:39 +0000 (UTC) Message-ID: <1520899118.2049.24.camel@perches.com> Subject: Re: [PATCH] netfilter: cttimeout: remove VLA usage From: Joe Perches To: "Gustavo A. R. Silva" , 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" Date: Mon, 12 Mar 2018 16:58:38 -0700 In-Reply-To: <20180312231442.GA22071@embeddedgus> References: <20180312231442.GA22071@embeddedgus> Content-Type: text/plain; charset="ISO-8859-1" X-Mailer: Evolution 3.26.1-1 Mime-Version: 1.0 Content-Transfer-Encoding: 7bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Mon, 2018-03-12 at 18:14 -0500, Gustavo A. R. Silva wrote: > 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 [] > diff --git 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; Why not if unlikely(!...) > > - 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); kmalloc_array? > > - 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; > } >