linux/drivers/virt
Len Baker 746f1b0ac5 virt: acrn: Prefer array_size and struct_size over open coded arithmetic
As noted in the "Deprecated Interfaces, Language Features, Attributes,
and Conventions" documentation [1], size calculations (especially
multiplication) should not be performed in memory allocator (or similar)
function arguments due to the risk of them overflowing. This could lead
to values wrapping around and a smaller allocation being made than the
caller was expecting. Using those allocations could lead to linear
overflows of heap memory and other misbehaviors.

So, use the array_size() helper to do the arithmetic instead of the
argument "count * size" in the vzalloc() function.

Also, take the opportunity to add a flexible array member of struct
vm_memory_region_op to the vm_memory_region_batch structure. And then,
change the code accordingly and use the struct_size() helper to do the
arithmetic instead of the argument "size + size * count" in the kzalloc
function.

This code was detected with the help of Coccinelle and audited and fixed
manually.

[1] https://www.kernel.org/doc/html/latest/process/deprecated.html#open-coded-arithmetic-in-allocator-arguments

Acked-by: Fei Li <fei1.li@intel.com>
Signed-off-by: Len Baker <len.baker@gmx.com>
Signed-off-by: Gustavo A. R. Silva <gustavoars@kernel.org>
2022-04-26 10:20:10 -05:00
..
acrn virt: acrn: Prefer array_size and struct_size over open coded arithmetic 2022-04-26 10:20:10 -05:00
nitro_enclaves Merge 5.16-rc8 into char-misc-next 2022-01-03 13:44:38 +01:00
vboxguest virt: vbox: Do not use wait_event_interruptible when called from kernel context 2021-01-27 14:37:02 +01:00
fsl_hypervisor.c virt: fsl_hypervisor: Directly return 0 instead of using local ret variable 2022-03-18 13:49:00 +01:00
Kconfig virt: vmgenid: notify RNG of VM fork and supply generation ID 2022-03-12 18:00:56 -07:00
Makefile virt: vmgenid: notify RNG of VM fork and supply generation ID 2022-03-12 18:00:56 -07:00
vmgenid.c virt: vmgenid: recognize new CID added by Hyper-V 2022-03-25 08:49:40 -06:00