Skip to contentSkip to conversation

Non disruptive application core dump infrastructure using task_work_add()

RFC PATCH In review Janani Venkataraman 7 participants 31 messages Oct 4, 2013 – Oct 9, 2013

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

cover Non disruptive application core dump infrastructure using task_work_add()

Hi all,

The following series implements an infrastructure for capturing the core of an application without disrupting its process.

So ideally what we are trying to do is to export the infrastructure using /proc/pid/core. Reading the file would give an ELF Format core-dump at that instant non-disruptively, without sending signals.

This would involve basically three operations:

1) Holding the threads of a process without sending a signal (SIGSTOP). At this point we can collect the register set snapshot and collect other information required to create the ELF header. The above operation could be initiated with the open() call.

2) Once the ELF header is created, read() can return the CORE DUMP data including, the process memory page-by-page, based on the fpos (file position).

3) The threads could be released upon a close().

We discussed various approaches for the implemenation in the post given below. -https://lkml.org/lkml/2013/9/3/122

This series is based on the Task work add approach. We didn't adopt the CRIU approch because of the following reasons:

* It is not upstream yet.

* There are concerns about the security of the dump.

* It involves a lot of changes and this approach provides a UNIX style interface.

Task work add

task_work_add() is an interface and an API. The task work add will run any queued work before returning to user space from the kernel. So that work is guaranteed to be done before user space can run again. So basically it queues a work for a task which is guaranteed to be executed when the task returns from kernel space to user space.

* Exploit this function to hold the threads when they are returning to the user space.

* Wait until all the threads of the process to be dumped, reach task_work_add.

* Once all the threads have reached, the dump is taken and they are released.

TODO:

* A mechanism to know when all the threads have reached the task added.

* A way to handle a case when one of the threads of the task to be dumped is blocked in the kernel.

* We could also add the infrastructure under a config option, say:CONFIG_ELF_GENCORE

* The current implementation doesn't wait for the threads to reach wait_for_completion(). Hence there is no guarantee of collecting the 'register set' reliably. We will address this issue in the next version. This is a prototype implementation to get reviews and comments.

Patches 1 to 8 deals with re-arranging the ELF code to be reusable by the infrastructure.

Patches 9 to 19 implements the infrastructure.

Please let me know your reviews and comments.

Janani Venkataraman (19):
Create elfcore-common.c for ELF class independent core generation helpers Make vma_dump_size() generic
Make fill_psinfo generic
Rename compat versions of the reusable core generation routines Export the reusable ELF core generation routines
Define API for reading arch specif Program Headers for Core ia64 impelementation for elf_core_copy_extra_phdrs() elf_core_copy_extra_phdrs() for UML
Create /proc/pid/core entry
Track the core generation requests
Check if the process is an ELF executable
Hold the threads using task_work_add
Create ELF Header
Create ELF Core notes Data
Calculate the size of the core file
Generate the data sections for ELF Core
Identify the ELF class of the process
Adding support for compat ELF class data structures
Compat ELF class core generation support

 arch/ia64/kernel/elfcore.c       |   34 +++
 arch/x86/um/elfcore.c            |   32 +++
 fs/Makefile                      |    1 
 fs/binfmt_elf.c                  |  190 ++--------------
 fs/compat_binfmt_elf.c           |    7 +
 fs/elfcore-common.c              |  169 ++++++++++++++
 fs/proc/Makefile                 |    2 
 fs/proc/base.c                   |    2 
 fs/proc/gencore-compat-elf.c     |   62 +++++
 fs/proc/gencore-elf.c            |  458 ++++++++++++++++++++++++++++++++++++++
 fs/proc/gencore.c                |  262 ++++++++++++++++++++++
 fs/proc/gencore.h                |   74 ++++++
 fs/proc/internal.h               |    1 
 include/linux/elfcore-internal.h |   72 ++++++
 include/linux/elfcore.h          |    3 
 kernel/elfcore.c                 |    6 
 16 files changed, 1209 insertions(+), 166 deletions(-)
 create mode 100644 fs/elfcore-common.c
 create mode 100644 fs/proc/gencore-compat-elf.c
 create mode 100644 fs/proc/gencore-elf.c
 create mode 100644 fs/proc/gencore.c
 create mode 100644 fs/proc/gencore.h
 create mode 100644 include/linux/elfcore-internal.h
Signature · 1 line
Janani 
#1 lore raw

PATCH 1/19 Create elfcore-common.c for ELF class independent core generation helpers

From:Suzuki K. Poulose <[email protected]>

Move the common code, shared by both native and compat ELF core generation code to a single instance.These functions could be re-used later for application core dump infrastructure.

---
 fs/Makefile                      |    1 
 fs/binfmt_elf.c                  |  156 -------------------------------------
 fs/elfcore-common.c              |  161 ++++++++++++++++++++++++++++++++++++++
 include/linux/elfcore-internal.h |   46 +++++++++++
 4 files changed, 209 insertions(+), 155 deletions(-)
 create mode 100644 fs/elfcore-common.c
 create mode 100644 include/linux/elfcore-internal.h
fs/Makefile +1 -0
index 4fe6df3..70e7add 100644
@@ -37,6 +37,7 @@ obj-$(CONFIG_BINFMT_MISC)	+= binfmt_misc.o
 obj-$(CONFIG_BINFMT_SCRIPT)	+= binfmt_script.o
 obj-$(CONFIG_BINFMT_ELF)	+= binfmt_elf.o
 obj-$(CONFIG_COMPAT_BINFMT_ELF)	+= compat_binfmt_elf.o
+obj-$(CONFIG_ELF_CORE)         += elfcore-common.o
 obj-$(CONFIG_BINFMT_ELF_FDPIC)	+= binfmt_elf_fdpic.o
 obj-$(CONFIG_BINFMT_SOM)	+= binfmt_som.o
 obj-$(CONFIG_BINFMT_FLAT)	+= binfmt_flat.o
fs/binfmt_elf.c +1 -155

180 lines not on this page · raw message

fs/elfcore-common.c new file +161 -0

161 lines not on this page · raw message

include/linux/elfcore-internal.h new file +46 -0

46 lines not on this page · raw message

#2 lore raw

PATCH 2/19 Make vma_dump_size() generic

In reply to Janani Venkataraman

From:Suzuki K. Poulose <[email protected]>

vma_dump_size calculates the file size of a vma area in the core file. It assumes the vma belongs to the "current". Make it generic to work for any task. This will be reused by application core dump infrastructure.

---
 fs/binfmt_elf.c                  |    6 +++---
 fs/elfcore-common.c              |   24 ++++++++++++++++--------
 include/linux/elfcore-internal.h |    4 ++--
 3 files changed, 21 insertions(+), 13 deletions(-)
fs/binfmt_elf.c +3 -3
index 6c8df47..107bbd3 100644
@@ -1870,7 +1870,7 @@ static size_t elf_core_vma_data_size(struct vm_area_struct *gate_vma,
 
 	for (vma = first_vma(current, gate_vma); vma != NULL;
 	     vma = next_vma(vma, gate_vma))
-		size += vma_dump_size(vma, mm_flags);
+		size += vma_dump_size(current, vma, mm_flags);
 	return size;
 }
 
@@ -1994,7 +1994,7 @@ static int elf_core_dump(struct coredump_params *cprm)
 		phdr.p_offset = offset;
 		phdr.p_vaddr = vma->vm_start;
 		phdr.p_paddr = 0;
-		phdr.p_filesz = vma_dump_size(vma, cprm->mm_flags);
+		phdr.p_filesz = vma_dump_size(current, vma, cprm->mm_flags);
 		phdr.p_memsz = vma->vm_end - vma->vm_start;
 		offset += phdr.p_filesz;
 		phdr.p_flags = vma->vm_flags & VM_READ ? PF_R : 0;
@@ -2029,7 +2029,7 @@ static int elf_core_dump(struct coredump_params *cprm)
 		unsigned long addr;
 		unsigned long end;
 
