Skip to content

Commit 7b0e690

Browse files
Kursad Oneygregkh
authored andcommitted
ARM: 9321/1: memset: cast the constant byte to unsigned char
[ Upstream commit c0e8246 ] memset() description in ISO/IEC 9899:1999 (and elsewhere) says: The memset function copies the value of c (converted to an unsigned char) into each of the first n characters of the object pointed to by s. The kernel's arm32 memset does not cast c to unsigned char. This results in the following code to produce erroneous output: char a[128]; memset(a, -128, sizeof(a)); This is because gcc will generally emit the following code before it calls memset() : mov r0, r7 mvn r1, torvalds#127 ; 0x7f bl 00000000 <memset> r1 ends up with 0xffffff80 before being used by memset() and the 'a' array will have -128 once in every four bytes while the other bytes will be set incorrectly to -1 like this (printing the first 8 bytes) : test_module: -128 -1 -1 -1 test_module: -1 -1 -1 -128 The change here is to 'and' r1 with 255 before it is used. Fixes: 1da177e ("Linux-2.6.12-rc2") Reviewed-by: Ard Biesheuvel <[email protected]> Reviewed-by: Linus Walleij <[email protected]> Signed-off-by: Kursad Oney <[email protected]> Signed-off-by: Russell King (Oracle) <[email protected]> Signed-off-by: Sasha Levin <[email protected]>
1 parent df0daac commit 7b0e690

File tree

1 file changed

+1
-0
lines changed

1 file changed

+1
-0
lines changed

arch/arm/lib/memset.S

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
ENTRY(mmioset)
2020
ENTRY(memset)
2121
UNWIND( .fnstart )
22+
and r1, r1, #255 @ cast to unsigned char
2223
ands r3, r0, #3 @ 1 unaligned?
2324
mov ip, r0 @ preserve r0 as return value
2425
bne 6f @ 1

0 commit comments

Comments
 (0)