[PATCH v3] coredump: ignore non-fatal signals when core dumping to a pipe

From: Mandeep Singh Baines
Date: Fri Feb 15 2013 - 19:10:36 EST


From: Ben Chan <benchan@xxxxxxxxxxxx>

Make wait_for_dump_helpers() not abort piping the core dump data when the
crashing process has received a non-fatal signal. The abort still occurs
in the case of SIGKILL.

Addresses http://crosbug.com/21559

Changes since v1:
* Mandeep Singh Baines
* To prevent blocking suspend, add try_to_freeze().
Changes since v2:
* LKML: <20130215150117.GB30829@xxxxxxxxxx> Oleg Nestorov
* Block non-fatal signals to avoid poll_wait busy waiting.
* LKML: <20130215152538.9a61a44e.akpm@xxxxxxxxxxxxxxxxxxxx> Andrew Morton
* Added comment re: try_to_freeze and clarified commit message.

Signed-off-by: Ben Chan <benchan@xxxxxxxxxxxx>
Signed-off-by: Mandeep Singh Baines <msb@xxxxxxxxxxxx>
CC: Oleg Nesterov <oleg@xxxxxxxxxx>
CC: Tejun Heo <tj@xxxxxxxxxx>
CC: Andrew Morton <akpm@xxxxxxxxxxxxxxxxxxxx>
CC: Rafael J. Wysocki <rjw@xxxxxxx>
CC: Ingo Molnar <mingo@xxxxxxxxxx>
---
fs/coredump.c | 16 ++++++++++++++++
1 file changed, 16 insertions(+)

diff --git a/fs/coredump.c b/fs/coredump.c
index 1774932..976f6cc 100644
--- a/fs/coredump.c
+++ b/fs/coredump.c
@@ -32,6 +32,7 @@
#include <linux/pipe_fs_i.h>
#include <linux/oom.h>
#include <linux/compat.h>
+#include <linux/freezer.h>

#include <asm/uaccess.h>
#include <asm/mmu_context.h>
@@ -410,6 +411,11 @@ static void coredump_finish(struct mm_struct *mm)
static void wait_for_dump_helpers(struct file *file)
{
struct pipe_inode_info *pipe;
+ sigset_t blocked, previous;
+
+ /* Block all but fatal signals. */
+ siginitsetinv(&blocked, sigmask(SIGKILL));
+ sigprocmask(SIG_BLOCK, &blocked, &previous);

pipe = file->f_path.dentry->d_inode->i_pipe;

@@ -421,12 +427,22 @@ static void wait_for_dump_helpers(struct file *file)
wake_up_interruptible_sync(&pipe->wait);
kill_fasync(&pipe->fasync_readers, SIGIO, POLL_IN);
pipe_wait(pipe);
+
+ /*
+ * Non-fatal signals are blocked. So we need to try
+ * to freeze in order to not block suspend.
+ */
+ pipe_unlock(pipe);
+ try_to_freeze();
+ pipe_lock(pipe);
}

pipe->readers--;
pipe->writers++;
pipe_unlock(pipe);

+ /* Restore signals. */
+ sigprocmask(SIG_SETMASK, &previous, NULL);
}

/*
--
1.7.12.4

--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/