linux-stable/arch/arm/lib
Kursad Oney 7b0e690456 ARM: 9321/1: memset: cast the constant byte to unsigned char
[ Upstream commit c0e824661f ]

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, #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: 1da177e4c3 ("Linux-2.6.12-rc2")
Reviewed-by: Ard Biesheuvel <ardb@kernel.org>
Reviewed-by: Linus Walleij <linus.walleij@linaro.org>
Signed-off-by: Kursad Oney <kursad.oney@broadcom.com>
Signed-off-by: Russell King (Oracle) <rmk+kernel@armlinux.org.uk>
Signed-off-by: Sasha Levin <sashal@kernel.org>
2023-11-20 10:29:19 +01:00
..
ashldi3.S
ashrdi3.S
backtrace.S
bitops.h ARM: 8843/1: use unified assembler in headers 2020-06-03 08:19:34 +02:00
bswapsdi2.S License cleanup: add SPDX GPL-2.0 license identifier to files with no license 2017-11-02 11:10:55 +01:00
call_with_stack.S
changebit.S
clear_user.S
clearbit.S
copy_from_user.S ARM: 8958/1: rename missed uaccess .fixup section 2020-03-20 11:55:59 +01:00
copy_page.S
copy_template.S
copy_to_user.S ARM: 8797/1: spectre-v1.1: harden __copy_to_user 2019-02-20 10:25:37 +01:00
csumipv6.S
csumpartial.S
csumpartialcopy.S
csumpartialcopygeneric.S
csumpartialcopyuser.S ARM: 8731/1: Fix csum_partial_copy_from_user() stack mismatch 2017-12-17 22:20:39 +00:00
delay-loop.S
delay.c
div64.S
ecard.S
findbit.S ARM: findbit: fix overflowing offset 2022-08-25 11:15:00 +02:00
floppydma.S
getuser.S ARM: 8813/1: Make aligned 2-byte getuser()/putuser() atomic on ARMv6+ 2019-12-13 08:51:10 +01:00
io-acorn.S
io-readsb.S
io-readsl.S
io-readsw-armv3.S
io-readsw-armv4.S
io-writesb.S
io-writesl.S
io-writesw-armv3.S
io-writesw-armv4.S
lib1funcs.S
lshrdi3.S
Makefile ARM: 8833/1: Ensure that NEON code always compiles with Clang 2019-04-05 22:33:08 +02:00
memchr.S
memcpy.S
memmove.S
memset.S ARM: 9321/1: memset: cast the constant byte to unsigned char 2023-11-20 10:29:19 +01:00
muldi3.S
putuser.S ARM: 8813/1: Make aligned 2-byte getuser()/putuser() atomic on ARMv6+ 2019-12-13 08:51:10 +01:00
setbit.S
strchr.S
strrchr.S
testchangebit.S
testclearbit.S
testsetbit.S
uaccess_with_memcpy.c ARM: 8797/1: spectre-v1.1: harden __copy_to_user 2019-02-20 10:25:37 +01:00
ucmpdi2.S
xor-neon.c ARM: crypto: comment out gcc warning that breaks clang builds 2022-08-11 12:48:41 +02:00