Blame SOURCES/0003-gcore-fix-memory-allocation-failure-during-processin.patch

f17523
From 4cb65a0d9168778d120920418b968d05da10989f Mon Sep 17 00:00:00 2001
f17523
From: HATAYAMA Daisuke <d.hatayama@fujitsu.com>
f17523
Date: Fri, 25 Feb 2022 04:59:48 -0500
f17523
Subject: [PATCH 3/3] gcore: fix memory allocation failure during processing
f17523
 NT_AUXV note
f17523
f17523
For crash dumps generated using kernel-4.18.0-365.el8 or later on
f17523
CentOS stream 8, crash gcore command fails as follows:
f17523
f17523
    crash> gcore -v 7 -f 128 10604
f17523
    gcore: Opening file core.10604.test-dumpfilter ...
f17523
    gcore: done.
f17523
    gcore: Writing ELF header ...
f17523
    gcore:  done.
f17523
    gcore: Retrieving and writing note information ...
f17523
    gcore: zero-size memory allocation! (called from 7fd558ce1e05)
f17523
    Failed.
f17523
f17523
This memory allocation failure occurs in fill_auxv_note() that creates
f17523
NT_AUXV note due to saved_auxv entries of size and offset tables are
f17523
somehow 0.
f17523
f17523
This is because during the merge of the upstream kernel commit
f17523
1c33bb0507508af24fd754dd7123bd8e997fab2f (x86/elf: Support a new ELF
f17523
aux vector AT_MINSIGSTKSZ), location of saved_auxv of struct mm_struct
f17523
has been moved as workaround in order to avoid kABI breakage.
f17523
f17523
Fix this by using RHEL-specific location for saved_auxv if there is
f17523
member rh_reserved_saved_auxv in struct mm_struct.
f17523
f17523
Signed-off-by: HATAYAMA Daisuke <d.hatayama@fujitsu.com>
f17523
---
f17523
 src/libgcore/gcore_coredump.c | 54 +++++++++++++++++++++++++++++------
f17523
 1 file changed, 46 insertions(+), 8 deletions(-)
f17523
f17523
diff --git a/src/libgcore/gcore_coredump.c b/src/libgcore/gcore_coredump.c
f17523
index 6f57b21b62b6..c14cc116e951 100644
f17523
--- a/src/libgcore/gcore_coredump.c
f17523
+++ b/src/libgcore/gcore_coredump.c
f17523
@@ -18,6 +18,10 @@
f17523
 
f17523
 static struct elf_note_info *elf_note_info_init(void);
f17523
 
f17523
+static void get_auxv_size_addr(struct task_context *tc,
f17523
+			       size_t *size,
f17523
+			       ulong *addr);
f17523
+
f17523
 static void fill_prstatus_note(struct elf_note_info *info,
f17523
 			       struct task_context *tc,
f17523
 			       struct memelfnote *memnote);
f17523
@@ -923,18 +927,49 @@ compat_fill_prstatus_note(struct elf_note_info *info,
f17523
 
f17523
 #endif /* GCORE_ARCH_COMPAT */
f17523
 
f17523
+static void get_auxv_size_addr(struct task_context *tc,
f17523
+			       size_t *psize,
f17523
+			       ulong *paddr)
f17523
+{
f17523
+	size_t size;
f17523
+	ulong addr;
f17523
+
f17523
+	if (MEMBER_EXISTS("mm_struct", "rh_reserved_saved_auxv")) {
f17523
+		ulong mm_rh;
f17523
+
f17523
+		size = MEMBER_SIZE("mm_struct_rh", "saved_auxv");
f17523
+		readmem(task_mm(tc->task, FALSE) + MEMBER_OFFSET("mm_struct", "mm_rh"),
f17523
+			KVADDR,
f17523
+			&mm_rh,
f17523
+			sizeof(mm_rh),
f17523
+			"mm_struct mm_rh",
f17523
+			gcore_verbose_error_handle());
f17523
+		addr = mm_rh + MEMBER_OFFSET("mm_struct_rh", "saved_auxv");
f17523
+	} else {
f17523
+		size = MEMBER_SIZE("mm_struct", "saved_auxv");
f17523
+		addr = task_mm(tc->task, FALSE) +
f17523
+			MEMBER_OFFSET("mm_struct", "saved_auxv");
f17523
+	}
f17523
+
f17523
+	*psize = size;
f17523
+	*paddr = addr;
f17523
+}
f17523
+
f17523
 static void
f17523
 fill_auxv_note(struct elf_note_info *info, struct task_context *tc,
f17523
 	       struct memelfnote *memnote)
f17523
 {
f17523
 	ulong *auxv;
f17523
+	ulong addr;
f17523
+	size_t size;
f17523
 	int i;
f17523
 
f17523
-	auxv = (ulong *)GETBUF(MEMBER_SIZE("mm_struct", "saved_auxv"));
f17523
+	get_auxv_size_addr(tc, &size, &addr);
f17523
 
f17523
-	readmem(task_mm(tc->task, FALSE) +
f17523
-		MEMBER_OFFSET("mm_struct", "saved_auxv"), KVADDR, auxv,
f17523
-		MEMBER_SIZE("mm_struct", "saved_auxv"), "fill_auxv_note",
f17523
+	auxv = (ulong *)GETBUF(size);
f17523
+
f17523
+	readmem(addr, KVADDR, auxv,
f17523
+		size, "fill_auxv_note",
f17523
 		gcore_verbose_error_handle());
f17523
 
f17523
 	i = 0;
f17523
@@ -954,13 +989,16 @@ compat_fill_auxv_note(struct elf_note_info *info,
f17523
 		      struct memelfnote *memnote)
f17523
 {
f17523
 	uint32_t *auxv;
f17523
+	ulong addr;
f17523
+	size_t size;
f17523
 	int i;
f17523
 
f17523
-	auxv = (uint32_t *)GETBUF(MEMBER_SIZE("mm_struct", "saved_auxv"));
f17523
+	get_auxv_size_addr(tc, &size, &addr);
f17523
+
f17523
+	auxv = (uint32_t *)GETBUF(size);
f17523
 
f17523
-	readmem(task_mm(tc->task, FALSE) +
f17523
-		MEMBER_OFFSET("mm_struct", "saved_auxv"), KVADDR, auxv,
f17523
-		MEMBER_SIZE("mm_struct", "saved_auxv"), "fill_auxv_note32",
f17523
+	readmem(addr, KVADDR, auxv,
f17523
+		size, "fill_auxv_note32",
f17523
 		gcore_verbose_error_handle());
f17523
 
f17523
 	i = 0;
f17523
-- 
f17523
2.30.2
f17523