diff mbox series

tests/plugins: fix use-after-free bug

Message ID 20240311081619.669832-1-pbonzini@redhat.com (mailing list archive)
State New, archived
Headers show
Series tests/plugins: fix use-after-free bug | expand

Commit Message

Paolo Bonzini March 11, 2024, 8:16 a.m. UTC
rec->count.score is inside rec, which is freed before rec->count.score is.
Reorder the instructions

Reported by Coverity as CID 1539967.

Cc: Alex Bennée <alex.bennee@linaro.org>
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
---
 contrib/plugins/howvec.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

Comments

Philippe Mathieu-Daudé March 11, 2024, 8:26 a.m. UTC | #1
On 11/3/24 09:16, Paolo Bonzini wrote:
> rec->count.score is inside rec, which is freed before rec->count.score is.
> Reorder the instructions
> 
> Reported by Coverity as CID 1539967.
> 
> Cc: Alex Bennée <alex.bennee@linaro.org>
> Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
> ---
>   contrib/plugins/howvec.c | 2 +-
>   1 file changed, 1 insertion(+), 1 deletion(-)

Reviewed-by: Philippe Mathieu-Daudé <philmd@linaro.org>
Philippe Mathieu-Daudé March 11, 2024, 8:30 a.m. UTC | #2
On 11/3/24 09:16, Paolo Bonzini wrote:
> rec->count.score is inside rec, which is freed before rec->count.score is.
> Reorder the instructions
> 
> Reported by Coverity as CID 1539967.
> 
> Cc: Alex Bennée <alex.bennee@linaro.org>
> Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
> ---
>   contrib/plugins/howvec.c | 2 +-
>   1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/contrib/plugins/howvec.c b/contrib/plugins/howvec.c
> index 2d10c87e0fb..94bbc53820a 100644
> --- a/contrib/plugins/howvec.c
> +++ b/contrib/plugins/howvec.c
> @@ -167,9 +167,9 @@ static gint cmp_exec_count(gconstpointer a, gconstpointer b)
>   static void free_record(gpointer data)
>   {
>       InsnExecCount *rec = (InsnExecCount *) data;
> +    qemu_plugin_scoreboard_free(rec->count.score);
>       g_free(rec->insn);
>       g_free(rec);
> -    qemu_plugin_scoreboard_free(rec->count.score);
>   }
>   
>   static void plugin_exit(qemu_plugin_id_t id, void *p)

Actually Pierrick sent the same:
https://lore.kernel.org/qemu-devel/20240311060456.218190-1-pierrick.bouvier@linaro.org/
diff mbox series

Patch

diff --git a/contrib/plugins/howvec.c b/contrib/plugins/howvec.c
index 2d10c87e0fb..94bbc53820a 100644
--- a/contrib/plugins/howvec.c
+++ b/contrib/plugins/howvec.c
@@ -167,9 +167,9 @@  static gint cmp_exec_count(gconstpointer a, gconstpointer b)
 static void free_record(gpointer data)
 {
     InsnExecCount *rec = (InsnExecCount *) data;
+    qemu_plugin_scoreboard_free(rec->count.score);
     g_free(rec->insn);
     g_free(rec);
-    qemu_plugin_scoreboard_free(rec->count.score);
 }
 
 static void plugin_exit(qemu_plugin_id_t id, void *p)