Blame SOURCES/kvm-target-s390x-arch_dump-Fix-memory-corruption-in-s390.patch

97168e
From e1870dec813fa6f8482f4f27b7a9bef8c1584b6b Mon Sep 17 00:00:00 2001
97168e
From: Thomas Huth <thuth@redhat.com>
97168e
Date: Tue, 14 Feb 2023 14:48:37 +0100
97168e
Subject: [PATCH 3/3] target/s390x/arch_dump: Fix memory corruption in
97168e
 s390x_write_elf64_notes()
97168e
MIME-Version: 1.0
97168e
Content-Type: text/plain; charset=UTF-8
97168e
Content-Transfer-Encoding: 8bit
97168e
97168e
RH-Author: Thomas Huth <thuth@redhat.com>
97168e
RH-MergeRequest: 260: target/s390x/arch_dump: Fix memory corruption in s390x_write_elf64_notes()
97168e
RH-Bugzilla: 2168187
97168e
RH-Acked-by: David Hildenbrand <david@redhat.com>
97168e
RH-Acked-by: Cédric Le Goater <clg@redhat.com>
97168e
RH-Acked-by: Cornelia Huck <cohuck@redhat.com>
97168e
RH-Commit: [1/1] 67b71ed720a1f03d5bda9119969ea95fc4a6106d
97168e
97168e
Bugzilla: https://bugzilla.redhat.com/2168187
97168e
Upstream-Status: Posted (and reviewed, but not merged yet)
97168e
97168e
"note_size" can be smaller than sizeof(note), so unconditionally calling
97168e
memset(notep, 0, sizeof(note)) could cause a memory corruption here in
97168e
case notep has been allocated dynamically, thus let's use note_size as
97168e
length argument for memset() instead.
97168e
97168e
Fixes: 113d8f4e95 ("s390x: pv: Add dump support")
97168e
Message-Id: <20230214141056.680969-1-thuth@redhat.com>
97168e
Reviewed-by: Janosch Frank <frankja@linux.ibm.com>
97168e
Reviewed-by: Philippe Mathieu-Daudé <philmd@linaro.org>
97168e
Signed-off-by: Thomas Huth <thuth@redhat.com>
97168e
---
97168e
 target/s390x/arch_dump.c | 2 +-
97168e
 1 file changed, 1 insertion(+), 1 deletion(-)
97168e
97168e
diff --git a/target/s390x/arch_dump.c b/target/s390x/arch_dump.c
97168e
index a2329141e8..a7c44ba49d 100644
97168e
--- a/target/s390x/arch_dump.c
97168e
+++ b/target/s390x/arch_dump.c
97168e
@@ -248,7 +248,7 @@ static int s390x_write_elf64_notes(const char *note_name,
97168e
             notep = g_malloc(note_size);
97168e
         }
97168e
 
97168e
-        memset(notep, 0, sizeof(note));
97168e
+        memset(notep, 0, note_size);
97168e
 
97168e
         /* Setup note header data */
97168e
         notep->hdr.n_descsz = cpu_to_be32(content_size);
97168e
-- 
97168e
2.37.3
97168e