2
0
mirror of https://github.com/edk2-porting/linux-next.git synced 2024-12-23 04:34:11 +08:00
linux-next/drivers/staging/unisys
Tim Sell a5eb2188f5 staging: unisys: visorbus: address theoretical int overflows
Add necessary casting to several places where we were doing 32-bit
arithmetic (unsigned) to produce a 64-bit (unsigned long) result, to
prevent the theoretical possibility of a 32-bit overflow during the
arithmetic.

FYI, these are unsigned long:

	ctx->param_bytes
	ctx->allocbytes

These are unsigned int:

	bytes
	phdr->name_offset
	phdr->name_length

Here is the test program demonstrating why we really need the casts:

void main()
{
	unsigned int i;
	unsigned long il;

	printf("sizeof(int) =%dn",sizeof(i));
	printf("sizeof(long)=%dn",sizeof(il));

	i = (unsigned int)((((unsigned long)(1)) << 32) - 1);
	printf("i                     = %un", i);
	il = i+1;
	printf("adding 1 withOUT cast = %lun", il);
	il = (unsigned long)i+1;
	printf("adding 1 WITH    cast = %lun", il);
}
[selltc@mac tmp]$ gcc x.c -o x.out
[selltc@mac tmp]$ ./x.out
sizeof(int) =4
sizeof(long)=8
i                     = 4294967295
adding 1 withOUT cast = 0
adding 1 WITH    cast = 4294967296

Signed-off-by: Tim Sell <Timothy.Sell@unisys.com>
Reported-by: Dan Carpenter <dan.carpenter@oracle.com>
Signed-off-by: David Kershner <david.kershner@unisys.com>
Reviewed-by: David Binder <david.binder@unisys.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
2017-11-28 14:20:50 +01:00
..
Documentation staging: unisys: Switch to use new generic UUID API 2017-08-22 14:56:03 -07:00
include staging: unisys: Remove redundant license text 2017-11-28 13:20:46 +01:00
visorbus staging: unisys: visorbus: address theoretical int overflows 2017-11-28 14:20:50 +01:00
visorhba staging: unisys: Remove redundant license text 2017-11-28 13:20:46 +01:00
visorinput staging: unisys: Remove redundant license text 2017-11-28 13:20:46 +01:00
visornic staging: unisys: Remove redundant license text 2017-11-28 13:20:46 +01:00
Kconfig staging: unisys: visorhid: rename to visorinput 2015-10-04 09:53:34 +01:00
MAINTAINERS staging: unisys: Fix incorrect unisys MAINTAINERS pattern 2017-11-02 11:45:57 +01:00
Makefile staging: unisys: visorhid: rename to visorinput 2015-10-04 09:53:34 +01:00
TODO staging: unisys: documentation and TODO tweaks 2015-09-12 18:24:43 -07:00