public inbox for qemu-devel@nongnu.org
 help / color / mirror / Atom feed
* [PATCH] hw/net/rocker: Avoid double-free of l2_flood.group_ids
@ 2026-03-24 19:35 Peter Maydell
  2026-03-25 10:00 ` Philippe Mathieu-Daudé
  0 siblings, 1 reply; 2+ messages in thread
From: Peter Maydell @ 2026-03-24 19:35 UTC (permalink / raw)
  To: qemu-devel; +Cc: Jiri Pirko, Jason Wang

In of_dpa_cmd_add_l2_flood(), we allocate memory for the
group->l2_flood.group_ids array, freeing any previous array.
However, in the error-exit path we free the group_ids memory but do
not clear the pointer to NULL.  This means that if the guest causes
us to take the error-exit path and then later call the function
again, we will try again to free the memory we already freed.

Fix this by clearing the group_ids pointer in the error exit
path, so we maintain the invariant of "either it points at
allocated memory, or it is NULL" (both being valid to g_free()).

Cc: qemu-stable@nongnu.org
Fixes: dc488f88806 ("rocker: add new rocker switch device")
Resolves: https://gitlab.com/qemu-project/qemu/-/work_items/3253
Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
---
 hw/net/rocker/rocker_of_dpa.c | 1 +
 1 file changed, 1 insertion(+)

diff --git a/hw/net/rocker/rocker_of_dpa.c b/hw/net/rocker/rocker_of_dpa.c
index 814f19afc5..3190a0e75c 100644
--- a/hw/net/rocker/rocker_of_dpa.c
+++ b/hw/net/rocker/rocker_of_dpa.c
@@ -2059,6 +2059,7 @@ static int of_dpa_cmd_add_l2_flood(OfDpa *of_dpa, OfDpaGroup *group,
 err_out:
     group->l2_flood.group_count = 0;
     g_free(group->l2_flood.group_ids);
+    group->l2_flood.group_ids = NULL;
     g_free(tlvs);
 
     return err;
-- 
2.43.0



^ permalink raw reply related	[flat|nested] 2+ messages in thread

* Re: [PATCH] hw/net/rocker: Avoid double-free of l2_flood.group_ids
  2026-03-24 19:35 [PATCH] hw/net/rocker: Avoid double-free of l2_flood.group_ids Peter Maydell
@ 2026-03-25 10:00 ` Philippe Mathieu-Daudé
  0 siblings, 0 replies; 2+ messages in thread
From: Philippe Mathieu-Daudé @ 2026-03-25 10:00 UTC (permalink / raw)
  To: Peter Maydell, qemu-devel; +Cc: Jiri Pirko, Jason Wang

On 24/3/26 20:35, Peter Maydell wrote:
> In of_dpa_cmd_add_l2_flood(), we allocate memory for the
> group->l2_flood.group_ids array, freeing any previous array.
> However, in the error-exit path we free the group_ids memory but do
> not clear the pointer to NULL.  This means that if the guest causes
> us to take the error-exit path and then later call the function
> again, we will try again to free the memory we already freed.
> 
> Fix this by clearing the group_ids pointer in the error exit
> path, so we maintain the invariant of "either it points at
> allocated memory, or it is NULL" (both being valid to g_free()).
> 
> Cc: qemu-stable@nongnu.org
> Fixes: dc488f88806 ("rocker: add new rocker switch device")
> Resolves: https://gitlab.com/qemu-project/qemu/-/work_items/3253
> Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
> ---
>   hw/net/rocker/rocker_of_dpa.c | 1 +
>   1 file changed, 1 insertion(+)

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


^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2026-03-25 10:00 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-03-24 19:35 [PATCH] hw/net/rocker: Avoid double-free of l2_flood.group_ids Peter Maydell
2026-03-25 10:00 ` Philippe Mathieu-Daudé

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox