OSDN Git Service

hw/net/fsl_etsec/rings.c: Avoid variable length array
authorPeter Maydell <peter.maydell@linaro.org>
Thu, 24 Aug 2023 15:32:21 +0000 (16:32 +0100)
committerJason Wang <jasowang@redhat.com>
Mon, 18 Sep 2023 06:36:13 +0000 (14:36 +0800)
commit2a6cb383e2ec7224d8631c3c0a324bff469c9c64
tree59136aca4b3b7e33553e4c5aadb38b278d252adc
parentcb039ef3d9e3112da01e1ecd9b136ac9809ef733
hw/net/fsl_etsec/rings.c: Avoid variable length array

In fill_rx_bd() we create a variable length array of size
etsec->rx_padding. In fact we know that this will never be
larger than 64 bytes, because rx_padding is set in rx_init_frame()
in a way that ensures it is only that large. Use a fixed sized
array and assert that it is big enough.

Since padd[] is now potentially rather larger than the actual
padding required, adjust the memset() we do on it to match the
size that we write with cpu_physical_memory_write(), rather than
clearing the entire array.

The codebase has very few VLAs, and if we can get rid of them all we
can make the compiler error on new additions.  This is a defensive
measure against security bugs where an on-stack dynamic allocation
isn't correctly size-checked (e.g.  CVE-2021-3527).

Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
Reviewed-by: Philippe Mathieu-Daudé <philmd@linaro.org>
Signed-off-by: Jason Wang <jasowang@redhat.com>
hw/net/fsl_etsec/rings.c