-		end = vma->vm_start + vma_dump_size(vma, cprm->mm_flags);
+		end = vma->vm_start + vma_dump_size(current, vma, cprm->mm_flags);
 
 		for (addr = vma->vm_start; addr < end; addr += PAGE_SIZE) {
 			struct page *page;
fs/elfcore-common.c +16 -8
index 4886f15..48f1a9d 100644
@@ -21,7 +21,7 @@
 #include <asm/page.h>
 #include <linux/elfcore-internal.h>
 
-static struct vm_area_struct *first_vma(struct task_struct *tsk,
+struct vm_area_struct *first_vma(struct task_struct *tsk,
 					struct vm_area_struct *gate_vma)
 {
 	struct vm_area_struct *ret = tsk->mm->mmap;
@@ -35,7 +35,7 @@ static struct vm_area_struct *first_vma(struct task_struct *tsk,
  * Helper function for iterating across a vma list.  It ensures that the caller
  * will visit `gate_vma' prior to terminating the search.
  */
-static struct vm_area_struct *next_vma(struct vm_area_struct *this_vma,
+struct vm_area_struct *next_vma(struct vm_area_struct *this_vma,
 					struct vm_area_struct *gate_vma)
 {
 	struct vm_area_struct *ret;
@@ -56,7 +56,7 @@ static struct vm_area_struct *next_vma(struct vm_area_struct *this_vma,
  * meant. These special mappings include - vDSO, vsyscall, and other
  * architecture specific mappings
  */
-static bool always_dump_vma(struct vm_area_struct *vma)
+bool always_dump_vma(struct vm_area_struct *vma)
 {
 	/* Any vsyscall mappings? */
 	if (vma == get_gate_vma(vma->vm_mm))
@@ -74,7 +74,7 @@ static bool always_dump_vma(struct vm_area_struct *vma)
 /*
  *  Decide what to dump of a segment, part, all or none.
  */
-static unsigned long vma_dump_size(struct vm_area_struct *vma,
+unsigned long vma_dump_size(struct task_struct *p, struct vm_area_struct *vma,
 					unsigned long mm_flags)
 {
 #define FILTER(type)    (mm_flags & (1UL << MMF_DUMP_##type))
@@ -143,10 +143,18 @@ static unsigned long vma_dump_size(struct vm_area_struct *vma,
 		 * Switch to the user "segment" for get_user(),
 		 * then put back what elf_core_dump() had in place.
 		 */
-		set_fs(USER_DS);
- 		if (unlikely(get_user(word, header)))
- 			word = 0;
-		set_fs(fs);
+		if (p->mm == current->mm) {
+			mm_segment_t fs = get_fs();
+			set_fs(USER_DS);
+			if (unlikely(get_user(word, header)))
+				word = 0;
+			set_fs(fs);
+		} else {
+			int bytes = access_process_vm(p, (unsigned long)header,
+						&word, sizeof (word), 0);
+			if (bytes != sizeof(word))
+				word = 0;
+		}		
 		if (word == magic.cmp)
 			return PAGE_SIZE;
 	}
include/linux/elfcore-internal.h +2 -2
index f6354f0..9e9cd93 100644
@@ -38,9 +38,9 @@ extern struct vm_area_struct *first_vma(struct task_struct *tsk,
 					struct vm_area_struct *gate_vma);
 extern struct vm_area_struct *next_vma(struct vm_area_struct *this_vma,
 					struct vm_area_struct *gate_vma);
-extern unsigned long vma_dump_size(struct vm_area_struct *vma,
+extern unsigned long vma_dump_size(struct task_struct *task,
+					struct vm_area_struct *vma,
 					unsigned long mm_flags);
 
 #endif
 #endif
-
#3 lore raw

Re: [PATCH 02/19] Make vma_dump_size() generic

Quoted 15 lines · Janani Venkataraman

From:Suzuki K. Poulose <[email protected]>

vma_dump_size calculates the file size of a vma area in the core file. It assumes the vma belongs to the "current". Make it generic to work for any task. This will be reused by application core dump infrastructure.

---

fs/elfcore-common.c +1 -1
-static unsigned long vma_dump_size(struct vm_area_struct *vma,
+unsigned long vma_dump_size(struct task_struct *p, struct vm_area_struct *vma,
 					unsigned long mm_flags)
 {
 #define FILTER(type)    (mm_flags & (1UL << MMF_DUMP_##type))

fs/elfcore-common.c static unsigned long vma_dump_size(struct vm_area_struct *vma, · line 147

Quoted 9 lines
fs/elfcore-common.c +2 -4
@@ -143,10 +143,18 @@ static unsigned long vma_dump_size(struct vm_area_struct *vma,
 		 * Switch to the user "segment" for get_user(),
 		 * then put back what elf_core_dump() had in place.
 		 */
-		set_fs(USER_DS);
- 		if (unlikely(get_user(word, header)))
- 			word = 0;
-		set_fs(fs);
+		if (p->mm == current->mm) {
+			mm_segment_t fs = get_fs();

It looks like you missed the removal of the old:

	mm_segment_t fs = get_fs();

above? Just below if (FILTER(ELF_HEADERS)).

~Ryan

#4 lore raw

Re: [PATCH 02/19] Make vma_dump_size() generic

From: Ryan Mallon <[email protected]>
To: Janani Venkataraman1/India/IBM@IBMIN,
[email protected],
Cc: [email protected], [email protected], [email protected],
[email protected], [email protected], [email protected], [email protected], [email protected], [email protected], [email protected], [email protected], [email protected], [email protected], [email protected], [email protected], [email protected], [email protected], [email protected], [email protected], [email protected], [email protected], [email protected], [email protected], [email protected]
Date: 10/08/2013 05:52 AM
Subject: Re: [PATCH 02/19] Make vma_dump_size() generic

Quoted 4 lines · Janani Venkataraman

From:Suzuki K. Poulose <[email protected]>

vma_dump_size calculates the file size of a vma area in the core file. It assumes the vma belongs to the "current". Make it generic to work for any

task.

Review

Quoted 7 lines

This will be reused by application core dump infrastructure.

---

(quoted diff) +1 -1
-static unsigned long vma_dump_size(struct vm_area_struct *vma,
+unsigned long vma_dump_size(struct task_struct *p, struct vm_area_struct

*vma,

Quoted 1 line

unsigned long

mm_flags)

Review static unsigned long vma_dump_size(struct

Quoted 3 lines

{
#define FILTER(type) (mm_flags & (1UL << MMF_DUMP_##type))

(quoted diff) +0 -0
@@ -143,10 +143,18 @@ static unsigned long vma_dump_size(struct

vm_area_struct *vma,

Review static unsigned long vma_dump_size(struct · line 144

Quoted 2 lines
(quoted diff) +0 -0
 		 		  * Switch to the user "segment" for get_user(),
 		 		  * then put back what elf_core_dump() had in

place.

fs/elfcore-common.c static unsigned long vma_dump_size(struct vm_area_struct *vma, · line 147

Quoted 7 lines
fs/elfcore-common.c +2 -4
 		 		  */
-		 		 set_fs(USER_DS);
- 		 		 if (unlikely(get_user(word, header)))
- 		 		 		 word = 0;
-		 		 set_fs(fs);
+		 		 if (p->mm == current->mm) {
+		 		 		 mm_segment_t fs = get_fs();

It looks like you missed the removal of the old:

		 mm_segment_t fs = get_fs();

above? Just below if (FILTER(ELF_HEADERS)).

Yes thats correct. I will remove it. Thanks for pointing it out.

Thanks
Janani

~Ryan

#5 lore raw

PATCH 3/19 Make fill_psinfo generic

In reply to Janani Venkataraman

From:Suzuki K. Poulose <[email protected]>

fill_psinfo() fills the NT_PRPSINFO note for the core. NT_PRPSINFO stores the command line of the process, which is stored at from mm->arg_start. Make fill_psinfo reusable by supporting other tasks. Use access_process_vm() to read the command line args for non-current task.

---
 fs/binfmt_elf.c |   18 +++++++++++++++---
 1 file changed, 15 insertions(+), 3 deletions(-)
fs/binfmt_elf.c +15 -3
index 107bbd3..4eee017 100644
@@ -1222,9 +1222,21 @@ static int fill_psinfo(struct elf_prpsinfo *psinfo, struct task_struct *p,
 	len = mm->arg_end - mm->arg_start;
 	if (len >= ELF_PRARGSZ)
 		len = ELF_PRARGSZ-1;
-	if (copy_from_user(&psinfo->pr_psargs,
-		           (const char __user *)mm->arg_start, len))
-		return -EFAULT;
+	/*
+	* If we are dumping core for "another task"
+	* we can't use copy_from_user().
+	*/
+	if (p->mm == current->mm) {
+		if (copy_from_user(&psinfo->pr_psargs,
+				(const char __user *)mm->arg_start, len))
+			return -EFAULT;
+	} else {
+		int bytes = access_process_vm(p, mm->arg_start,
+						&psinfo->pr_psargs, len, 0);
+		if (bytes != len)
+			return -EFAULT;
+	}
+
 	for(i = 0; i < len; i++)
 		if (psinfo->pr_psargs[i] == 0)
 			psinfo->pr_psargs[i] = ' ';
#6 lore raw

PATCH 4/19 Rename compat versions of the reusable core generation routines

In reply to Janani Venkataraman

From:Suzuki K. Poulose <[email protected]>

Rename the ELF class specific functions reusable for the application core dump infrastructure. The compat ELF class routines are prepended with compat_ .

---
 fs/compat_binfmt_elf.c |    7 +++++++
 1 file changed, 7 insertions(+)
fs/compat_binfmt_elf.c +7 -0
index a81147e..9a288aa 100644
@@ -134,6 +134,13 @@ static void cputime_to_compat_timeval(const cputime_t cputime,
 #define init_elf_binfmt		init_compat_elf_binfmt
 #define exit_elf_binfmt		exit_compat_elf_binfmt
 
+/* Rename the functions that may be reused */
+#define fill_elf_header        compat_fill_elf_header
+#define fill_psinfo            compat_fill_psinfo
+#define fill_prstatus          compat_fill_prstatus
+#define fill_extnum_info       compat_fill_extnum_info
+#define fill_auxv_note         compat_fill_auxv_note
+
 /*
  * We share all the actual code with the native (64-bit) version.
  */
#7 lore raw

PATCH 5/19 Export the reusable ELF core generation routines

In reply to Janani Venkataraman

From:Suzuki K. Poulose <[email protected]>

Export the ELF class specific core generation helper functions via elfcore-internal.h

---
 fs/binfmt_elf.c                  |   10 +++++-----
 include/linux/elfcore-internal.h |   28 +++++++++++++++++++++++++++-
 2 files changed, 32 insertions(+), 6 deletions(-)
fs/binfmt_elf.c +5 -5
index 4eee017..3f13203 100644
@@ -1137,7 +1137,7 @@ static int writenote(struct memelfnote *men, struct file *file,
 }
 #undef DUMP_WRITE
 
-static void fill_elf_header(struct elfhdr *elf, int segs,
+void fill_elf_header(struct elfhdr *elf, int segs,
 			    u16 machine, u32 flags)
 {
 	memset(elf, 0, sizeof(*elf));
@@ -1177,7 +1177,7 @@ static void fill_elf_note_phdr(struct elf_phdr *phdr, int sz, loff_t offset)
  * fill up all the fields in prstatus from the given task struct, except
  * registers which need to be filled up separately.
  */
-static void fill_prstatus(struct elf_prstatus *prstatus,
+void fill_prstatus(struct elf_prstatus *prstatus,
 		struct task_struct *p, long signr)
 {
 	prstatus->pr_info.si_signo = prstatus->pr_cursig = signr;
@@ -1210,7 +1210,7 @@ static void fill_prstatus(struct elf_prstatus *prstatus,
 	cputime_to_timeval(p->signal->cstime, &prstatus->pr_cstime);
 }
 
-static int fill_psinfo(struct elf_prpsinfo *psinfo, struct task_struct *p,
+int fill_psinfo(struct elf_prpsinfo *psinfo, struct task_struct *p,
 		       struct mm_struct *mm)
 {
 	const struct cred *cred;
@@ -1265,7 +1265,7 @@ static int fill_psinfo(struct elf_prpsinfo *psinfo, struct task_struct *p,
 	return 0;
 }
 
-static void fill_auxv_note(struct memelfnote *note, struct mm_struct *mm)
+void fill_auxv_note(struct memelfnote *note, struct mm_struct *mm)
 {
 	elf_addr_t *auxv = (elf_addr_t *) mm->saved_auxv;
 	int i = 0;
@@ -1858,7 +1858,7 @@ static void free_note_info(struct elf_note_info *info)
 
 #endif
 
-static void fill_extnum_info(struct elfhdr *elf, struct elf_shdr *shdr4extnum,
+void fill_extnum_info(struct elfhdr *elf, struct elf_shdr *shdr4extnum,
 			     elf_addr_t e_shoff, int segs)
 {
 	elf->e_shoff = e_shoff;
include/linux/elfcore-internal.h +27 -1
index 9e9cd93..8c5323a 100644
@@ -14,7 +14,7 @@
 #define __ELF_CORE_INTERNAL_H
 
 #ifdef __KERNEL__
-
+#include <linux/elfcore.h>
 /* An ELF note in memory */
 struct memelfnote
 {
@@ -42,5 +42,31 @@ extern unsigned long vma_dump_size(struct task_struct *task,
 					struct vm_area_struct *vma,
 					unsigned long mm_flags);
 
+/* Core dump generation routines for native ELF class */
+extern void fill_elf_header(struct elfhdr *elf, int segs,
+				u16 machine, u32 flags);
+extern void fill_extnum_info(struct elfhdr *elf, struct elf_shdr *shdr,
+				elf_addr_t e_shoff, int segs);
+extern void fill_prstatus(struct elf_prstatus *prstatus,
+				struct task_struct *p, long signr);
+extern int fill_psinfo(struct elf_prpsinfo *psinfo, struct task_struct *p,
+				struct mm_struct *mm);
+extern void fill_auxv_note(struct memelfnote *note, struct mm_struct *mm);
+
+/* compat ELF class variant of the above helpers*/
+#ifdef CONFIG_COMPAT_BINFMT_ELF
+#include <linux/elfcore-compat.h>
+
+extern void compat_fill_extnum_info(struct elf32_hdr *elf, struct elf32_shdr *shdr,
+					Elf32_Addr e_shoff, int segs);
+extern void compat_fill_prstatus(struct compat_elf_prstatus *prstatus,
+					struct task_struct *p, long signr);
+extern int compat_fill_psinfo(struct compat_elf_prpsinfo *psinfo, struct task_struct *p,
+				struct mm_struct *mm);
+extern void compat_fill_auxv_note(struct memelfnote *note, struct mm_struct *mm);
+extern void compat_fill_elf_header(struct elf32_hdr *elf, int segs,
+					u16 machine, u32 flags);
+#endif /* CONFIG_COMPAT_BINFMT_ELF */
+
 #endif
 #endif
#8 lore raw

PATCH 6/19 Define API for reading arch specif Program Headers for Core

In reply to Janani Venkataraman

From:Suzuki K. Poulose <[email protected]>

The binfmt ELF defines APIs for the "arch" specific Program headers to be written to the ELF core. Define the "read" (or copy) variants of the APIs, to collect it for the application core dump(which is a read based approach).

---
 include/linux/elfcore.h |    3 +++
 kernel/elfcore.c        |    6 ++++++
 2 files changed, 9 insertions(+)
include/linux/elfcore.h +3 -0
index cdd3d13..cf13b45 100644
@@ -66,6 +66,9 @@ extern int
 elf_core_write_extra_phdrs(struct file *file, loff_t offset, size_t *size,
 			   unsigned long limit);
 extern int
+elf_core_copy_extra_phdrs(char *buf, loff_t offset, size_t *size,
+				unsigned long limit);
+extern int
 elf_core_write_extra_data(struct file *file, size_t *size, unsigned long limit);
 extern size_t elf_core_extra_data_size(void);
 
kernel/elfcore.c +6 -0
index ff915ef..f422c6c 100644
@@ -16,6 +16,12 @@ int __weak elf_core_write_extra_phdrs(struct file *file, loff_t offset, size_t *
 	return 1;
 }
 
+int __weak elf_core_copy_extra_phdrs(char *buf, loff_t offset, size_t *size,
+					unsigned long limit)
+{
+	return 1;
+}
+
 int __weak elf_core_write_extra_data(struct file *file, size_t *size,
 				     unsigned long limit)
 {
#9 lore raw

PATCH 7/19 ia64 impelementation for elf_core_copy_extra_phdrs()

In reply to Janani Venkataraman

From:Suzuki K. Poulose <[email protected]>

ia64 impelementation for elf_core_copy_extra_phdrs(). Adapted from elf_core_write_extra_phdrs().

---
 arch/ia64/kernel/elfcore.c |   34 ++++++++++++++++++++++++++++++++++
 1 file changed, 34 insertions(+)
arch/ia64/kernel/elfcore.c +34 -0
index bac1639..64c8acf 100644
@@ -42,6 +42,40 @@ int elf_core_write_extra_phdrs(struct file *file, loff_t offset, size_t *size,
 	return 1;
 }
 
+int elf_core_copy_extra_phdrs(char *bufp, loff_t offset, size_t *size,
+				unsigned long limit)
+{
+	const struct elf_phdr *const gate_phdrs =
+		(const struct elf_phdr *) (GATE_ADDR + GATE_EHDR->e_phoff);
+	int i;
+	Elf64_Off ofs = 0;
+	struct elf_phdr *phdr = (struct elf_phdr *) bufp;
+
+	for (i = 0; i < GATE_EHDR->e_phnum; ++i) {
+		*size += sizeof(*phdr);
+		if (*size > limit)
+			return 0;
+
+		*phdr = gate_phdrs[i];
+
+		if (phdr->p_type == PT_LOAD) {
+			phdr->p_memsz = PAGE_ALIGN(phdr->p_memsz);
+			phdr->p_filesz = phdr->p_memsz;
+			if (ofs == 0) {
+				ofs = phdr->p_offset = *offset;
+				offset += phdr->p_filesz;
+			} else {
+				phdr->p_offset = ofs;
+			}
+		} else {
+			phdr->p_offset += ofs;
+		}
+		phdr->p_paddr = 0; /* match other core phdrs */
+		phdr++;
+	}
+	return 1;
+}
+
 int elf_core_write_extra_data(struct file *file, size_t *size,
 			      unsigned long limit)
 {
#10 lore raw

PATCH 8/19 elf_core_copy_extra_phdrs() for UML

In reply to Janani Venkataraman

From:Suzuki K. Poulose <[email protected]>

elf_core_copy_extra_phdrs() for UML. Adapted from elf_core_write_extra_phdrs()

---
 arch/x86/um/elfcore.c |   32 ++++++++++++++++++++++++++++++++
 1 file changed, 32 insertions(+)
arch/x86/um/elfcore.c +32 -0
index 6bb49b6..edecfce 100644
@@ -41,6 +41,38 @@ int elf_core_write_extra_phdrs(struct file *file, loff_t offset, size_t *size,
 	return 1;
 }
 
+int elf_core_copy_extra_phdrs(char *bufp, loff_t offset, size_t *size,
+				unsigned long limit)
+{
+	if (vsyscall_ehdr) {
+		const struct elfhdr *const ehdrp =
+			(struct elfhdr *) vsyscall_ehdr;
+		const struct elf_phdr *const phdrp =
+			(const struct elf_phdr *) (vsyscall_ehdr + ehdrp->e_phoff);
+		struct elf_phdr *phdr = (struct elf_phdr *)bufp;
+		int i;
+		Elf32_Off ofs = 0;
+
+		for (i = 0; i < ehdrp->e_phnum; ++i) {
+			*size += sizeof(*phdr);
+			if (*size > limit)
+				return 0;
+
+			*phdr = phdrp[i];
+
+			if (phdr.p_type == PT_LOAD) {
+				ofs = phdr.p_offset = offset;
+				offset += phdr.p_filesz;
+			} else {
+				phdr.p_offset += ofs;
+			}
+			phdr.p_paddr = 0; /* match other core phdrs */
+			phdr++;
+		}
+	}
+	return 1;
+}  
+  
 int elf_core_write_extra_data(struct file *file, size_t *size,
 			      unsigned long limit)
 {
#11 lore raw

PATCH 9/19 Create /proc/pid/core entry

In reply to Janani Venkataraman

From:Ananth N.Mavinakayanahalli <[email protected]>

Create the /proc/PID/core entry.

---
 fs/proc/Makefile   |    1 +
 fs/proc/base.c     |    2 ++
 fs/proc/gencore.c  |   48 ++++++++++++++++++++++++++++++++++++++++++++++++
 fs/proc/internal.h |    1 +
 4 files changed, 52 insertions(+)
 create mode 100644 fs/proc/gencore.c
fs/proc/Makefile +1 -0
index ab30716..a456c22 100644
@@ -23,6 +23,7 @@ proc-y	+= version.o
 proc-y	+= softirqs.o
 proc-y	+= namespaces.o
 proc-y	+= self.o
+proc-$(CONFIG_ELF_CORE)        += gencore.o
 proc-$(CONFIG_PROC_SYSCTL)	+= proc_sysctl.o
 proc-$(CONFIG_NET)		+= proc_net.o
 proc-$(CONFIG_PROC_KCORE)	+= kcore.o
fs/proc/base.c +2 -0
index 1485e38..da5a212 100644
@@ -2640,6 +2640,8 @@ static const struct pid_entry tgid_base_stuff[] = {
 #endif
 #ifdef CONFIG_ELF_CORE
 	REG("coredump_filter", S_IRUGO|S_IWUSR, proc_coredump_filter_operations),
+	REG("core", S_IRUSR, proc_gen_core_operations),
+
 #endif
 #ifdef CONFIG_TASK_IO_ACCOUNTING
 	INF("io",	S_IRUSR, proc_tgid_io_accounting),
fs/proc/gencore.c new file +48 -0

48 lines not on this page · raw message

fs/proc/internal.h +1 -0
index 651d09a..47538f2 100644
@@ -228,6 +228,7 @@ extern const struct file_operations proc_ns_dir_operations;
  */
 extern const struct file_operations proc_net_operations;
 extern const struct inode_operations proc_net_inode_operations;
+extern const struct file_operations proc_gen_core_operations;
 
 #ifdef CONFIG_NET
 extern int proc_net_init(void);
#12 lore raw

PATCH 10/19 Track the core generation requests

In reply to Janani Venkataraman

From:Suzuki K.Poulose <[email protected]>

Keep track of the core generation requests. Concurrent core generation requests for the same target process are not allowed.

---
 fs/proc/gencore.c |   86 ++++++++++++++++++++++++++++++++++++++++++++++++++++-
 fs/proc/gencore.h |   12 +++++++
 2 files changed, 96 insertions(+), 2 deletions(-)
 create mode 100644 fs/proc/gencore.h
fs/proc/gencore.c +84 -2
index 115f1e4..580a8b5 100644
@@ -23,23 +23,105 @@
  */
 
 #include <linux/seq_file.h>
+#include <linux/slab.h>
 #include "internal.h"
+#include "gencore.h"
+
+static LIST_HEAD(core_list);
+static DEFINE_MUTEX(core_mutex);
+
+/* Called with core_mutex held */
+static struct core_proc* get_core_proc(struct task_struct *t)
+{
+	struct core_proc *cp;
+
+	list_for_each_entry(cp, &core_list, list) {
+		if (cp->task == t->group_leader)
+			return cp;
+	}
+	return NULL;
+}
 
 static ssize_t read_gencore(struct file *file, char __user *buffer,
 				size_t buflen, loff_t *fpos)
 {
-	return 0;
+	struct task_struct *task = get_proc_task(file->f_dentry->d_inode);
+	struct core_proc *cp;
+	ssize_t ret = 0;
+
+	if (!task)
+		return -EIO;
+
+	mutex_lock(&core_mutex);
+	cp = get_core_proc(task);
+	if (!cp) {
+		mutex_unlock(&core_mutex);
+		ret = -EIO;
+		goto out;
+	}
+	mutex_unlock(&core_mutex);
+
+out:
+	put_task_struct(task);
+	return ret;
 }
 
 static int release_gencore(struct inode *inode, struct file *file)
 {
+	struct task_struct *task = get_proc_task(file->f_dentry->d_inode);
+	struct core_proc *cp;
+
+	if (!task)
+		return -EIO;
+
+	mutex_lock(&core_mutex);
+	cp = get_core_proc(task);
+	if (cp) {
+		list_del(&cp->list);
+		kfree(cp);
+	}
+	mutex_unlock(&core_mutex);
+	put_task_struct(task);
 	return 0;
 }
 
+/*
+ * Validate if the call is valid. We also need to prevent >1 open
+ * of the same file.
+ */
 static int open_gencore(struct inode *inode, struct file *filp)
 {
-	return 0;
+	struct task_struct *task = get_proc_task(inode);
+	struct core_proc *cp;
+	int ret = 0;
+	if (!task)
+		return -ENOENT;
+
+	mutex_lock(&core_mutex);
+	cp = get_core_proc(task);
+	mutex_unlock(&core_mutex);	
+	if (cp) {
+		ret = -EALREADY;
+		goto out;
+	}
+
+	cp = kzalloc(sizeof (*cp), GFP_KERNEL);
+	if (!cp) {
+		ret = -ENOMEM;
+		goto out;
+	}
+
+	cp->task = task->group_leader;
+	INIT_LIST_HEAD(&cp->list);
+	mutex_lock(&core_mutex);
+	list_add(&cp->list, &core_list);
+	mutex_unlock(&core_mutex);
+
+out:
+	put_task_struct(task);
+	return ret;
 }
+
 const struct file_operations proc_gen_core_operations = {
 	.open           = open_gencore,
 	.read           = read_gencore,
fs/proc/gencore.h new file +12 -0
new file mode 100644
index 0000000..c98fddf
@@ -0,0 +1,12 @@
+#ifndef __GEN_CORE_H
+#define __GEN_CORE_H
+
+#include <linux/list.h>
+#include <linux/sched.h>
+
+struct core_proc {
+	struct list_head list;
+	struct task_struct *task;
+};
+
+#endif
#13 lore raw

PATCH 11/19 Check if the process is an ELF executable

In reply to Janani Venkataraman

From:Suzuki K. Poulose <[email protected]>

Validate if the process is an ELF exec. This will be later extended to identify if the task is a native ELF or a compat ELF.

---
 fs/proc/gencore.c |   29 +++++++++++++++++++++++++++++
 1 file changed, 29 insertions(+)
fs/proc/gencore.c +29 -0
index 580a8b5..5f56910 100644
@@ -22,6 +22,7 @@
  *      Suzuki K. Poulose <[email protected]>
  */
 
+#include <linux/elf.h>
 #include <linux/seq_file.h>
 #include <linux/slab.h>
 #include "internal.h"
@@ -85,6 +86,29 @@ static int release_gencore(struct inode *inode, struct file *file)
 	return 0;
 }
 
+ /*
+ * Determine whether the task is an ELF executable.
+ * Returns
+ *     < 0     - Non-ELF
+ *     0       - Native ELF Executable
+ */
+static int get_elf_class(struct task_struct *task)
+{
+	struct elfhdr hdr;
+	int ret = 0;
+	ret = kernel_read(task->mm->exe_file, 0, (char*)&hdr, sizeof(hdr));
+	if (ret < 0)
+		return ret;
+	
+	/* Verify the ELF magic on the exe_file */
+	if (memcmp(hdr.e_ident, ELFMAG, SELFMAG))
+		return -EINVAL;
+	if (elf_check_arch(&hdr))
+		return 0;
+	
+	return -EINVAL;
+}
+
 /*
  * Validate if the call is valid. We also need to prevent >1 open
  * of the same file.
@@ -93,10 +117,15 @@ static int open_gencore(struct inode *inode, struct file *filp)
 {
 	struct task_struct *task = get_proc_task(inode);
 	struct core_proc *cp;
+	int elf_class;
 	int ret = 0;
 	if (!task)
 		return -ENOENT;
 
+	elf_class = get_elf_class(task);
+	if (elf_class < 0)
+		return elf_class;
+
 	mutex_lock(&core_mutex);
 	cp = get_core_proc(task);
 	mutex_unlock(&core_mutex);	
#14 lore raw

PATCH 12/19 Hold the threads using task_work_add

In reply to Janani Venkataraman

From:Janani Venkataraman <[email protected]>

Hold the threads in a killable state, for collection of register set. This was implemented in the past using the freezer system. The freezer functions in kernel essentially help start and stop sets of tasks and this approach exploited the existing freezer subsystem kernel interface effectively to quiesce all the threads of the application before triggering the core dump. This approach was not accepted due to the potential Dos attack. Also the community discussed that "freeze" is a bit dangerous because an application which is frozen cannot be ended and while it's frozen and there is no information "its frozen" via usual user commands as 'ps' or 'top'.

In this method we assign work to the threads of the task, which will make them wait in a killable state until the operation is complete, using 'completion'. Once the dump is complete we release the threads.

The following are yet to be implemented:

1) A check to ensure all the threads have entered the work that was queued
2) Handling of threads blocked in kernel.These will not reach the work queued and hence the dump may be delayed. If the process is in a non running state we can probably take the dump as it would not lead to inconsistency. We would like to community views on the same.

---
 fs/proc/gencore.c |   42 +++++++++++++++++++++++++++++++++++++++---
 fs/proc/gencore.h |    4 ++++
 2 files changed, 43 insertions(+), 3 deletions(-)
fs/proc/gencore.c +39 -3
index 5f56910..d741f18 100644
@@ -20,8 +20,10 @@
  * Authors:
  *      Ananth N.Mavinakayanahalli <[email protected]>
  *      Suzuki K. Poulose <[email protected]>
+ *      Janani Venkataraman <[email protected]>
  */
 
+#include <linux/task_work.h>
 #include <linux/elf.h>
 #include <linux/seq_file.h>
 #include <linux/slab.h>
@@ -67,22 +69,45 @@ out:
 	return ret;
 }
 
+static void gencore_work(struct callback_head *open_work)
+{
+	/* TODO A method to know when all the threads have reached here */ 
+	struct core_proc *cp = container_of(open_work, struct core_proc, twork);
+	/* If a thread is exiting we could let it go */
+	if (current->flags & PF_EXITING)
+		return;
+	wait_for_completion_killable(&cp->hold);
+}
+ 
 static int release_gencore(struct inode *inode, struct file *file)
 {
 	struct task_struct *task = get_proc_task(file->f_dentry->d_inode);
 	struct core_proc *cp;
+	struct task_struct *t;
 
 	if (!task)
 		return -EIO;
 
 	mutex_lock(&core_mutex);
 	cp = get_core_proc(task);
-	if (cp) {
+	if (cp) 
 		list_del(&cp->list);
-		kfree(cp);
-	}
+	else
+		return -ENOENT;
+	
+	complete_all(&cp->hold);
 	mutex_unlock(&core_mutex);
+	/* Cancelling the work added */
+	t = task;
+	read_lock(&tasklist_lock);
+	do {
+		if (t != current)
+			task_work_cancel(t, gencore_work);
+	} while_each_thread(cp->task, t);
+
+	read_unlock(&tasklist_lock);   
 	put_task_struct(task);
+	kfree(cp);
 	return 0;
 }
 
@@ -117,6 +142,7 @@ static int open_gencore(struct inode *inode, struct file *filp)
 {
 	struct task_struct *task = get_proc_task(inode);
 	struct core_proc *cp;
+	struct task_struct *t;
 	int elf_class;
 	int ret = 0;
 	if (!task)
@@ -145,6 +171,16 @@ static int open_gencore(struct inode *inode, struct file *filp)
 	mutex_lock(&core_mutex);
 	list_add(&cp->list, &core_list);
 	mutex_unlock(&core_mutex);
+	init_completion(&cp->hold);
+	/* Adding the work for all the threads except current */
+	t = cp->task;
+	init_task_work(&cp->twork, gencore_work);
+	read_lock(&tasklist_lock);
+	do {
+		if (t != current)
+			task_work_add(t, &cp->twork, true);
+	} while_each_thread(cp->task, t);
+	read_unlock(&tasklist_lock); 
 
 out:
 	put_task_struct(task);
fs/proc/gencore.h +4 -0
index c98fddf..1a88e24 100644
@@ -1,12 +1,16 @@
 #ifndef __GEN_CORE_H
 #define __GEN_CORE_H
 
+#include <linux/types.h>
 #include <linux/list.h>
 #include <linux/sched.h>
+#include <linux/completion.h>
 
 struct core_proc {
 	struct list_head list;
 	struct task_struct *task;
+	struct completion hold;
+	struct callback_head twork;
 };
 
 #endif
#15 lore raw

PATCH 13/19 Create ELF Header

In reply to Janani Venkataraman

From:Suzuki K. Poulose <[email protected]>

Build the ELF header on the fly for the very first read request. The ELF Header, Program Headers are stored in a buffer for processing future read() requests.

gencore-elf.c contains the ELF class specific functions.

---
 fs/proc/Makefile      |    2 -
 fs/proc/gencore-elf.c |  181 +++++++++++++++++++++++++++++++++++++++++++++++++
 fs/proc/gencore.h     |    7 ++
 3 files changed, 189 insertions(+), 1 deletion(-)
 create mode 100644 fs/proc/gencore-elf.c
fs/proc/Makefile +1 -1
index a456c22..d231ac3 100644
@@ -23,7 +23,7 @@ proc-y	+= version.o
 proc-y	+= softirqs.o
 proc-y	+= namespaces.o
 proc-y	+= self.o
-proc-$(CONFIG_ELF_CORE)        += gencore.o
+proc-$(CONFIG_ELF_CORE)        += gencore.o gencore-elf.o
 proc-$(CONFIG_PROC_SYSCTL)	+= proc_sysctl.o
 proc-$(CONFIG_NET)		+= proc_net.o
 proc-$(CONFIG_PROC_KCORE)	+= kcore.o
fs/proc/gencore-elf.c new file +181 -0

181 lines not on this page · raw message

fs/proc/gencore.h +7 -0
index 1a88e24..6c1d57c 100644
@@ -11,6 +11,13 @@ struct core_proc {
 	struct task_struct *task;
 	struct completion hold;
 	struct callback_head twork;
+	void *shdr;             /* elf_shdr, in case nphdrs > PN_XNUM */
+	char *elf_buf;          /* buffer for elf_hdr + phdrs + notes */
+	size_t elf_buflen;      /* size of elf_buf */
+	size_t nphdrs;          /* number of phdrs */
 };
 
+extern ssize_t elf_read_gencore(struct core_proc *cp, char __user *buffer,
+					size_t buflen, loff_t *foffset);
+
 #endif
#16 lore raw

PATCH 14/19 Create ELF Core notes Data

In reply to Janani Venkataraman

From:Suzuki K. Poulose <[email protected]>

Collect the PT_NOTE information for the core.

There are two "process wide" notes. NT_PRPSINFO and NT_AUXV. These are captured in the core_proc structure.

Each thread gets a NT_PRSTATUS note, which will contain the GPR contents. A thread may have additional notes depending on the other register sets used by it. Uses struct elf_thread_core_info to capture the thread specific information.

fill_thread_core_info() fills in the notes for a thread.

---
 fs/proc/gencore-elf.c |  180 ++++++++++++++++++++++++++++++++++++++++++++++++-
 fs/proc/gencore.c     |   56 +++++++++++++++
 fs/proc/gencore.h     |   28 ++++++++
 3 files changed, 260 insertions(+), 4 deletions(-)
fs/proc/gencore-elf.c +178 -2
index 0a245f0..6e97f6a 100644
@@ -34,6 +34,157 @@
 
 #include "gencore.h"
 
+static int notesize(struct memelfnote *men)
+{
+	int size = sizeof(struct elf_note);
+
+	size += roundup(strlen(men->name) + 1, 4);
+	size += roundup(men->datasz, 4);
+
+	return size;
+}
+
+/* Store the note in the header buffer */
+static char *storenote(struct memelfnote *men, char *bufp)
+{
+	struct elf_note *en = (struct elf_note *)bufp;
+
+	en->n_namesz = strlen(men->name) + 1;
+	en->n_descsz = men->datasz;
+	en->n_type = men->type;
+	bufp = (char *) (en + 1);
+
+	memcpy(bufp, men->name, en->n_namesz);
+	bufp = (char *) roundup((unsigned long)bufp + en->n_namesz, 4);
+
+	memcpy(bufp, men->data, men->datasz);
+	bufp = (char *) roundup((unsigned long)bufp + men->datasz, 4);
+
+	return bufp;
+}
+
+#ifdef CORE_DUMP_USE_REGSET
+static void do_thread_regset_writeback(struct task_struct *task,
+				const struct user_regset *regset)
+{
+	if (regset->writeback)
+		regset->writeback(task, regset, 1);
+}
+
+static int fill_thread_core_info(struct elf_thread_core_info *tinfo,
+					struct core_proc *cp)
+{
+	unsigned int i;
+	const struct user_regset_view *view = task_user_regset_view(tinfo->task);
+
+	fill_prstatus(&tinfo->prstatus, tinfo->task, 0);
+
+	do_thread_regset_writeback(tinfo->task, &view->regsets[0]);
+	(void) view->regsets[0].get(tinfo->task, &view->regsets[0],
+				0, sizeof(tinfo->prstatus.pr_reg),
+				&tinfo->prstatus.pr_reg, NULL);
+	fill_note(&tinfo->notes[0], "CORE", NT_PRSTATUS,
+			sizeof(tinfo->prstatus), &tinfo->prstatus);
+	cp->notes_size += notesize(&tinfo->notes[0]);
+	tinfo->num_notes = view->n;
+
+	for (i = 1; i < view->n; i++) {
+		const struct user_regset *regset = &view->regsets[i];
+
+		do_thread_regset_writeback(tinfo->task, regset);
+		if (regset->core_note_type &&
+			(!regset->active || regset->active(tinfo->task, regset))) {
+			int ret;
+			size_t size = regset->n * regset->size;
+			void *data = kzalloc(size, GFP_KERNEL);
+			if (!unlikely(data))
+				return 0;
+			ret = regset->get(tinfo->task, regset,
+					0, size, data, NULL);
+			if (unlikely(ret))
+				kfree(data);
+			else {
+				if (regset->core_note_type != NT_PRFPREG)
+					fill_note(&tinfo->notes[i], "LINUX",
+						regset->core_note_type,
+						size, data);
+				else {
+					tinfo->prstatus.pr_fpvalid = 1;
+					fill_note(&tinfo->notes[i], "CORE",
+						NT_PRFPREG, size, data);
+				}
+				cp->notes_size += notesize(&tinfo->notes[i]);
+			}
+		}
+	}
+	return 1;
+}
+#else
+static int fill_thread_core_info(struct elf_thread_core_info *tinfo,
+					struct core_proc *cp)
+{
+	elf_fpregset_t fpu, *pfpu;
+#ifdef ELF_CORE_COPY_XFPREGS
+	elf_fpxregset_t xfpu, *pxfpu;
+#endif
+
+	fill_prstatus(&tinfo->prstatus, t->task, 0);
+	elf_core_copy_task_regs(t->task, &tinfo->prstatus.pr_reg);
+	fill_note(&tinfo->notes[0], "CORE", NT_PRSTATUS,
+			sizeof(t->prstatus), &t->prstatus);
+	cp->notes_size += notesize(&tinfo->notes[0]);
+	tinfo->num_notes = 1;
+
+	if (tinfo->prstatus.pr_fpvalid = elf_core_copy_task_fpregs(tinfo->task,
+							NULL, &fpu)) {
+		pfpu = kzalloc(sizeof(*pfpu), GFP_KERNEL);
+		if (pfpu == NULL)
+			return 0;
+		memcpy(pfpu, &fpu, sizeof(fpu));
+		fill_note(&tinfo->notes[tinfo->num_notes], "CORE", NT_PRFPREG,
+				sizeof(*pfpu), pfpu);
+		cp->notes_size += notesize(&tinfo->notes[tinfo->num_notes]);
+		tinfo->num_notes++;
+	}
+#ifdef ELF_CORE_COPY_XFPREGS
+	if (elf_core_copy_task_xfpregs(tinfo->task, &xfpu)) {
+		pxfpu = kzalloc(sizeof(*pxfpu), GFP_KERNEL);
+		if (!pxfpu)
+			return 0;
+		memcpy(pxfpu, &xfpu, sizeof(xfpu));
+		fill_note(&tinfo->notes[tinfo->num_notes], "LINUX",
+			ELF_CORE_XFPREG_TYPE, sizeof(*pxfpu), pxfpu);
+		cp->notes_size += notesize(&tinfo->notes[tinfo->num_notes]);
+		tinfo->num_notes++;
+	}
+#endif
+	return 1;
+}
+#endif
+
+/* Returns 0 on error, 1 on success */
+static int collect_notes(struct core_proc *cp)
+{
+	struct elf_thread_core_info *tinfo;
+
+	/* Fill the 2 process wide notes */
+	fill_psinfo(&cp->prpsinfo, cp->task, cp->task->mm);
+	fill_note(&cp->psinfo, "CORE", NT_PRPSINFO,
+			sizeof(struct elf_prpsinfo), &cp->prpsinfo);
+	cp->notes_size += notesize(&cp->psinfo);
+
+	fill_auxv_note(&cp->auxv, cp->task->mm);
+	cp->notes_size += notesize(&cp->auxv);
+
+	tinfo = cp->tinfo;
+	while (tinfo != NULL) {
+		if (!fill_thread_core_info(tinfo, cp))
+			return 0;
+		tinfo = tinfo->next;
+	}
+	return 1;
+}
+
 static void get_elfhdr_size(struct core_proc *cp)
 {
 	struct vm_area_struct *gate_vma;
@@ -51,7 +202,7 @@ static void get_elfhdr_size(struct core_proc *cp)
 
 	cp->nphdrs = segs;
 	cp->elf_buflen = sizeof(struct elfhdr) +
-			(cp->nphdrs * sizeof(struct elf_phdr));
+			(cp->nphdrs * sizeof(struct elf_phdr)) + cp->notes_size;
 	cp->elf_buflen = roundup(cp->elf_buflen, ELF_EXEC_PAGESIZE);
 
 	return;
@@ -66,11 +217,13 @@ static int create_elf_header(struct core_proc *cp)
 	struct elfhdr *elf = (struct elfhdr *)cp->elf_buf;
 	struct elf_phdr *note;
 	struct vm_area_struct *vma, *gate_vma = get_gate_vma(cp->task->mm);
+	struct elf_thread_core_info *tinfo;
 	char *bufp;
 	off_t dataoff, offset;
 	short e_phnum = (cp->nphdrs > PN_XNUM ? PN_XNUM : cp->nphdrs);
 	size_t exphdrs_sz = 0;
 	unsigned long limit = elf_core_extra_phdrs() * sizeof(struct elf_phdr);
+	int first = 1;
 
 #ifdef CORE_DUMP_USE_REGSET
 	const struct user_regset_view *view = task_user_regset_view(cp->task);
@@ -91,7 +244,7 @@ static int create_elf_header(struct core_proc *cp)
 	note->p_offset = dataoff;
 	note->p_vaddr = 0;
 	note->p_paddr = 0;
-	/* TODO: Needs to be populated with the size of the notes section */
+	note->p_filesz = cp->notes_size;
 	note->p_memsz = 0;
 	note->p_flags = 0;
 	note->p_align = 0;
@@ -138,6 +291,22 @@ static int create_elf_header(struct core_proc *cp)
 						dataoff, cp->nphdrs);
 		dataoff += sizeof(struct elf_shdr);
 	}
+	/* Store the notes */
+	tinfo = cp->tinfo;
+	do {
+		int i;
+
+		bufp = storenote(&tinfo->notes[0], bufp);
+		if (first) {
+			bufp = storenote(&cp->psinfo, bufp);
+			bufp = storenote(&cp->auxv, bufp);
+		}
+		for (i = 1; i < tinfo->num_notes; i++)
+			if (tinfo->notes[i].data != NULL)
+				bufp = storenote(&tinfo->notes[i], bufp);
+		first = 0;
+		tinfo = tinfo->next;
+	} while (tinfo != NULL);
 
 	return 0;
 }
@@ -147,6 +316,13 @@ ssize_t elf_read_gencore(struct core_proc *cp, char __user *buffer,
 {
 	ssize_t ret = 0;
 
+	if (!cp->notes_size) {
+		if (!collect_notes(cp)) {
+			ret = -ENOMEM;
+			goto out;
+		}
+	}
+
 	if (!cp->elf_buf) {
 		get_elfhdr_size(cp);
 
fs/proc/gencore.c +54 -2

86 lines not on this page · raw message

fs/proc/gencore.h +28 -0
index 6c1d57c..e508417 100644
@@ -5,6 +5,16 @@
 #include <linux/list.h>
 #include <linux/sched.h>
 #include <linux/completion.h>
+#include <linux/elfcore.h>
+#include <linux/elfcore-internal.h>
+
+struct elf_thread_core_info {
+	unsigned short num_notes;       /* Number of notes for this thread */
+	struct elf_thread_core_info *next;
+	struct task_struct *task;
+	struct elf_prstatus prstatus;
+	struct memelfnote notes[0];
+};
 
 struct core_proc {
 	struct list_head list;
@@ -13,10 +23,28 @@ struct core_proc {
 	struct callback_head twork;
 	void *shdr;             /* elf_shdr, in case nphdrs > PN_XNUM */
 	char *elf_buf;          /* buffer for elf_hdr + phdrs + notes */
+	struct elf_thread_core_info *tinfo; 
+	struct memelfnote psinfo; 
+	struct memelfnote auxv;
+	struct elf_prpsinfo prpsinfo;
 	size_t elf_buflen;      /* size of elf_buf */
 	size_t nphdrs;          /* number of phdrs */
+	size_t notes_size;
 };
 
+#ifdef CORE_DUMP_USE_REGSET
+#include <linux/regset.h>
+
+static inline int  get_max_regsets(struct task_struct *task)
+{  
+	const struct user_regset_view *view = task_user_regset_view(task);
+	return view->n;
+}
+
+#else
+#define get_max_regsets(task)  3 /* GPR, FP, XFP? */
+#endif
+
 extern ssize_t elf_read_gencore(struct core_proc *cp, char __user *buffer,
 					size_t buflen, loff_t *foffset);
 
#17 lore raw

PATCH 15/19 Calculate the size of the core file

In reply to Janani Venkataraman

From:Suzuki K. Poulose <[email protected]>

Calculate the size of the core file

---
 fs/proc/gencore-elf.c |    6 ++++++
 fs/proc/gencore.h     |    1 +
 2 files changed, 7 insertions(+)
fs/proc/gencore-elf.c +6 -0
index 6e97f6a..efd1722 100644
@@ -291,6 +291,9 @@ static int create_elf_header(struct core_proc *cp)
 						dataoff, cp->nphdrs);
 		dataoff += sizeof(struct elf_shdr);
 	}
+
+	cp->size = dataoff;
+
 	/* Store the notes */
 	tinfo = cp->tinfo;
 	do {
@@ -351,6 +354,9 @@ ssize_t elf_read_gencore(struct core_proc *cp, char __user *buffer,
 			buffer += bcp;
 		}
 	}
+	if (*fpos > cp->size)
+		goto out;
+  
 out:
 	return ret;
 }
fs/proc/gencore.h +1 -0
index e508417..f6822f2 100644
@@ -30,6 +30,7 @@ struct core_proc {
 	size_t elf_buflen;      /* size of elf_buf */
 	size_t nphdrs;          /* number of phdrs */
 	size_t notes_size;
+	size_t size;
 };
 
 #ifdef CORE_DUMP_USE_REGSET
#18 lore raw

PATCH 16/19 Generate the data sections for ELF Core

In reply to Janani Venkataraman

From:Suzuki K. Poulose <[email protected]>

Generate the "data" for the memory regions. Also write down the section header if we have, number of phdrs > PN_XNUM.

The vma areas are read, page by page using access_process_vm() without an mmap_sem. If there are active threads, then we may miss a vma if it is removed while we are doing the read.

---
 fs/proc/gencore-elf.c |   90 ++++++++++++++++++++++++++++++++++++++++++++++++-
 1 file changed, 88 insertions(+), 2 deletions(-)
fs/proc/gencore-elf.c +88 -2
index efd1722..244e5bb 100644
@@ -314,10 +314,29 @@ static int create_elf_header(struct core_proc *cp)
 	return 0;
 }
 
+/*
+ * Verify if the fpos asked for in read is valid.
+ * Returns the phdr corresponding to offset, else NULL.
+ */
+static struct elf_phdr *get_pos_elfphdr(struct core_proc *cp, loff_t pos)
+{
+	struct elfhdr *elf_hdr = (struct elfhdr *)cp->elf_buf;
+	struct elf_phdr *phdr = (struct elf_phdr*)(cp->elf_buf + elf_hdr->e_phoff);
+	int i;
+
+	for (i = 0; i < cp->nphdrs; i++, phdr++) {
+		unsigned long end = phdr->p_offset + phdr->p_filesz;
+		if ((pos >= phdr->p_offset) && (pos < end) && phdr->p_filesz)
+			return phdr;
+	}
+	return NULL;
+}
+
 ssize_t elf_read_gencore(struct core_proc *cp, char __user *buffer,
 				size_t buflen, loff_t *fpos)
 {
-	ssize_t ret = 0;
+	ssize_t ret = 0, acc = 0;
+	struct elfhdr *elf_hdr = (struct elfhdr *)cp->elf_buf;
 
 	if (!cp->notes_size) {
 		if (!collect_notes(cp)) {
@@ -349,13 +368,80 @@ ssize_t elf_read_gencore(struct core_proc *cp, char __user *buffer,
 			goto out;
 		} else {
 			ret = bcp;
+			acc = bcp;
 			*fpos += bcp;
 			buflen -= bcp;
 			buffer += bcp;
 		}
 	}
+
 	if (*fpos > cp->size)
-		goto out;
+		goto done;
+
+	/*
+	 * Read from the vma segments
+	 * a. verify if the *fpos is within a phdr
+	 * b. Use access_process_vm() to get data page by page
+	 * c. copy_to_user into user buffer
+	 */
+
+	while (buflen) {
+		size_t bufsz, offset, bytes;
+		char *readbuf;
+		struct elf_phdr *phdr = get_pos_elfphdr(cp, *fpos);
+
+		if (!phdr)
+			break;
+
+		bufsz = (buflen > PAGE_SIZE) ? PAGE_SIZE : buflen;
+		readbuf = kmalloc(bufsz, GFP_KERNEL);
+		if (!readbuf) {
+			ret = -ENOMEM;
+			goto out;
+		}
+
+		offset = *fpos - phdr->p_offset;
+		bytes = access_process_vm(cp->task, (phdr->p_vaddr + offset),
+							readbuf, bufsz, 0);	 		
+		if (!bytes) {
+			ret = -EIO;
+			goto out;
+		}
+		if (copy_to_user(buffer, readbuf, bytes)) {
+			ret = -EFAULT;
+			kfree(readbuf);
+			goto out;
+		} else
+			acc += bytes;
+
+		kfree(readbuf);
+		buflen -= bytes;
+		buffer += bytes;
+		*fpos += bytes;
+	}
+
+	/* Fill extnum section header if present */
+	if (buflen &&
+		elf_hdr->e_shoff &&
+		(*fpos >= elf_hdr->e_shoff) &&
+		(*fpos < (elf_hdr->e_shoff + sizeof(struct elf_shdr)))) {
+
+		off_t offset = *fpos - elf_hdr->e_shoff;
+		size_t shdrsz = sizeof(struct elf_shdr) - offset;
+
+		shdrsz = (buflen < shdrsz) ? buflen : shdrsz;
+		if (copy_to_user(buffer, ((char *)cp->shdr) + offset, shdrsz)) {
+			ret = -EFAULT;
+			goto out;
+		} else {
+			acc += shdrsz;
+			buflen -= shdrsz;
+			buffer += shdrsz;
+		}
+	}
+ 
+done:
+	ret = acc;
   
 out:
 	return ret;
#19 lore raw

PATCH 17/19 Identify the ELF class of the process

In reply to Janani Venkataraman

From:Suzuki K. Poulose <[email protected]>

Identify the ELF class of the process to native or compat.

---
 fs/proc/gencore.c |   17 ++++++++++++++---
 fs/proc/gencore.h |    3 +++
 2 files changed, 17 insertions(+), 3 deletions(-)
fs/proc/gencore.c +14 -3
index 463bedd..3e0db30 100644
@@ -64,6 +64,9 @@ static ssize_t read_gencore(struct file *file, char __user *buffer,
 	}
 	mutex_unlock(&core_mutex);
 
+	if (cp->elf_class == ELF_CLASS_NATIVE)
+		ret = elf_read_gencore(cp, buffer, buflen, fpos);
+
 out:
 	put_task_struct(task);
 	return ret;
@@ -147,8 +150,8 @@ static int release_gencore(struct inode *inode, struct file *file)
  /*
  * Determine whether the task is an ELF executable.
  * Returns
- *     < 0     - Non-ELF
- *     0       - Native ELF Executable
+ *     -EINVAL - On non ELF execs
+ *     Returns the ELF_CLASS_NATIVE or ELF_CLASS_COMPAT
  */
 static int get_elf_class(struct task_struct *task)
 {
@@ -162,7 +165,14 @@ static int get_elf_class(struct task_struct *task)
 	if (memcmp(hdr.e_ident, ELFMAG, SELFMAG))
 		return -EINVAL;
 	if (elf_check_arch(&hdr))
-		return 0;
+		return ELF_CLASS_NATIVE;
+#ifdef CONFIG_COMPAT_BINFMT_ELF
+	{ 
+		struct elf32_hdr *chdr = (struct elf32_hdr *)&hdr;
+		if (compat_elf_check_arch(chdr))
+			return ELF_CLASS_COMPAT;
+	}
+#endif
 	
 	return -EINVAL;
 }
@@ -206,6 +216,7 @@ static int open_gencore(struct inode *inode, struct file *filp)
 	list_add(&cp->list, &core_list);
 	mutex_unlock(&core_mutex);
 	max_regset = get_max_regsets(task);
+	cp->elf_class = elf_class;
 
 	for (i = 0; i < get_nr_threads(task); i++) {
 		tinfo = kzalloc(offsetof(struct elf_thread_core_info,
fs/proc/gencore.h +3 -0
index f6822f2..d7a5fb3 100644
@@ -8,6 +8,8 @@
 #include <linux/elfcore.h>
 #include <linux/elfcore-internal.h>
 
+enum { ELF_CLASS_NATIVE, ELF_CLASS_COMPAT };
+
 struct elf_thread_core_info {
 	unsigned short num_notes;       /* Number of notes for this thread */
 	struct elf_thread_core_info *next;
@@ -31,6 +33,7 @@ struct core_proc {
 	size_t nphdrs;          /* number of phdrs */
 	size_t notes_size;
 	size_t size;
+	unsigned char elf_class;
 };
 
 #ifdef CORE_DUMP_USE_REGSET
#20 lore raw

PATCH 18/19 Adding support for compat ELF class data structures

In reply to Janani Venkataraman

From:Suzuki K. Poulose <[email protected]>

gencore-elf.c will be reused for the compat ELF class support. Hence, define macros to get the right member for each class.

---
 fs/proc/gencore-elf.c |   31 ++++++++++++++++++++-----------
 fs/proc/gencore.h     |   16 +++++++++++++++-
 2 files changed, 35 insertions(+), 12 deletions(-)
fs/proc/gencore-elf.c +20 -11
index 244e5bb..3c6b67a 100644
@@ -33,6 +33,15 @@
 #endif
 
 #include "gencore.h"
+#ifndef et_prstatus
+/* prstatus field for native elf,  in elf_thread_core_info*/
+#define et_prstatus u.prstatus
+#endif
+
+#ifndef cp_prpsinfo
+/* prpsinfo field for native elf, in core_proc */
+#define cp_prpsinfo u.prpsinfo
+#endif
 
 static int notesize(struct memelfnote *men)
 {
@@ -77,14 +86,14 @@ static int fill_thread_core_info(struct elf_thread_core_info *tinfo,
 	unsigned int i;
 	const struct user_regset_view *view = task_user_regset_view(tinfo->task);
 
-	fill_prstatus(&tinfo->prstatus, tinfo->task, 0);
+	fill_prstatus(&tinfo->et_prstatus, tinfo->task, 0);
 
 	do_thread_regset_writeback(tinfo->task, &view->regsets[0]);
 	(void) view->regsets[0].get(tinfo->task, &view->regsets[0],
-				0, sizeof(tinfo->prstatus.pr_reg),
-				&tinfo->prstatus.pr_reg, NULL);
+				0, sizeof(tinfo->et_prstatus.pr_reg),
+				&tinfo->et_prstatus.pr_reg, NULL);
 	fill_note(&tinfo->notes[0], "CORE", NT_PRSTATUS,
-			sizeof(tinfo->prstatus), &tinfo->prstatus);
+			sizeof(tinfo->et_prstatus), &tinfo->et_prstatus);
 	cp->notes_size += notesize(&tinfo->notes[0]);
 	tinfo->num_notes = view->n;
 
@@ -109,7 +118,7 @@ static int fill_thread_core_info(struct elf_thread_core_info *tinfo,
 						regset->core_note_type,
 						size, data);
 				else {
-					tinfo->prstatus.pr_fpvalid = 1;
+					tinfo->et_prstatus.pr_fpvalid = 1;
 					fill_note(&tinfo->notes[i], "CORE",
 						NT_PRFPREG, size, data);
 				}
@@ -128,14 +137,14 @@ static int fill_thread_core_info(struct elf_thread_core_info *tinfo,
 	elf_fpxregset_t xfpu, *pxfpu;
 #endif
 
-	fill_prstatus(&tinfo->prstatus, t->task, 0);
-	elf_core_copy_task_regs(t->task, &tinfo->prstatus.pr_reg);
+	fill_prstatus(&tinfo->et_prstatus, t->task, 0);
+	elf_core_copy_task_regs(t->task, &tinfo->et_prstatus.pr_reg);
 	fill_note(&tinfo->notes[0], "CORE", NT_PRSTATUS,
-			sizeof(t->prstatus), &t->prstatus);
+			sizeof(t->et_prstatus), &t->et_prstatus);
 	cp->notes_size += notesize(&tinfo->notes[0]);
 	tinfo->num_notes = 1;
 
-	if (tinfo->prstatus.pr_fpvalid = elf_core_copy_task_fpregs(tinfo->task,
+	if (tinfo->et_prstatus.pr_fpvalid = elf_core_copy_task_fpregs(tinfo->task,
 							NULL, &fpu)) {
 		pfpu = kzalloc(sizeof(*pfpu), GFP_KERNEL);
 		if (pfpu == NULL)
@@ -168,9 +177,9 @@ static int collect_notes(struct core_proc *cp)
 	struct elf_thread_core_info *tinfo;
 
 	/* Fill the 2 process wide notes */
-	fill_psinfo(&cp->prpsinfo, cp->task, cp->task->mm);
+	fill_psinfo(&cp->cp_prpsinfo, cp->task, cp->task->mm);
 	fill_note(&cp->psinfo, "CORE", NT_PRPSINFO,
-			sizeof(struct elf_prpsinfo), &cp->prpsinfo);
+			sizeof(struct elf_prpsinfo), &cp->cp_prpsinfo);
 	cp->notes_size += notesize(&cp->psinfo);
 
 	fill_auxv_note(&cp->auxv, cp->task->mm);
fs/proc/gencore.h +15 -1
index d7a5fb3..60972a2 100644
@@ -7,6 +7,9 @@
 #include <linux/completion.h>
 #include <linux/elfcore.h>
 #include <linux/elfcore-internal.h>
+#ifdef CONFIG_COMPAT_BINFMT_ELF
+#include <linux/elfcore-compat.h>
+#endif
 
 enum { ELF_CLASS_NATIVE, ELF_CLASS_COMPAT };
 
@@ -15,6 +18,12 @@ struct elf_thread_core_info {
 	struct elf_thread_core_info *next;
 	struct task_struct *task;
 	struct elf_prstatus prstatus;
+	union {
+		struct elf_prstatus prstatus;
+#ifdef CONFIG_COMPAT_BINFMT_ELF
+		struct compat_elf_prstatus compat_prstatus;
+#endif
+	} u;
 	struct memelfnote notes[0];
 };
 
@@ -28,7 +37,12 @@ struct core_proc {
 	struct elf_thread_core_info *tinfo; 
 	struct memelfnote psinfo; 
 	struct memelfnote auxv;
-	struct elf_prpsinfo prpsinfo;
+	union {
+		struct elf_prpsinfo prpsinfo;
+#ifdef CONFIG_COMPAT_BINFMT_ELF
+		struct compat_elf_prpsinfo compat_prpsinfo;
+#endif
+	} u; 
 	size_t elf_buflen;      /* size of elf_buf */
 	size_t nphdrs;          /* number of phdrs */
 	size_t notes_size;
#21 lore raw

PATCH 19/19 Compat ELF class core generation support

In reply to Janani Venkataraman

From:Suzuki K. Poulose <[email protected]>

Add full support for the compat ELF class objects. The gencore-compat-elf.c reuses the gencore-elf.c, by renaming the ABI structures and functions. (Inspired by compat_binfmt_elf.c)

---
 fs/proc/Makefile             |    1 +
 fs/proc/gencore-compat-elf.c |   62 ++++++++++++++++++++++++++++++++++++++++++
 fs/proc/gencore.c            |    4 +++
 fs/proc/gencore.h            |    5 +++
 4 files changed, 72 insertions(+)
 create mode 100644 fs/proc/gencore-compat-elf.c
fs/proc/Makefile +1 -0
index d231ac3..d8e17f2 100644
@@ -24,6 +24,7 @@ proc-y	+= softirqs.o
 proc-y	+= namespaces.o
 proc-y	+= self.o
 proc-$(CONFIG_ELF_CORE)        += gencore.o gencore-elf.o
+proc-$(CONFIG_COMPAT_BINFMT_ELF) += gencore-compat-elf.o
 proc-$(CONFIG_PROC_SYSCTL)	+= proc_sysctl.o
 proc-$(CONFIG_NET)		+= proc_net.o
 proc-$(CONFIG_PROC_KCORE)	+= kcore.o
fs/proc/gencore-compat-elf.c new file +62 -0

62 lines not on this page · raw message

fs/proc/gencore.c +4 -0
index 3e0db30..92be778 100644
@@ -66,6 +66,10 @@ static ssize_t read_gencore(struct file *file, char __user *buffer,
 
 	if (cp->elf_class == ELF_CLASS_NATIVE)
 		ret = elf_read_gencore(cp, buffer, buflen, fpos);
+#ifdef CONFIG_COMPAT_BINFMT_ELF
+	else if (cp->elf_class == ELF_CLASS_COMPAT)
+		ret = compat_elf_read_gencore(cp, buffer, buflen, fpos);
+#endif
 
 out:
 	put_task_struct(task);
fs/proc/gencore.h +5 -0
index 60972a2..840863b 100644
@@ -66,4 +66,9 @@ static inline int  get_max_regsets(struct task_struct *task)
 extern ssize_t elf_read_gencore(struct core_proc *cp, char __user *buffer,
 					size_t buflen, loff_t *foffset);
 
+#ifdef CONFIG_COMPAT_BINFMT_ELF
+extern ssize_t compat_elf_read_gencore(struct core_proc *cp, char __user *buffer,
+					size_t buflen, loff_t *foffset);
+#endif
+
 #endif
#22 lore raw
In reply to Janani Venkataraman
Quoted 7 lines · Janani Venkataraman

Hi all,

This series is based on the Task work add approach. We didn't adopt the CRIU approch because of the following reasons:

* It is not upstream yet.

It is, starting from criu-v0.7 + linux-3.11

Quoted 1 line

* There are concerns about the security of the dump.

Can you elaborate on this? Is it fixable in CRIU at all?

Quoted 2 lines

* It involves a lot of changes and this approach provides a UNIX style interface.

Can you also shed more light on this -- what changes do you mean?

#23 lore raw

Hello,

Quoted 4 lines · Pavel Emelyanov
Quoted 1 line

* It is not upstream yet.

It is, starting from criu-v0.7 + linux-3.11

Quoted 8 lines
Quoted 1 line

* There are concerns about the security of the dump.

Can you elaborate on this? Is it fixable in CRIU at all?

Quoted 2 lines

* It involves a lot of changes and this approach provides a UNIX style interface.

Can you also shed more light on this -- what changes do you mean?

Yeah, I'd like to hear more too. It doesn't make much sense to me to add something completely new if it can be served mostly by the existing infrastructure. Also, what do you mean by "disruption"? You mentioned signal but PTRACE_SEIZE is completely transparent w.r.t. signals. If you mean without stopping the target process's execution, what are you trying to use the dumping for and how much gain are we talking about? Also, isn't it kinda mandatory to stop the process to get a consistent dump? What am I missing here?

Thanks.

Signature · 1 line
tejun
#24 lore raw

From: Tejun Heo <[email protected]>
To: Pavel Emelyanov <[email protected]>,
Cc: Janani Venkataraman1/India/IBM@IBMIN,
[email protected], [email protected], [email protected], [email protected], [email protected], [email protected], [email protected], [email protected], [email protected], [email protected], [email protected], [email protected], [email protected], [email protected], [email protected], [email protected], [email protected], [email protected], [email protected], [email protected], [email protected], [email protected], [email protected]
Date: 10/08/2013 12:26 AM
Subject: Re: [RFC] [PATCH 00/19] Non disruptive application core dump
infrastructure using task_work_add()
Sent by: Tejun Heo <[email protected]>

Hello,

Quoted 4 lines · Pavel Emelyanov
Quoted 1 line

* It is not upstream yet.

It is, starting from criu-v0.7 + linux-3.11

Quoted 8 lines
Quoted 1 line

* There are concerns about the security of the dump.

Can you elaborate on this? Is it fixable in CRIU at all?

Quoted 2 lines

* It involves a lot of changes and this approach provides a UNIX style interface.

Can you also shed more light on this -- what changes do you mean?

Yeah, I'd like to hear more too. It doesn't make much sense to me to add something completely new if it can be served mostly by the existing infrastructure. Also, what do you mean by "disruption"? You mentioned signal but PTRACE_SEIZE is completely transparent w.r.t. signals. If you mean without stopping the target process's execution, what are you trying to use the dumping for and how much gain are we talking about? Also, isn't it kinda mandatory to stop the process to get a consistent dump? What am I missing here?

By disruption we do mean not using signals. PTRACE_SEIZE doesn't use signals,
but the concern is, a seize can't be done on oneself and we are looking at also
a self dump.

Thanks.
Janani

Thanks.

--
tejun

#25 lore raw
In reply to Pavel Emelyanov

From: Pavel Emelyanov <[email protected]>
To: Janani Venkataraman1/India/IBM@IBMIN,
Cc: <[email protected]>, <[email protected]>,

            <[email protected]>, <[email protected]>,
            <[email protected]>, <[email protected]>,
            <[email protected]>, <[email protected]>,
            <[email protected]>, <[email protected]>,
            <[email protected]>, <[email protected]>,
            <[email protected]>, <[email protected]>, <[email protected]>,
            <[email protected]>, <[email protected]>,
            <[email protected]>, <[email protected]>, <[email protected]>,
            <[email protected]>, <[email protected]>,
            <[email protected]>, <[email protected]>

Date: 10/04/2013 04:08 PM
Subject: Re: [RFC] [PATCH 00/19] Non disruptive application core dump
infrastructure using task_work_add()

Quoted 4 lines · Janani Venkataraman

Hi all,

This series is based on the Task work add approach. We didn't adopt the

CRIU

Quoted 3 lines

approch because of the following reasons:

* It is not upstream yet.

It is, starting from criu-v0.7 + linux-3.11

Quoted 1 line

* There are concerns about the security of the dump.

Can you elaborate on this? Is it fixable in CRIU at all?

Quoted 2 lines

* It involves a lot of changes and this approach provides a UNIX style interface.

Can you also shed more light on this -- what changes do you mean?

We had a prototype ready earlier using the freezer approach.
http://lwn.net/Articles/419756/

We made a couple of minor changes to it and implemented using task work add.
We wanted to know what the community felt about this approach.

Also in the previous RFD, Andi Kleen had mentioned a concern on the security with
respect to the daemon approach for a self dump in CRIU.

Thanks.
Janani

#26 lore raw
Quoted 47 lines · On 10/08/2013 02:12 PM, Janani Venkataraman1 wrote:

From: Pavel Emelyanov <[email protected]>
To: Janani Venkataraman1/India/IBM@IBMIN,
Cc: <[email protected]>, <[email protected]>,

            <[email protected]>, <[email protected]>,
            <[email protected]>, <[email protected]>,
            <[email protected]>, <[email protected]>,
            <[email protected]>, <[email protected]>,
            <[email protected]>, <[email protected]>,
            <[email protected]>, <[email protected]>, <[email protected]>,
            <[email protected]>, <[email protected]>,
            <[email protected]>, <[email protected]>, <[email protected]>,
            <[email protected]>, <[email protected]>,
            <[email protected]>, <[email protected]>

Date: 10/04/2013 04:08 PM
Subject: Re: [RFC] [PATCH 00/19] Non disruptive application core dump
infrastructure using task_work_add()

Quoted 4 lines · Janani Venkataraman

Hi all,

This series is based on the Task work add approach. We didn't adopt the

CRIU

Quoted 3 lines

approch because of the following reasons:

* It is not upstream yet.

It is, starting from criu-v0.7 + linux-3.11

Quoted 1 line

* There are concerns about the security of the dump.

Can you elaborate on this? Is it fixable in CRIU at all?

Quoted 2 lines

* It involves a lot of changes and this approach provides a UNIX style interface.

Can you also shed more light on this -- what changes do you mean?

We had a prototype ready earlier using the freezer approach.
http://lwn.net/Articles/419756/

Quoted 7 lines

We made a couple of minor changes to it and implemented using task work add.
We wanted to know what the community felt about this approach.

Also in the previous RFD, Andi Kleen had mentioned a concern on the security with
respect to the daemon approach for a self dump in CRIU.

We have this thing addressed -- when one requests a self-dump from criu daemon the latter

a) gets pid to dump from SO_PEERCRED, thus requester cannot just send some other's pid
b) doesn't dump tasks that belong to user other than the one who requested the dump

What other security concerns do you have? We're also interested in addressing them.

Quoted 5 lines

Thanks.
Janani

.

#27 lore raw
In reply to Janani Venkataraman
Quoted 4 lines · Janani Venkataraman

Hi all,

The following series implements an infrastructure for capturing the core of an application without disrupting its process.

The problem is that gcore et.al. have to stop the process briefly to attach and then use the pid mmap ptrace interfaces, right?

Couldn't they just use the new process_vm_readv() syscalls instead? AFAIK those do not require ptrace.

Then this could be all done in user space.

Or are there some specific races with this approach?

-Andi

#28 lore raw
Quoted 9 lines · Andi Kleen
Quoted 4 lines · Janani Venkataraman

Hi all,

The following series implements an infrastructure for capturing the core of an application without disrupting its process.

The problem is that gcore et.al. have to stop the process briefly to attach and then use the pid mmap ptrace interfaces, right?

Correct.

Quoted 3 lines

Couldn't they just use the new process_vm_readv() syscalls instead? AFAIK those do not require ptrace.

We need the register set and hence would need a ptrace.

Quoted 4 lines

Then this could be all done in user space.

Or are there some specific races with this approach?

Cheers
Suzuki

#29 lore raw
Quoted 7 lines · Suzuki K. Poulose
Quoted 3 lines · Andi Kleen

Couldn't they just use the new process_vm_readv() syscalls instead? AFAIK those do not require ptrace.

We need the register set and hence would need a ptrace.

Or the task itself can dump its memory/registers/whatever in responce to the request from dumper.

gencore_work() is only used to freeze the process, but it can do more?

Oleg.

#30 lore raw
In reply to Suzuki K. Poulose
Quoted 4 lines
Quoted 3 lines

Couldn't they just use the new process_vm_readv() syscalls instead? AFAIK those do not require ptrace.

We need the register set and hence would need a ptrace.

But the kernel needs to stop to to read the registers.

Do you have data how much the latency difference is between an optimized ptrace reader (using PTRACE_GETREGSET) vs the kernel ?

-Andi