mirror of
				https://github.com/torvalds/linux.git
				synced 2025-11-04 10:40:15 +02:00 
			
		
		
		
	coredump: ensure that SIGKILL always kills the dumping thread
prepare_signal() blesses SIGKILL sent to the dumping process but this signal can be "lost" anyway. The problems is, complete_signal() sees SIGNAL_GROUP_EXIT and skips the "kill them all" logic. And even if the dumping process is single-threaded (so the target is always "correct"), the group-wide SIGKILL is not recorded in task->pending and thus __fatal_signal_pending() won't be true. A multi-threaded case has even more problems. And even ignoring all technical details, SIGNAL_GROUP_EXIT doesn't look right to me. This coredumping process is not exiting yet, it can do a lot of work dumping the core. With this patch the dumping process doesn't have SIGNAL_GROUP_EXIT, we set signal->group_exit_task instead. This makes signal_group_exit() true and thus this should equally close the races with exit/exec/stop but allows to kill the dumping thread reliably. Notes: - It is not clear what should we do with ->group_exit_code if the dumper was killed, see the next change. - we need more (hopefully straightforward) changes to ensure that SIGKILL actually interrupts the coredump. Basically we need to check __fatal_signal_pending() in dump_write() and dump_seek(). 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>
This commit is contained in:
		
							parent
							
								
									403bad72b6
								
							
						
					
					
						commit
						6cd8f0acae
					
				
					 1 changed files with 8 additions and 2 deletions
				
			
		| 
						 | 
					@ -263,7 +263,6 @@ static int zap_process(struct task_struct *start, int exit_code)
 | 
				
			||||||
	struct task_struct *t;
 | 
						struct task_struct *t;
 | 
				
			||||||
	int nr = 0;
 | 
						int nr = 0;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	start->signal->flags = SIGNAL_GROUP_EXIT;
 | 
					 | 
				
			||||||
	start->signal->group_exit_code = exit_code;
 | 
						start->signal->group_exit_code = exit_code;
 | 
				
			||||||
	start->signal->group_stop_count = 0;
 | 
						start->signal->group_stop_count = 0;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
| 
						 | 
					@ -291,8 +290,9 @@ static int zap_threads(struct task_struct *tsk, struct mm_struct *mm,
 | 
				
			||||||
	if (!signal_group_exit(tsk->signal)) {
 | 
						if (!signal_group_exit(tsk->signal)) {
 | 
				
			||||||
		mm->core_state = core_state;
 | 
							mm->core_state = core_state;
 | 
				
			||||||
		nr = zap_process(tsk, exit_code);
 | 
							nr = zap_process(tsk, exit_code);
 | 
				
			||||||
 | 
							tsk->signal->group_exit_task = tsk;
 | 
				
			||||||
		/* ignore all signals except SIGKILL, see prepare_signal() */
 | 
							/* ignore all signals except SIGKILL, see prepare_signal() */
 | 
				
			||||||
		tsk->signal->flags |= SIGNAL_GROUP_COREDUMP;
 | 
							tsk->signal->flags = SIGNAL_GROUP_COREDUMP;
 | 
				
			||||||
		clear_tsk_thread_flag(tsk, TIF_SIGPENDING);
 | 
							clear_tsk_thread_flag(tsk, TIF_SIGPENDING);
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
	spin_unlock_irq(&tsk->sighand->siglock);
 | 
						spin_unlock_irq(&tsk->sighand->siglock);
 | 
				
			||||||
| 
						 | 
					@ -343,6 +343,7 @@ static int zap_threads(struct task_struct *tsk, struct mm_struct *mm,
 | 
				
			||||||
				if (unlikely(p->mm == mm)) {
 | 
									if (unlikely(p->mm == mm)) {
 | 
				
			||||||
					lock_task_sighand(p, &flags);
 | 
										lock_task_sighand(p, &flags);
 | 
				
			||||||
					nr += zap_process(p, exit_code);
 | 
										nr += zap_process(p, exit_code);
 | 
				
			||||||
 | 
										p->signal->flags = SIGNAL_GROUP_EXIT;
 | 
				
			||||||
					unlock_task_sighand(p, &flags);
 | 
										unlock_task_sighand(p, &flags);
 | 
				
			||||||
				}
 | 
									}
 | 
				
			||||||
				break;
 | 
									break;
 | 
				
			||||||
| 
						 | 
					@ -394,6 +395,11 @@ static void coredump_finish(struct mm_struct *mm)
 | 
				
			||||||
	struct core_thread *curr, *next;
 | 
						struct core_thread *curr, *next;
 | 
				
			||||||
	struct task_struct *task;
 | 
						struct task_struct *task;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						spin_lock_irq(¤t->sighand->siglock);
 | 
				
			||||||
 | 
						current->signal->group_exit_task = NULL;
 | 
				
			||||||
 | 
						current->signal->flags = SIGNAL_GROUP_EXIT;
 | 
				
			||||||
 | 
						spin_unlock_irq(¤t->sighand->siglock);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	next = mm->core_state->dumper.next;
 | 
						next = mm->core_state->dumper.next;
 | 
				
			||||||
	while ((curr = next) != NULL) {
 | 
						while ((curr = next) != NULL) {
 | 
				
			||||||
		next = curr->next;
 | 
							next = curr->next;
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
		Loading…
	
		Reference in a new issue