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

[PATCH] ARM: 2653/1: Fix memset and memzero macro double-reference of parameters

Patch from Deepak Saxena

The current memset() and memzero() macros on ARM reference the
incoming parameters more than once and this can cause uninted
side-effects. The issue was found while debugging SCTP protocol
and with the specific usage of memzero(skb_put(skb,size),size).
This call would call skb_put(skb,size) twice leading to badness.
The fixed version copies the incoming parameters into local
variables and uses those instead.

Signed-off-by: Deepak Saxena
Signed-off-by: Russell King

authored by

Deepak Saxena and committed by
Russell King
2fac6f3f 41130d37

+12 -5
+12 -5
include/asm-arm/string.h
··· 29 29 30 30 #define memset(p,v,n) \ 31 31 ({ \ 32 - if ((n) != 0) { \ 32 + void *__p = (p); size_t __n = n; \ 33 + if ((__n) != 0) { \ 33 34 if (__builtin_constant_p((v)) && (v) == 0) \ 34 - __memzero((p),(n)); \ 35 + __memzero((__p),(__n)); \ 35 36 else \ 36 - memset((p),(v),(n)); \ 37 + memset((__p),(v),(__n)); \ 37 38 } \ 38 - (p); \ 39 + (__p); \ 39 40 }) 40 41 41 - #define memzero(p,n) ({ if ((n) != 0) __memzero((p),(n)); (p); }) 42 + #define memzero(p,n) \ 43 + ({ \ 44 + void *__p = (p); size_t __n = n; \ 45 + if ((__n) != 0) \ 46 + __memzero((__p),(__n)); \ 47 + (__p); \ 48 + }) 42 49 43 50 #endif