Received: by 2002:ac0:a5b6:0:0:0:0:0 with SMTP id m51-v6csp4796230imm; Wed, 30 May 2018 12:09:52 -0700 (PDT) X-Google-Smtp-Source: ADUXVKKaCS9QM+OjxU7Kq6HlJ8hOeqWP5UU/M0sBqP5aZxNAXYYatjfianl9UiiFW6CBwZS8LIbJ X-Received: by 2002:a63:36c1:: with SMTP id d184-v6mr3178963pga.224.1527707392742; Wed, 30 May 2018 12:09:52 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1527707392; cv=none; d=google.com; s=arc-20160816; b=HzYLSiK4OFVv2Zaz4CWCoRZLgixSrzEKBD9M0UStkcok6GySGRqZdLNddn/2R2Oz0a ISCO5Ewut4V/Zb7TyYuB/JcKAUKvKTLnQ+2worOvze/t3xsc/w2E0wr5YPj8K3iX6UX+ w7s/MLnx4RLnb2anUvFCd3KoKjKuQ54DEMb/vfbJRWuq5c+TUmdTlEv8+3ufgOuRSqkD wDV+VRMkqLoBJRyETNPBQcIecOc81A/EdeRvJoGjFZjb+KAWSASFC+ZL9oaDcF9F2nIr 1EJPNjKTMewLdo6qXNEIlAvI5xLV2pGi3asrZze4mOi9A3eaDV2PxCt9ZP7x9nG9Cg6w yn9A== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:cc:to:subject:message-id:date:from :references:in-reply-to:mime-version:dkim-signature:dkim-signature :arc-authentication-results; bh=bwfpFtbSwEEyF1FFpgQUvJBIRWI1n/Y72GevFM5r0qA=; b=OPR3ZgOrYPFLTnDHIbiUmwX066v1YYJLnLrQ0bQFYVCMCoTHLI2a4qPzYt1FEN5uZu Dzn8BZo9ChTcGAVUpbP9YNsafdWYwUhu4a0yBXzrktArRytES4wtk1deGJzkK7zxt9y6 6GY1ALyRbURumvLk1Fp4ckN/0oJZAU74WW4JGj8iRdm/MSABXtDjTC926Xs4ajQpilUe obcvA9giUoq9kSmXfeKkje8zZu+BGw8kgv1Rl1LLXs+4an2DXIF1UagHBHH32txgg/IC f36W9yF/eZnqAB9CJNKl6jZomkf3WBOQurIKXl7BagcuxQWCfiWLU2lbav/G2euESohA RqWQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@google.com header.s=20161025 header.b=bN3vw6h6; dkim=fail header.i=@chromium.org header.s=google header.b=nS6nPNlk; 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; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=chromium.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id b8-v6si37456005pls.261.2018.05.30.12.09.38; Wed, 30 May 2018 12:09:52 -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; dkim=fail header.i=@google.com header.s=20161025 header.b=bN3vw6h6; dkim=fail header.i=@chromium.org header.s=google header.b=nS6nPNlk; 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; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=chromium.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753799AbeE3TIM (ORCPT + 99 others); Wed, 30 May 2018 15:08:12 -0400 Received: from mail-ua0-f196.google.com ([209.85.217.196]:36113 "EHLO mail-ua0-f196.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753627AbeE3TIK (ORCPT ); Wed, 30 May 2018 15:08:10 -0400 Received: by mail-ua0-f196.google.com with SMTP id c23-v6so6735598uan.3 for ; Wed, 30 May 2018 12:08:09 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20161025; h=mime-version:sender:in-reply-to:references:from:date:message-id :subject:to:cc; bh=bwfpFtbSwEEyF1FFpgQUvJBIRWI1n/Y72GevFM5r0qA=; b=bN3vw6h6CadolluiT1++XjVablwHq5wLyAohwbD4Ck/u2K85RDGFDqZVxfDa0h6mlS RI7I1Tp1kikhFfp76SyCaEIgCV0J8mB+VIJw1dJQO5fFj5VUjTGGD1dQYKUwuZNHq9h/ 0UMl8vCfj/+isv0+5i+jYE4sBj3kGykV8ogGkIt/N98Zn1kqdOXPc62vKkYCPXqr9UrQ 2vQFqYub1gmePETo3lzebYY1Io05ifiDghB6mJEB7r1lsXcBVHNv3nmHwaozrxrNvPv1 byBPL6ua+I9rYC41qrHGXCz298svD0hNye7e0DzuwlyqiOVv75LW/XvMPxMWd8QisTi+ g4Gg== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; h=mime-version:sender:in-reply-to:references:from:date:message-id :subject:to:cc; bh=bwfpFtbSwEEyF1FFpgQUvJBIRWI1n/Y72GevFM5r0qA=; b=nS6nPNlkwa+EuhwDJ+aRKJRm7mSAMD9zXNn8ZIfny87fPJ3Lafb8wJBnPUW0RWkXgJ gAH5s1Z+KLwypNaJhqfmvqfI8HVD/ewWGBdctqBRPQdxbXOg9cQCdyfrotXbEdFzcUBh cpMDPj1pMPUiLX5IQkB5ku5mfrY0Wms5LQfA8= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:sender:in-reply-to:references:from :date:message-id:subject:to:cc; bh=bwfpFtbSwEEyF1FFpgQUvJBIRWI1n/Y72GevFM5r0qA=; b=ezX5QAKjZZvb0DEslAPNA7QDnWhfZ9VSm60ad5HbGvKng4Owmi8kb+v15d+/4jomaQ 9YOlQJH7SAjrtupCdWpUBdjcN5+wPgFqgMVb8rN6HGEYmLfqKIERJeGeVzUBXm/GeWeI 5KeHr1uAWxwebWsVvW+nWqQZu7A3D0n/X3Qj4w3nZCpHn7WFQP6cuiFbdO2x1+3BFLnD uzgNhnleiTzMHPVLsSwssO8GilWV7dG+DZWqEaZmvBn4BFT/jZk5AYlobDwPgset/R6t fF5p58TQrNBHKQjPUs4/dVwjx5yqoapKK2jCPzd7yIRqmOhFT8nidqb9aBZyeswb14xx p8ZQ== X-Gm-Message-State: ALKqPwexgY1wXxUxmjnF7rEl35QjdvbnUzEqGWfrIGTT/NTOwYNBGP/+ c7SgxAsNL2nBK8Lh0psTTja+uOfx7nx0d/M9qWoLHQ== X-Received: by 2002:ab0:2508:: with SMTP id j8-v6mr2583061uan.83.1527707288877; Wed, 30 May 2018 12:08:08 -0700 (PDT) MIME-Version: 1.0 Received: by 2002:a1f:a085:0:0:0:0:0 with HTTP; Wed, 30 May 2018 12:08:08 -0700 (PDT) In-Reply-To: <20180530095249.3jdhb5gdwt24cnsa@salvia> References: <20180530003525.GA18642@beast> <20180530095249.3jdhb5gdwt24cnsa@salvia> From: Kees Cook Date: Wed, 30 May 2018 12:08:08 -0700 X-Google-Sender-Auth: zWTbfo9p0wXrMR9hVJ_ugaMr0hA Message-ID: Subject: Re: [PATCH] netfilter: nfnetlink: Remove VLA usage To: Pablo Neira Ayuso Cc: Jozsef Kadlecsik , Florian Westphal , "David S. Miller" , netfilter-devel@vger.kernel.org, coreteam@netfilter.org, Network Development , LKML 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 On Wed, May 30, 2018 at 2:52 AM, Pablo Neira Ayuso wrote: > On Tue, May 29, 2018 at 05:35:25PM -0700, 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 >> >> MODULE_LICENSE("GPL"); >> MODULE_AUTHOR("Harald Welte "); >> @@ -37,6 +38,11 @@ MODULE_ALIAS_NET_PF_PROTO(PF_NETLINK, NETLINK_NETFILTER); >> rcu_dereference_protected(table[(id)].subsys, \ >> lockdep_nfnl_is_held((id))) >> >> +#define NFTA_MAX_ATTR max(max(max(NFTA_CHAIN_MAX, NFTA_FLOWTABLE_MAX),\ >> + max(NFTA_OBJ_MAX, NFTA_RULE_MAX)), \ >> + max(NFTA_TABLE_MAX, \ >> + max(NFTA_SET_ELEM_LIST_MAX, NFTA_SET_MAX))) > > This is very specific of nftables, there are other nf subsystems using > nfnetlink that may go over this maximum attribute value (grep from > "struct nfnetlink_subsystem"). Oops, yes. I see that now. > To remove the VLA, I think we need an artificial maximum attribute > that reasonably large enough. git grep insanity: $ for i in $(git grep -A10 'static .*struct nfnetlink_subsystem' | \ grep '\.cb\b' | awk '{print $NF}' | cut -d, -f1) do git grep -A100 'static .*'"$i\b"; done | \ grep '\.attr_count\b' | awk -F= '{print $NF}' | \ sed -e 's/ //g' | cut -d, -f1 | sort -u and manual counting gets me: CTA_EXPECT_MAX 12 CTA_MAX 25 CTA_TIMEOUT_MAX 6 IPSET_ATTR_CMD_MAX 11 NFACCT_MAX 9 NFCTH_MAX 7 NFQA_CFG_MAX 6 NFQA_MAX 21 NFTA_CHAIN_MAX 10 NFTA_COMPAT_MAX 4 NFTA_OBJ_MAX 8 NFTA_RULE_MAX 10 NFTA_SET_ELEM_LIST_MAX 5 NFTA_SET_MAX 17 NFTA_TABLE_MAX 6 NFULA_CFG_MAX 7 NFULA_MAX 20 OSF_ATTR_MAX 2 How about 32? As Florian suggested, I'll add the check in nfnetlink_subsys_register() with a WARN(). -Kees -- Kees Cook Pixel Security