lkml.org 
[lkml]   [2024]   [May]   [9]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
/
Date
SubjectRe: [PATCH] tty: Fix possible deadlock in tty_buffer_flush
From
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


\
 
 \ /
  Last update: 2024-05-09 08:41    [W:0.049 / U:2.248 seconds]
©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site