Received: by 10.192.165.148 with SMTP id m20csp453340imm; Wed, 25 Apr 2018 02:13:28 -0700 (PDT) X-Google-Smtp-Source: AIpwx4+jaM5mhmC0XhGzW4WzDvscSP7CWbsGNFYFAGO2nZlLlDKQ5qK17NlhE1YIDG3W8V54KxDz X-Received: by 10.99.170.72 with SMTP id x8mr17539028pgo.398.1524647608907; Wed, 25 Apr 2018 02:13:28 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1524647608; cv=none; d=google.com; s=arc-20160816; b=F51GML5zw6RiQDXCHbAhg8eaugzTD0oBEU8JYskzDSmccfJfycZoeXe4wU4kfRjVm5 pRMfEunv34exmrJQBUvJ/9NzdR4XfjdKi2040LOuf1MmZENs6g3AlYfztLDsIshJVBCo u0IYjSHq5MiQeFq7jX8jlJ8Jm5k7qp0KOCxGh9O0KqjAP+v78We9zjFHicXEo+crObHn tHW8eRiTuQ+NG/1EwGIfxJLUSfRmnLfdj5ffM57ytJRAmHQ84lxEaGqfPeUo2wV/BrTR u+SVRZluLz27Ciuaseba1Ft8C0FblTIzylVNfFjxwK3RG9Qnc3FdP8s3aPg0tLVqSo7E zBVg== 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 :organization:references:in-reply-to:message-id:subject:cc:to:from :date:arc-authentication-results; bh=UhrqaoHQqm710R/O1jNlrtUNeSpedUku1ALX1/8JGUE=; b=ZmiPojGLRH6+7q3dlKbAzB8GMC19zSDqG5LjoSgiXoicGhtKi2i1RAIB2EiNU9Ptbl mLVg6zQyx6CYQIdebYf2CjHycMlOybtmYwSnetpm8muA+TpL2KKiojcVsjnmrxfsUNR+ 2mSf1W6TP08czaV56ruZZ9Sc+z/WXcbUF64TqGTWuqXrfuNM5ayP+tfpN3ejVd3xAvSF W0tWZpt0YONUBAj6YgWxY9nmAdUa5J+60JZUUbxY6RLYTqQA/+8xsn77Um8mg8q2kRz1 WhtROxZXNsxYkUfNYX/n4uoKjO+MLjgW8sT9hXTiJ/F5dSf3FQyJjPReHsSih7K4dDYr 8Jyw== 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; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=redhat.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id l12si3333467pga.536.2018.04.25.02.13.14; Wed, 25 Apr 2018 02:13:28 -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; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751804AbeDYJMA (ORCPT + 99 others); Wed, 25 Apr 2018 05:12:00 -0400 Received: from mx3-rdu2.redhat.com ([66.187.233.73]:57858 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1751565AbeDYJLz (ORCPT ); Wed, 25 Apr 2018 05:11:55 -0400 Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.rdu2.redhat.com [10.11.54.3]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 2C7798E692; Wed, 25 Apr 2018 09:11:55 +0000 (UTC) Received: from epycfail (ovpn-112-74.ams2.redhat.com [10.36.112.74]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 5B511111CA19; Wed, 25 Apr 2018 09:11:51 +0000 (UTC) Date: Wed, 25 Apr 2018 11:11:47 +0200 From: Stefano Brivio To: Kees Cook Cc: Andreas Christoforou , kernel-hardening@lists.openwall.com, Steffen Klassert , Herbert Xu , "David S. Miller" , Alexey Kuznetsov , Hideaki YOSHIFUJI , netdev@vger.kernel.org, linux-kernel@vger.kernel.org Subject: Re: [PATCH v3 ipsec-next] xfrm: remove VLA usage in __xfrm6_sort() Message-ID: <20180425111147.1ad6d2e1@epycfail> In-Reply-To: <20180424234651.GA30225@beast> References: <20180424234651.GA30225@beast> Organization: Red Hat MIME-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit X-Scanned-By: MIMEDefang 2.78 on 10.11.54.3 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.2]); Wed, 25 Apr 2018 09:11:55 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.2]); Wed, 25 Apr 2018 09:11:55 +0000 (UTC) for IP:'10.11.54.3' DOMAIN:'int-mx03.intmail.prod.int.rdu2.redhat.com' HELO:'smtp.corp.redhat.com' FROM:'sbrivio@redhat.com' RCPT:'' Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Hi Kees, On Tue, 24 Apr 2018 16:46:51 -0700 Kees Cook wrote: > In the quest to remove all stack VLA usage removed from the kernel[1], > just use XFRM_MAX_DEPTH as already done for the "class" array. In one > case, it'll do this loop up to 5, the other caller up to 6. > > [1] https://lkml.org/lkml/2018/3/7/621 > > Co-developed-by: Andreas Christoforou > Signed-off-by: Kees Cook > --- > v3: > - adjust Subject and commit log (Steffen) > - use "= { }" instead of memset() (Stefano) > - reorder variables (Stefano) > v2: > - use XFRM_MAX_DEPTH for "count" array (Steffen and Mathias). > --- > net/ipv6/xfrm6_state.c | 4 ++-- > 1 file changed, 2 insertions(+), 2 deletions(-) > > diff --git a/net/ipv6/xfrm6_state.c b/net/ipv6/xfrm6_state.c > index 16f434791763..eeb44b64ae7f 100644 > --- a/net/ipv6/xfrm6_state.c > +++ b/net/ipv6/xfrm6_state.c > @@ -60,9 +60,9 @@ xfrm6_init_temprop(struct xfrm_state *x, const struct xfrm_tmpl *tmpl, > static int > __xfrm6_sort(void **dst, void **src, int n, int (*cmp)(void *p), int maxclass) > { > - int i; > + int count[XFRM_MAX_DEPTH] = { }; > int class[XFRM_MAX_DEPTH]; > - int count[maxclass]; > + int i; > > memset(count, 0, sizeof(count)); I guess you forgot to remove the memset() here. Just to be clear, I think this is how it should look like: --- a/net/ipv6/xfrm6_state.c +++ b/net/ipv6/xfrm6_state.c @@ -60,11 +60,9 @@ xfrm6_init_temprop(struct xfrm_state *x, const struct xfrm_tmpl *tmpl, static int __xfrm6_sort(void **dst, void **src, int n, int (*cmp)(void *p), int maxclass) { - int i; + int count[XFRM_MAX_DEPTH] = { }; int class[XFRM_MAX_DEPTH]; - int count[maxclass]; - - memset(count, 0, sizeof(count)); + int i; for (i = 0; i < n; i++) { int c; -- Stefano