Commit 403bad72b67d8b3f5a0240af5023adfa48132a65
Committed by
Linus Torvalds
1 parent
66e5b7e194
Exists in
master
and in
20 other branches
coredump: only SIGKILL should interrupt the coredumping task
There are 2 well known and ancient problems with coredump/signals, and a lot of related bug reports: - do_coredump() clears TIF_SIGPENDING but of course this can't help if, say, SIGCHLD comes after that. In this case the coredump can fail unexpectedly. See for example wait_for_dump_helper()->signal_pending() check but there are other reasons. - At the same time, dumping a huge core on the slow media can take a lot of time/resources and there is no way to kill the coredumping task reliably. In particular this is not oom_kill-friendly. This patch tries to fix the 1st problem, and makes the preparation for the next changes. We add the new SIGNAL_GROUP_COREDUMP flag set by zap_threads() to indicate that this process dumps the core. prepare_signal() checks this flag and nacks any signal except SIGKILL. Note that this check tries to be conservative, in the long term we should probably treat the SIGNAL_GROUP_EXIT case equally but this needs more discussion. See marc.info/?l=linux-kernel&m=120508897917439 Notes: - recalc_sigpending() doesn't check SIGNAL_GROUP_COREDUMP. The patch assumes that dump_write/etc paths should never call it, but we can change it as well. - There is another source of TIF_SIGPENDING, freezer. This will be addressed separately. Signed-off-by: Oleg Nesterov <oleg@redhat.com> Tested-by: Mandeep Singh Baines <msb@chromium.org> Cc: Ingo Molnar <mingo@redhat.com> Cc: Neil Horman <nhorman@redhat.com> Cc: "Rafael J. Wysocki" <rjw@sisk.pl> Cc: Roland McGrath <roland@hack.frob.com> Cc: Tejun Heo <tj@kernel.org> Cc: Al Viro <viro@zeniv.linux.org.uk> Signed-off-by: Andrew Morton <akpm@linux-foundation.org> Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Showing 3 changed files with 10 additions and 10 deletions Side-by-side Diff
fs/coredump.c
... | ... | @@ -280,8 +280,8 @@ |
280 | 280 | return nr; |
281 | 281 | } |
282 | 282 | |
283 | -static inline int zap_threads(struct task_struct *tsk, struct mm_struct *mm, | |
284 | - struct core_state *core_state, int exit_code) | |
283 | +static int zap_threads(struct task_struct *tsk, struct mm_struct *mm, | |
284 | + struct core_state *core_state, int exit_code) | |
285 | 285 | { |
286 | 286 | struct task_struct *g, *p; |
287 | 287 | unsigned long flags; |
... | ... | @@ -291,6 +291,9 @@ |
291 | 291 | if (!signal_group_exit(tsk->signal)) { |
292 | 292 | mm->core_state = core_state; |
293 | 293 | nr = zap_process(tsk, exit_code); |
294 | + /* ignore all signals except SIGKILL, see prepare_signal() */ | |
295 | + tsk->signal->flags |= SIGNAL_GROUP_COREDUMP; | |
296 | + clear_tsk_thread_flag(tsk, TIF_SIGPENDING); | |
294 | 297 | } |
295 | 298 | spin_unlock_irq(&tsk->sighand->siglock); |
296 | 299 | if (unlikely(nr < 0)) |
... | ... | @@ -513,12 +516,6 @@ |
513 | 516 | goto fail_creds; |
514 | 517 | |
515 | 518 | old_cred = override_creds(cred); |
516 | - | |
517 | - /* | |
518 | - * Clear any false indication of pending signals that might | |
519 | - * be seen by the filesystem code called to write the core file. | |
520 | - */ | |
521 | - clear_thread_flag(TIF_SIGPENDING); | |
522 | 519 | |
523 | 520 | ispipe = format_corename(&cn, &cprm); |
524 | 521 |
include/linux/sched.h
... | ... | @@ -626,6 +626,7 @@ |
626 | 626 | #define SIGNAL_STOP_STOPPED 0x00000001 /* job control stop in effect */ |
627 | 627 | #define SIGNAL_STOP_CONTINUED 0x00000002 /* SIGCONT since WCONTINUED reap */ |
628 | 628 | #define SIGNAL_GROUP_EXIT 0x00000004 /* group exit in progress */ |
629 | +#define SIGNAL_GROUP_COREDUMP 0x00000008 /* coredump in progress */ | |
629 | 630 | /* |
630 | 631 | * Pending notifications to parent. |
631 | 632 | */ |
kernel/signal.c
... | ... | @@ -854,12 +854,14 @@ |
854 | 854 | * Returns true if the signal should be actually delivered, otherwise |
855 | 855 | * it should be dropped. |
856 | 856 | */ |
857 | -static int prepare_signal(int sig, struct task_struct *p, bool force) | |
857 | +static bool prepare_signal(int sig, struct task_struct *p, bool force) | |
858 | 858 | { |
859 | 859 | struct signal_struct *signal = p->signal; |
860 | 860 | struct task_struct *t; |
861 | 861 | |
862 | - if (unlikely(signal->flags & SIGNAL_GROUP_EXIT)) { | |
862 | + if (signal->flags & (SIGNAL_GROUP_EXIT | SIGNAL_GROUP_COREDUMP)) { | |
863 | + if (signal->flags & SIGNAL_GROUP_COREDUMP) | |
864 | + return sig == SIGKILL; | |
863 | 865 | /* |
864 | 866 | * The process is in the middle of dying, nothing to do. |
865 | 867 | */ |