From: ebiederm@xmission.com (Eric W. Biederman)
To: Kirill Tkhai <ktkhai@virtuozzo.com>
Cc: gregkh@linuxfoundation.org, jslaby@suse.com, oleg@redhat.com,
linux-kernel@vger.kernel.org
Subject: Re: [PATCH v2 3/3] tty: Use RCU read lock to iterate tasks and threads in __do_SAK()
Date: Wed, 17 Jan 2018 10:54:00 -0600 [thread overview]
Message-ID: <87lggwh1ef.fsf@xmission.com> (raw)
In-Reply-To: <151619279470.5683.15554197416743431023.stgit@localhost.localdomain> (Kirill Tkhai's message of "Wed, 17 Jan 2018 15:39:54 +0300")
Kirill Tkhai <ktkhai@virtuozzo.com> writes:
> There were made several efforts to make __do_SAK()
> working in process context long ago, but it does
> not solves the problem completely. Since __do_SAK()
> may take tasklist_lock for a long time, the concurent
> processes, waiting for write lock with interrupts
> disabled (e.g., forking), get into the same situation
> like __do_SAK() would have been executed in interrupt
> context. I've observed several hard lockups on 3.10
> kernel running 200 containers, caused by long duration
> of copy_process()->write_lock_irq() after SAK was sent
> to a tty. Current mainline kernel has the same problem.
>
> The solution is to use RCU to iterate processes and threads.
> Task list integrity is the only reason we taken tasklist_lock
> before, as tty subsys primitives mostly take it for reading
> also (e.g., __proc_set_tty). RCU read lock is enough for that.
> This patch solves the problem and makes __do_SAK() to be
> not greedy of tasklist_lock. That should prevent hard lockups
> I've pointed above.
__do_SAK() needs to be 100% accurate. I do not see the rcu_read_lock
guaranteeing that new processes created while the process list is being
iterated that happen to have a reference to the tty will be seen.
So I do not believe this is the actual fix to the problem. Especially
not if we intend to for SAK to remain a secure attention key that
guarantees no other processes have access to the tty.
Eric
> Signed-off-by: Kirill Tkhai <ktkhai@virtuozzo.com>
> ---
> drivers/tty/tty_io.c | 4 +++-
> 1 file changed, 3 insertions(+), 1 deletion(-)
>
> diff --git a/drivers/tty/tty_io.c b/drivers/tty/tty_io.c
> index 89326cee2403..55115e65668d 100644
> --- a/drivers/tty/tty_io.c
> +++ b/drivers/tty/tty_io.c
> @@ -2724,7 +2724,9 @@ void __do_SAK(struct tty_struct *tty)
> task_pid_nr(p), p->comm);
> send_sig(SIGKILL, p, 1);
> } while_each_pid_task(session, PIDTYPE_SID, p);
> + read_unlock(&tasklist_lock);
>
> + rcu_read_lock();
> /* Now kill any processes that happen to have the tty open */
> for_each_process(p) {
> if (p->signal->tty == tty) {
> @@ -2754,7 +2756,7 @@ void __do_SAK(struct tty_struct *tty)
> kill:
> send_sig(SIGKILL, p, 1);
> }
> - read_unlock(&tasklist_lock);
> + rcu_read_unlock();
> #endif
> }
>
next prev parent reply other threads:[~2018-01-17 16:54 UTC|newest]
Thread overview: 15+ messages / expand[flat|nested] mbox.gz Atom feed top
2018-01-17 12:39 [PATCH v2 0/3] tty: Make __do_SAK() less greedy in regard to tasklist_lock Kirill Tkhai
2018-01-17 12:39 ` [PATCH v2 1/3] Revert "do_SAK: Don't recursively take the tasklist_lock" Kirill Tkhai
2018-01-17 17:18 ` Eric W. Biederman
2018-01-17 17:34 ` Oleg Nesterov
2018-01-17 17:49 ` Eric W. Biederman
2018-01-17 18:04 ` Oleg Nesterov
2018-01-17 18:37 ` Eric W. Biederman
2018-01-17 20:43 ` Oleg Nesterov
2018-01-18 10:07 ` Kirill Tkhai
2018-01-18 9:59 ` Kirill Tkhai
2018-01-17 12:39 ` [PATCH v2 2/3] tty: Avoid threads files iterations in __do_SAK() Kirill Tkhai
2018-01-17 12:39 ` [PATCH v2 3/3] tty: Use RCU read lock to iterate tasks and threads " Kirill Tkhai
2018-01-17 16:54 ` Eric W. Biederman [this message]
2018-01-17 17:39 ` Oleg Nesterov
2018-01-18 10:11 ` Kirill Tkhai
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=87lggwh1ef.fsf@xmission.com \
--to=ebiederm@xmission.com \
--cc=gregkh@linuxfoundation.org \
--cc=jslaby@suse.com \
--cc=ktkhai@virtuozzo.com \
--cc=linux-kernel@vger.kernel.org \
--cc=oleg@redhat.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.