Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

xfrm: remove VLA usage in __xfrm6_sort()

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 <andreaschristofo@gmail.com>
Signed-off-by: Kees Cook <keescook@chromium.org>
Acked-by: Stefano Brivio <sbrivio@redhat.com>
Signed-off-by: Steffen Klassert <steffen.klassert@secunet.com>

authored by

Kees Cook and committed by
Steffen Klassert
c926ca16 cd027a54

+2 -4
+2 -4
net/ipv6/xfrm6_state.c
··· 60 60 static int 61 61 __xfrm6_sort(void **dst, void **src, int n, int (*cmp)(void *p), int maxclass) 62 62 { 63 - int i; 63 + int count[XFRM_MAX_DEPTH] = { }; 64 64 int class[XFRM_MAX_DEPTH]; 65 - int count[maxclass]; 66 - 67 - memset(count, 0, sizeof(count)); 65 + int i; 68 66 69 67 for (i = 0; i < n; i++) { 70 68 int c;