qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] tests/plugins: fix use-after-free bug
@ 2024-03-11  8:16 Paolo Bonzini
  2024-03-11  8:26 ` Philippe Mathieu-Daudé
  2024-03-11  8:30 ` Philippe Mathieu-Daudé
  0 siblings, 2 replies; 3+ messages in thread
From: Paolo Bonzini @ 2024-03-11  8:16 UTC (permalink / raw)
  To: qemu-devel; +Cc: Alex Bennée

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)
-- 
2.43.2



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

* Re: [PATCH] tests/plugins: fix use-after-free bug
  2024-03-11  8:16 [PATCH] tests/plugins: fix use-after-free bug Paolo Bonzini
@ 2024-03-11  8:26 ` Philippe Mathieu-Daudé
  2024-03-11  8:30 ` Philippe Mathieu-Daudé
  1 sibling, 0 replies; 3+ messages in thread
From: Philippe Mathieu-Daudé @ 2024-03-11  8:26 UTC (permalink / raw)
  To: Paolo Bonzini, qemu-devel; +Cc: Alex Bennée

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>




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

* Re: [PATCH] tests/plugins: fix use-after-free bug
  2024-03-11  8:16 [PATCH] tests/plugins: fix use-after-free bug Paolo Bonzini
  2024-03-11  8:26 ` Philippe Mathieu-Daudé
@ 2024-03-11  8:30 ` Philippe Mathieu-Daudé
  1 sibling, 0 replies; 3+ messages in thread
From: Philippe Mathieu-Daudé @ 2024-03-11  8:30 UTC (permalink / raw)
  To: Paolo Bonzini, qemu-devel; +Cc: Alex Bennée, Pierrick Bouvier

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/


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

end of thread, other threads:[~2024-03-11  8:31 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2024-03-11  8:16 [PATCH] tests/plugins: fix use-after-free bug Paolo Bonzini
2024-03-11  8:26 ` Philippe Mathieu-Daudé
2024-03-11  8:30 ` 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;
as well as URLs for NNTP newsgroup(s).