lkml.org 
[lkml]   [2018]   [Jul]   [17]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
/
Date
From
SubjectRe: [RFC][PATCH 09/11] tty_io: Use do_send_sig_info in __do_SACK to forcibly kill tasks
On 07/16, Eric W. Biederman wrote:
>
> Oleg Nesterov <oleg@redhat.com> writes:
>
> > On 07/10, Eric W. Biederman wrote:
> >>
> >> Therefore use do_send_sig_info in all cases in __do_SAK to kill
> >> tasks as allows for exactly what the code wants to do.
> >
> > OK, but probably the changelog should also mention that now even the global
> > init will be killed if it has this tty opened.
>
> force_sig was ensuring the global init would die. So that isn't a
> change. Mentioning it isn't a bad idea.

I meant another "p->signal->tty == tty" case which uses send_sig(SIGKILL).

As for force_sig(), yes it kills init, but "by accident". See your commit
20ac94378 "do_SAK: Don't recursively take the tasklist_lock", it replaced
send_sig() because it took tasklist_lock.

Nevermind, let me repeat I am not arguing with this change.

But it looks off-topic in this series, why do we need it? Yes, these
send_sig/force_sig are ugly, we need do_send_sig_info(PIDTYPE_TGID). But
__do_SAK() needs more cleanups, do_each_thread() is ugly too by the same
reason, we should not send SIGKILL per-thread. And iirc it is racy either
way, a process can open tty right after it was checkeda process can open
tty right after it was checked.

I think the main loop should be rewritten as

for_each_process(p) {
if (p->signal->tty == tty) {
tty_notice(tty, "SAK: killed process %d (%s): by controlling tty\n",
task_pid_nr(p), p->comm);
goto kill;
}

files = NULL;
for_each_thread(p, t) {
if (t->files == files) /* racy but we do not care */
continue;

task_lock(t);
files = t->files;
i = iterate_fd(files, 0, this_tty, tty);
task_unlock(t);

if (i != 0) {
tty_notice(tty, "SAK: killed process %d (%s): by fd#%d\n",
task_pid_nr(p), p->comm, i - 1);
goto kill;
}
}

continue;
kill:
do_send_sig_info(SIGKILL, SEND_SIG_NOINFO, p, true);
}

If we want to kill init's as well, we can use SEND_SIG_FORCE and this can come
as a separate change, although I am personally fine either way.

Oleg.

\
 
 \ /
  Last update: 2018-07-17 12:59    [W:0.081 / U:6.100 seconds]
©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site