[minicoredumper] [PATCH 06/14] minicoredumper: Add checking if the mapped memory regions are in the coredump

Mateusz Moscicki m.moscicki2 at partner.samsung.com
Tue May 21 14:52:42 CEST 2019


Minicoredumper try to dump NT_GNU_BUILD_ID notes for the every mapped
shared object.

In some cases (e.g. on armv7l) the different memory regions are mapped at the same
file offset:

  ...
  0xb6f78000  0xb6f7f000  0x00000000
      /usr/bin/dotnet-launcher
  0xb6f8e000  0xb6f8f000  0x00000006
      /usr/bin/dotnet-launcher
  ...

  Type           Offset    VirtAddr   PhysAddr   FileSiz MemSiz  Flg Align
  ...
  LOAD           0x80b7000 0xb6f78000 0x00000000 0x00000 0x07000 R E 0x1000
  LOAD           0x80b7000 0xb6f8e000 0x00000000 0x01000 0x01000 RW  0x1000
  ...

We have to check if the region with NT_GNU_BUILD_ID exists in the
coredump file. Otherwise data in RW region will be overwritten and it
can cause that it will be impossible to unwind call stack.

Change-Id: I22247c24c7f524a1cd44abc5fb5d38364de43636
---
 src/minicoredumper/corestripper.c | 26 ++++++++++++++++++++++++--
 1 file changed, 24 insertions(+), 2 deletions(-)

diff --git a/src/minicoredumper/corestripper.c b/src/minicoredumper/corestripper.c
index fa7a957..65df340 100644
--- a/src/minicoredumper/corestripper.c
+++ b/src/minicoredumper/corestripper.c
@@ -2157,6 +2157,29 @@ out:
 	return result;
 }
 
+static struct core_vma* find_vma(struct dump_info *di, size_t start)
+{
+	struct core_vma* res = NULL;
+	for (struct core_vma* p = di->vma; p != NULL; p = p->next) {
+		if (p->start == start) {
+			res = p;
+			break;
+		}
+	}
+	return res;
+}
+
+static off64_t vma_in_file_len(struct dump_info *di, size_t start)
+{
+	struct core_vma* vma = find_vma(di, start);
+	if (vma == NULL) {
+		info("vma on 0x%lx not found", start);
+		return -1;
+	}
+
+	return vma->file_end - vma->start;
+}
+
 /*
  * Iterates over all maps and dumps the selected ones.
  */
@@ -2204,9 +2227,8 @@ static int dump_maps(struct dump_info *di, int get_only)
 		/* dump build id */
 		if (di->cfg->prog_config.dump_build_id) {
 			size_t off_to_note_end = 0;
-			if (get_notes_end_offset(di->mem_fd, start, &off_to_note_end)) {
+			if ((vma_in_file_len(di, start) > 0) && get_notes_end_offset(di->mem_fd, start, &off_to_note_end))
 					dump_vma(di, start, off_to_note_end, 0, "notes");
-			}
 		}
 
 		if (get_only) {
-- 
2.7.4




More information about the minicoredumper mailing list