Received: by 10.223.185.111 with SMTP id b44csp286860wrg; Fri, 9 Mar 2018 05:04:32 -0800 (PST) X-Google-Smtp-Source: AG47ELtmQM6WEA3dPoSMZQHEB9qf1uCMK3ug2rbHVQ4K+ErRGLrzavmk2zPzDZO30ql3Y+WSAH3v X-Received: by 10.98.62.14 with SMTP id l14mr30305276pfa.206.1520600672071; Fri, 09 Mar 2018 05:04:32 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1520600672; cv=none; d=google.com; s=arc-20160816; b=mGwszZPG78UXZ1wev1tb6wVCJKbxvZyxT0WQ9gWYnOPiiv5RV256+FwK9cqNjEnJCY F7fkvGyS8xCtwpGMcuTo5bnTZCdMCVgT3WfU0rHmRDHtatHjX2SnwLeBEc2thVY/w9gM FFpwX/AVbSqFy6118rINogAlfxis14xb7huVvtcMeRwT73gIuEpW41YeJ0OinaM50ZLd ObZlmyl04Nw0Ctk6sNePj3DSdGfDmywwIwB4m/HQxgGuAUwIys3QgykbKKnXd2/It0EO z+R5cKVOxpjgZaT6AScLGZ0k1Ky4kr0UI0uQzK/KL4H6/Lb4kXEa9hXwixhveXVudzTm K85A== 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=DjIv4j2F5OEBBmSkcM1mkpSH+SDuvSgKYUnPITgQTRw=; b=Edg/F25wNi0TTTnFelKJsS8lR46Sdt9VRX23D4fLFnMPRE/wcnGq+XShKcNolqnkYu 3hdJTkCjwgLXv7/0efFE/RRiI8ZNKFOqmCF1AGBoNwWHtDA0b9xIJQgwCKNJPZgX6adu Dm9NwRaby/E5jvEbb0mP/2FRzKR9132Y3vneQHoHG1+5pPAE2zM8BcYd0N3B34KMSkqj pNKMGNxgzgzspmd30eGKXFyr9ooG53Ca81HHjolrndLUgOekChmG4uA+SBiSrUz1LRSF HYlll0wlbgq0FXC5QyWiAZLZQiI3kQqeV5pfngoM9p/qbpeOjcpedHwGmfNi9zbrZ4NP 8tYw== 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 p11-v6si860874plr.628.2018.03.09.05.04.03; Fri, 09 Mar 2018 05:04:32 -0800 (PST) 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 S932147AbeCINCX (ORCPT + 99 others); Fri, 9 Mar 2018 08:02:23 -0500 Received: from a.mx.secunet.com ([62.96.220.36]:41624 "EHLO a.mx.secunet.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751059AbeCINCW (ORCPT ); Fri, 9 Mar 2018 08:02:22 -0500 Received: from localhost (localhost [127.0.0.1]) by a.mx.secunet.com (Postfix) with ESMTP id EC5DB201D7; Fri, 9 Mar 2018 14:02:20 +0100 (CET) X-Virus-Scanned: by secunet Received: from a.mx.secunet.com ([127.0.0.1]) by localhost (a.mx.secunet.com [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id jo1R_7K1YkzX; Fri, 9 Mar 2018 14:02:20 +0100 (CET) Received: from mail-essen-01.secunet.de (mail-essen-01.secunet.de [10.53.40.204]) (using TLSv1 with cipher ECDHE-RSA-AES256-SHA (256/256 bits)) (No client certificate requested) by a.mx.secunet.com (Postfix) with ESMTPS id 5F7E8201BE; Fri, 9 Mar 2018 14:02:20 +0100 (CET) Received: from gauss2.secunet.de (10.182.7.193) by mail-essen-01.secunet.de (10.53.40.204) with Microsoft SMTP Server id 14.3.382.0; Fri, 9 Mar 2018 14:02:20 +0100 Received: by gauss2.secunet.de (Postfix, from userid 1000) id 23C5F31824B1; Fri, 9 Mar 2018 14:02:20 +0100 (CET) Date: Fri, 9 Mar 2018 14:02:20 +0100 From: Steffen Klassert To: Mathias Krause CC: Andreas Christoforou , Kees Cook , , Herbert Xu , "David S. Miller" , Alexey Kuznetsov , Hideaki YOSHIFUJI , , Subject: Re: [PATCH] net: ipv6: xfrm6_state: remove VLA usage Message-ID: <20180309130220.is5i4qu3fdcmyngq@gauss3.secunet.de> References: <1520598106-3271-1-git-send-email-andreaschristofo@gmail.com> MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Disposition: inline In-Reply-To: User-Agent: NeoMutt/20170609 (1.8.3) X-G-Data-MailSecurity-for-Exchange-State: 0 X-G-Data-MailSecurity-for-Exchange-Error: 0 X-G-Data-MailSecurity-for-Exchange-Sender: 23 X-G-Data-MailSecurity-for-Exchange-Server: d65e63f7-5c15-413f-8f63-c0d707471c93 X-EXCLAIMER-MD-CONFIG: 2c86f778-e09b-4440-8b15-867914633a10 X-G-Data-MailSecurity-for-Exchange-Guid: CE3E31A6-8036-4C08-A898-A3929DBA210C Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Fri, Mar 09, 2018 at 01:49:07PM +0100, Mathias Krause wrote: > On 9 March 2018 at 13:21, Andreas Christoforou > wrote: > > The kernel would like to have all stack VLA usage removed[1]. > > > > Signed-off-by: Andreas Christoforou > > --- > > net/ipv6/xfrm6_state.c | 8 +++++++- > > 1 file changed, 7 insertions(+), 1 deletion(-) > > > > diff --git a/net/ipv6/xfrm6_state.c b/net/ipv6/xfrm6_state.c > > index b15075a..45c0d98 100644 > > --- a/net/ipv6/xfrm6_state.c > > +++ b/net/ipv6/xfrm6_state.c > > @@ -62,7 +62,12 @@ __xfrm6_sort(void **dst, void **src, int n, int (*cmp)(void *p), int maxclass) > > { > > int i; > > int class[XFRM_MAX_DEPTH]; > > - int count[maxclass]; > > + int *count; > > + > > + count = kcalloc(maxclass + 1, sizeof(*count), GFP_KERNEL); > > + > > + if (!count) > > + return -ENOMEM; > > > > memset(count, 0, sizeof(count)); > > > > @@ -80,6 +85,7 @@ __xfrm6_sort(void **dst, void **src, int n, int (*cmp)(void *p), int maxclass) > > src[i] = NULL; > > } > > > > + kfree(count); > > return 0; > > } > > Instead of dynamically allocating and freeing memory here, shouldn't > we just get rid of the maxclass parameter and use XFRM_MAX_DEPTH as > size for the count[] array, too? Right, that's the way to go. Aside from that, allocating with GFP_KERNEL is definitely wrong here.