From mboxrd@z Thu Jan 1 00:00:00 1970 From: Stefano Brivio Subject: Re: [PATCH v2] net: ipv6: xfrm6_state: remove VLA usage Date: Sat, 10 Mar 2018 19:26:44 +0100 Message-ID: <20180310192644.3fcbb69d@epycfail> References: <1520667645-21975-1-git-send-email-andreaschristofo@gmail.com> <20180310094327.685d181d@epycfail> Mime-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit Cc: Andreas Christoforou , Kernel Hardening , Steffen Klassert , Herbert Xu , "David S. Miller" , Alexey Kuznetsov , Hideaki YOSHIFUJI , Network Development , LKML To: Kees Cook Return-path: In-Reply-To: Sender: linux-kernel-owner@vger.kernel.org List-Id: netdev.vger.kernel.org On Sat, 10 Mar 2018 09:18:46 -0800 Kees Cook wrote: > On Sat, Mar 10, 2018 at 12:43 AM, Stefano Brivio wrote: > > On Sat, 10 Mar 2018 09:40:44 +0200 > > Andreas Christoforou wrote: > > > >> diff --git a/net/ipv6/xfrm6_state.c b/net/ipv6/xfrm6_state.c > >> index b15075a..270a53a 100644 > >> --- a/net/ipv6/xfrm6_state.c > >> +++ b/net/ipv6/xfrm6_state.c > >> @@ -62,7 +62,7 @@ __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[XFRM_MAX_DEPTH]; > >> > >> memset(count, 0, sizeof(count)); > > > > Can you perhaps initialize 'count' instead of calling memset(), now? > > Do you mean: > > int count[XFRM_MAX_DEPTH] = { }; > > instead of the memset()? Yep. > I thought the compiler would resolve these both to the same thing? Yes, for all practical purposes. With gcc 7.3.0 for x86_64, starting from -O1, it's exactly the same. With e.g. gcc 4.4.7, even with -O3, they can be a bit different depending on context. > The former looks better though! :) Yep! :) -- Stefano