[PATCH] hw/char/stm32l4x5_usart: Fix memory corruption by adding correct class_size

Thomas Huth posted 1 patch 2 weeks, 4 days ago
Patches applied successfully (tree, apply log)
git fetch https://github.com/patchew-project/qemu tags/patchew/20240429075908.36302-1-thuth@redhat.com
Maintainers: Arnaud Minier <arnaud.minier@telecom-paris.fr>, "Inès Varhol" <ines.varhol@telecom-paris.fr>, "Marc-André Lureau" <marcandre.lureau@redhat.com>, Paolo Bonzini <pbonzini@redhat.com>
hw/char/stm32l4x5_usart.c | 1 +
1 file changed, 1 insertion(+)
[PATCH] hw/char/stm32l4x5_usart: Fix memory corruption by adding correct class_size
Posted by Thomas Huth 2 weeks, 4 days ago
"make check-qtest-aarch64" recently started failing on FreeBSD builds,
and valgrind on Linux also detected that there is something fishy with
the new stm32l4x5-usart: The code forgot to set the correct class_size
here, so the various class_init functions in this file wrote beyond
the allocated buffer when setting the subc->type field.

Fixes: 4fb37aea7e ("hw/char: Implement STM32L4x5 USART skeleton")
Signed-off-by: Thomas Huth <thuth@redhat.com>
---
 hw/char/stm32l4x5_usart.c | 1 +
 1 file changed, 1 insertion(+)

diff --git a/hw/char/stm32l4x5_usart.c b/hw/char/stm32l4x5_usart.c
index 2627aab832..02f666308c 100644
--- a/hw/char/stm32l4x5_usart.c
+++ b/hw/char/stm32l4x5_usart.c
@@ -617,6 +617,7 @@ static const TypeInfo stm32l4x5_usart_types[] = {
         .parent         = TYPE_SYS_BUS_DEVICE,
         .instance_size  = sizeof(Stm32l4x5UsartBaseState),
         .instance_init  = stm32l4x5_usart_base_init,
+        .class_size     = sizeof(Stm32l4x5UsartBaseClass),
         .class_init     = stm32l4x5_usart_base_class_init,
         .abstract       = true,
     }, {
-- 
2.44.0
Re: [PATCH] hw/char/stm32l4x5_usart: Fix memory corruption by adding correct class_size
Posted by Peter Maydell 2 weeks, 3 days ago
On Mon, 29 Apr 2024 at 08:59, Thomas Huth <thuth@redhat.com> wrote:
>
> "make check-qtest-aarch64" recently started failing on FreeBSD builds,
> and valgrind on Linux also detected that there is something fishy with
> the new stm32l4x5-usart: The code forgot to set the correct class_size
> here, so the various class_init functions in this file wrote beyond
> the allocated buffer when setting the subc->type field.
>
> Fixes: 4fb37aea7e ("hw/char: Implement STM32L4x5 USART skeleton")
> Signed-off-by: Thomas Huth <thuth@redhat.com>
> ---



Applied to target-arm.next, thanks.

-- PMM
Re: [PATCH] hw/char/stm32l4x5_usart: Fix memory corruption by adding correct class_size
Posted by Philippe Mathieu-Daudé 2 weeks, 4 days ago
On 29/4/24 09:59, Thomas Huth wrote:
> "make check-qtest-aarch64" recently started failing on FreeBSD builds,
> and valgrind on Linux also detected that there is something fishy with
> the new stm32l4x5-usart: The code forgot to set the correct class_size
> here, so the various class_init functions in this file wrote beyond
> the allocated buffer when setting the subc->type field.
> 
> Fixes: 4fb37aea7e ("hw/char: Implement STM32L4x5 USART skeleton")
> Signed-off-by: Thomas Huth <thuth@redhat.com>
> ---
>   hw/char/stm32l4x5_usart.c | 1 +
>   1 file changed, 1 insertion(+)

Reviewed-by: Philippe Mathieu-Daudé <philmd@linaro.org>