Received: by 2002:ac0:a5b6:0:0:0:0:0 with SMTP id m51-v6csp4227844imm; Wed, 30 May 2018 01:20:36 -0700 (PDT) X-Google-Smtp-Source: ADUXVKKDwoosJ7Jvhr5SGjCSQ6w3lRZsjBvmoHd4zEbuRon/Pbbf+FI0TskCXiuTQCF8D2ogXmTH X-Received: by 2002:a62:df12:: with SMTP id u18-v6mr1842803pfg.230.1527668436027; Wed, 30 May 2018 01:20:36 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1527668436; cv=none; d=google.com; s=arc-20160816; b=YZdq9Qn/iCyt/JlwCcRfbPMGttCfMTwUpkET1Uy+d6R9PUZOcKT+hdlDq5XqtFR8Me pWhAF3Puz/Ef94IdzHOzXRW+f6BPXSP3SVqjcE//E9NAORgMlkCx4lDwnTFwR4GxHMo1 oCQwgOD2/l5Wb0EpwjxzcGLcdDkyoAPHFOptuyZyANDZ1la2EhDH0J+7qMgIKinVx1J0 qZH7/S226iW4HzM+EhBEbvaW46xSLSROcJwmJ3M7VOrkPGPaWvxUBxkaE8pmR2RGsdMW 2jCgIKuSAzxsCX4Ba+fIdWqBnaiJtBD+tm4Tb0GR3B+MVXSaLkWID0rWS5Uje5Ye8Nu+ kPtQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:user-agent:in-reply-to :content-disposition:mime-version:references:message-id:subject:cc :to:from:date:arc-authentication-results; bh=uBjiXA5J0OxLKIAopIYKr8nYqrcF84r3Dm5QLHJB7K4=; b=I8W1IfMumDl80JUUAHEiE0qAh41OC9QTZhg41F4uCa4cKcb96vVt0I1MSthkmXhVva nrZHcYm29IqcYuHkQF+H15JkPyDngH3XxRUg6Go/PrvprtzmKyHruLctrtMeXT3af6H9 jtmsUM11JKb9Q+zxzcmGqrr6DEu00U9Teu5BktTB1chbDPivkA58HRm67dw3R7DU3jWI /vTl3yQdlP0gKrQli2GnxvyYiM3pIqn8e/FWKGubFGSQgCktAKZYBX1YwnzUFW1+Irwk GAggT/GiCfj8WHkTAs0P7pKmE/9aQFXhK0gDogI/VmYITDzAdD52nKU9Jus9iFL1sbGc QZSw== 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 g12-v6si35592738pfi.212.2018.05.30.01.20.22; Wed, 30 May 2018 01:20:36 -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 S1030327AbeE3ITa (ORCPT + 99 others); Wed, 30 May 2018 04:19:30 -0400 Received: from Chamillionaire.breakpoint.cc ([146.0.238.67]:42278 "EHLO Chamillionaire.breakpoint.cc" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S965177AbeE3IT1 (ORCPT ); Wed, 30 May 2018 04:19:27 -0400 Received: from fw by Chamillionaire.breakpoint.cc with local (Exim 4.89) (envelope-from ) id 1fNwKI-0001pV-K8; Wed, 30 May 2018 10:19:22 +0200 Date: Wed, 30 May 2018 10:19:22 +0200 From: Florian Westphal To: Kees Cook Cc: Pablo Neira Ayuso , Jozsef Kadlecsik , Florian Westphal , "David S. Miller" , netfilter-devel@vger.kernel.org, coreteam@netfilter.org, netdev@vger.kernel.org, linux-kernel@vger.kernel.org Subject: Re: [PATCH] netfilter: nfnetlink: Remove VLA usage Message-ID: <20180530081922.tckogxkmltw6cxn7@breakpoint.cc> References: <20180530003525.GA18642@beast> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20180530003525.GA18642@beast> User-Agent: NeoMutt/20170113 (1.7.2) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Kees Cook wrote: > In the quest to remove all stack VLA usage from the kernel[1], this > allocates the maximum size expected for all possible attrs and adds > a sanity-check to make sure nothing gets out of sync. > > [1] https://lkml.kernel.org/r/CA+55aFzCG-zNmZwX4A2FQpadafLfEzK6CC=qPXydAacU1RqZWA@mail.gmail.com > > Signed-off-by: Kees Cook > --- > net/netfilter/nfnetlink.c | 22 ++++++++++++++++++++-- > 1 file changed, 20 insertions(+), 2 deletions(-) > > diff --git a/net/netfilter/nfnetlink.c b/net/netfilter/nfnetlink.c > index 03ead8a9e90c..0cb395f9627e 100644 > --- a/net/netfilter/nfnetlink.c > +++ b/net/netfilter/nfnetlink.c > @@ -28,6 +28,7 @@ > > #include > #include > +#include > > const struct nfnetlink_subsystem __rcu *subsys; > @@ -185,11 +191,17 @@ static int nfnetlink_rcv_msg(struct sk_buff *skb, struct nlmsghdr *nlh, > { > int min_len = nlmsg_total_size(sizeof(struct nfgenmsg)); > u8 cb_id = NFNL_MSG_TYPE(nlh->nlmsg_type); > - struct nlattr *cda[ss->cb[cb_id].attr_count + 1]; > + struct nlattr *cda[NFTA_MAX_ATTR + 1]; > struct nlattr *attr = (void *)nlh + min_len; > int attrlen = nlh->nlmsg_len - min_len; > __u8 subsys_id = NFNL_SUBSYS_ID(type); > > + /* Sanity-check NFTA_MAX_ATTR */ > + if (ss->cb[cb_id].attr_count > NFTA_MAX_ATTR) { > + rcu_read_unlock(); > + return -ENOMEM; > + } Would you mind also adding check to nfnetlink_subsys_register, plus WARN()? That way we'll see that NFTA_MAX_ATTR isn't large enough by virtue of registration rather than actual use. Other than that this looks fine to me.