From: Jiri Slaby <jirislaby@kernel.org>
To: kovalev@altlinux.org, gregkh@linuxfoundation.org,
linux-kernel@vger.kernel.org, linux-serial@vger.kernel.org
Cc: lvc-project@linuxtesting.org, dutyrok@altlinux.org,
oficerovas@altlinux.org, stable@vger.kernel.org
Subject: Re: [PATCH] tty: Fix possible deadlock in tty_buffer_flush
Date: Thu, 9 May 2024 08:41:18 +0200 [thread overview]
Message-ID: <e167d14c-76d3-46b4-aca5-b6003f9cbfc1@kernel.org> (raw)
In-Reply-To: <20240508093005.1044815-1-kovalev@altlinux.org>
On 08. 05. 24, 11:30, kovalev@altlinux.org wrote:
> From: Vasiliy Kovalev <kovalev@altlinux.org>
>
> A possible scenario in which a deadlock may occur is as follows:
>
> flush_to_ldisc() {
>
> mutex_lock(&buf->lock);
>
> tty_port_default_receive_buf() {
> tty_ldisc_receive_buf() {
> n_tty_receive_buf2() {
> n_tty_receive_buf_common() {
> n_tty_receive_char_special() {
> isig() {
> tty_driver_flush_buffer() {
> pty_flush_buffer() {
> tty_buffer_flush() {
>
> mutex_lock(&buf->lock); (DEADLOCK)
>
> flush_to_ldisc() and tty_buffer_flush() functions they use the same mutex
> (&buf->lock), but not necessarily the same struct tty_bufhead object.
"not necessarily" -- so does it mean that it actually can happen (and we
should fix it) or not at all (and we should annotate the mutex)?
> However, you should probably use a separate mutex for the
> tty_buffer_flush() function to exclude such a situation.
...
> Cc: stable@vger.kernel.org
What commit does this fix?
> --- a/drivers/tty/tty_buffer.c
> +++ b/drivers/tty/tty_buffer.c
> @@ -226,7 +226,7 @@ void tty_buffer_flush(struct tty_struct *tty, struct tty_ldisc *ld)
>
> atomic_inc(&buf->priority);
>
> - mutex_lock(&buf->lock);
> + mutex_lock(&buf->flush_mtx);
Hmm, how does this protect against concurrent buf pickup. We free it
here and the racing thread can start using it, or?
> /* paired w/ release in __tty_buffer_request_room; ensures there are
> * no pending memory accesses to the freed buffer
> */
thanks,
--
js
suse labs
next prev parent reply other threads:[~2024-05-09 6:41 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-05-08 9:30 [PATCH] tty: Fix possible deadlock in tty_buffer_flush kovalev
2024-05-09 6:41 ` Jiri Slaby [this message]
2024-05-09 10:32 ` Vasiliy Kovalev
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=e167d14c-76d3-46b4-aca5-b6003f9cbfc1@kernel.org \
--to=jirislaby@kernel.org \
--cc=dutyrok@altlinux.org \
--cc=gregkh@linuxfoundation.org \
--cc=kovalev@altlinux.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-serial@vger.kernel.org \
--cc=lvc-project@linuxtesting.org \
--cc=oficerovas@altlinux.org \
--cc=stable@vger.kernel.org \
/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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox