Skip to contentSkip to conversation

elf, coredump: Extract only the active register set during core dump

PATCH In review Anshuman Khandual 2 participants 2 messages May 23, 2014 – May 27, 2014

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 elf, coredump: Extract only the active register set during core dump

Regset active hooks provide a way to query how many registers in the register set are active at any point of time. Currently this information is being ignored while creating core dump sections corresponding to any core note register set. This way the core dump will contain data which are not part of the active context of the process and may not be useful. This patch will make sure that only the active part of the register set are captured during the core dump process which will reduce the core dump size.

---
NOTE:
Pedro Alves has mentioned that producing smaller note sections in the core dump may break some existing consumers. I request suggestions, reviews and test reports on different architectures to prove that this patch does not break any existing consumer. Thank you.

Please find the previous discussion here

https://lkml.org/lkml/2014/5/20/185

Regards
Anshuman

 fs/binfmt_elf.c | 14 +++++++++++---
 1 file changed, 11 insertions(+), 3 deletions(-)
fs/binfmt_elf.c +11 -3
index aa3cb62..00aba07 100644
@@ -1551,10 +1551,18 @@ static int fill_thread_core_info(struct elf_thread_core_info *t,
 		const struct user_regset *regset = &view->regsets[i];
 		do_thread_regset_writeback(t->task, regset);
 		if (regset->core_note_type && regset->get &&
-		    (!regset->active || regset->active(t->task, regset))) {
+		    (!regset->active || regset->active(t->task, regset) > 0)) {
 			int ret;
-			size_t size = regset->n * regset->size;
-			void *data = kmalloc(size, GFP_KERNEL);
+			size_t size;
+			void *data;
+
+			if (!regset->active)
+				size = regset->n * regset->size;
+			else
+				size = regset->active(t->task, regset)
+								* regset->size;
+
+			data = kmalloc(size, GFP_KERNEL);
 			if (unlikely(!data))
 				return 0;
 			ret = regset->get(t->task, regset,
Signature · 1 line
1.7.11.7
#1 lore raw
Quoted 9 lines · Anshuman Khandual

Regset active hooks provide a way to query how many registers in the register set are active at any point of time. Currently this information is being ignored while creating core dump sections corresponding to any core note register set. This way the core dump will contain data which are not part of the active context of the process and may not be useful. This patch will make sure that only the active part of the register set are captured during the core dump process which will reduce the core dump size.

Quoted 7 lines

---
NOTE:
Pedro Alves has mentioned that producing smaller note sections in the core dump may break some existing consumers. I request suggestions, reviews and test reports on different architectures to prove that this patch does not break any existing consumer. Thank you.

Yeah, FYI, I mentioned that after noticing that ia64 does:

mainline/linux-2.6/arch/ia64/kernel/ptrace.c:

static int
fpregs_active(struct task_struct *target, const struct user_regset *regset)

 {
         return (target->thread.flags & IA64_THREAD_FPH_VALID) ? 128 : 32;

}

And it's likely that tools expect fpregset_t to have a fixed size.

include/uapi/linux/elfcore.h:

22 typedef elf_fpregset_t fpregset_t;

arch/ia64/include/asm/elf.h:

186 typedef struct ia64_fpreg elf_fpreg_t; 187 typedef elf_fpreg_t elf_fpregset_t[ELF_NFPREG];

arch/ia64/include/asm/elf.h:

 154 #define ELF_NGREG       128     /* we really need just 72 but let's leave some headroom... */
 155 #define ELF_NFPREG      128     /* f0 and f1 could be omitted, but so what... */

I haven't done an exhaustive look over ports.

Signature · 1 line
Pedro Alves