net: ipv6: xfrm6_state: remove VLA usage
Subsystems (3)
PATCH 1/1 net: ipv6: xfrm6_state: remove VLA usage
The kernel would like to have all stack VLA usage removed[1].
--- net/ipv6/xfrm6_state.c | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-)
net/ipv6/xfrm6_state.c +7 -1
@@ -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 ; }
Signature · 1 line
2.7.4
Steffen Klassert
maintainerQuoted 3 lines · Andreas Christoforou
The kernel would like to have all stack VLA usage removed[1].
Signed-off-by Andreas Christoforou <[email protected]>
Can you please explain why you want this change?
Quoted 26 lines · Andreas Christoforou
The kernel would like to have all stack VLA usage removed[1].
Signed-off-by Andreas Christoforou <[email protected]>--- net/ipv6/xfrm6_state.c | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-)net/ipv6/xfrm6_state.c +6
-1@@ -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));
net/ipv6/xfrm6_state.c __xfrm6_sort(void **dst, void **src, int n, int (*cmp)(void *p), int maxclass) · line 90
Quoted 6 lines
net/ipv6/xfrm6_state.c +1
-0@@ -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?
Cheers,
Mathias
Steffen Klassert
maintainerQuoted 31 lines · Mathias Krause
Quoted 29 lines · Andreas Christoforou
The kernel would like to have all stack VLA usage removed[1].
Signed-off-by Andreas Christoforou <[email protected]>--- net/ipv6/xfrm6_state.c | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-)net/ipv6/xfrm6_state.c +6
-1@@ -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 ; }
Quoted 7 lines
net/ipv6/xfrm6_state.c __xfrm6_sort(void **dst, void **src, int n, int (*cmp)(void *p), int maxclass) · line 90
Quoted 3 lines
net/ipv6/xfrm6_state.c +1
-0+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_DEPTHas size for the count[] array, too?
Right, that's the way to go. Aside from that, allocating with GFP_KERNEL is definitely wrong here.
Right, thank you for your feedback I will create a new patch.
Kind Regards,
Andreas Christoforou
On Mar 9, 2018 15:02, "Steffen Klassert" <[email protected]> wrote:
Quoted 9 lines · Mathias Krause
Quoted 7 lines · Andreas Christoforou
The kernel would like to have all stack VLA usage removed[1].
Signed-off-by Andreas Christoforou <[email protected]>--- net/ipv6/xfrm6_state.c | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-)
Quoted 5 lines
net/ipv6/xfrm6_state.c __xfrm6_sort(void **dst, void **src, int n, int
Quoted 5 lines
net/ipv6/xfrm6_state.c +0
-0@@ -62,7 +62,12 @@ __xfrm6_sort(void **dst, void **src, int n, int
(*cmp)(void *p), int maxclass)
Quoted 11 lines
Quoted 11 lines
net/ipv6/xfrm6_state.c +6
-1{int i;int class[XFRM_MAX_DEPTH ]; -int count[maxclass]; +int *count; + + count =kcalloc (maxclass +1 ,sizeof (*count),GFP_KERNEL ); + +if (!count) +return -ENOMEM ;
Quoted 3 lines
net/ipv6/xfrm6_state.c __xfrm6_sort(void **dst, void **src, int n, int
Quoted 3 lines
net/ipv6/xfrm6_state.c +0
-0memset (count,0 ,sizeof (count));@@ -80,6 +85,7 @@ __xfrm6_sort(void **dst, void **src, int n, int
(*cmp)(void *p), int maxclass)
Quoted 10 lines
net/ipv6/xfrm6_state.c __xfrm6_sort(void **dst, void **src, int n, int (*cmp)(void *p), int maxclass) · line 90
Quoted 6 lines
net/ipv6/xfrm6_state.c +1
-0src[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_DEPTHas size for the count[] array, too?
Right, that's the way to go. Aside from that, allocating with GFP_KERNEL is definitely wrong here.
Hello!
Quoted 12 lines · Andreas Christoforou
The kernel would like to have all stack VLA usage removed[1].
Signed-off-by Andreas Christoforou <[email protected]>--- net/ipv6/xfrm6_state.c | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-)net/ipv6/xfrm6_state.c +0
-0
net/ipv6/xfrm6_state.c __xfrm6_sort(void **dst, void **src, int n, int (*cmp)(void *p), int maxclass) · line 68
Quoted 8 lines
net/ipv6/xfrm6_state.c +4
-1@@ -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 ); +
Empty line not needed here.
net/ipv6/xfrm6_state.c __xfrm6_sort(void **dst, void **src, int n, int (*cmp)(void *p), int maxclass) · line 73
Quoted 5 lines
net/ipv6/xfrm6_state.c +2
-0+if (!count) +return -ENOMEM ;memset (count,0 ,sizeof (count));
[...]
MBR, Sergei