From: Jia-Ju Bai <baijiaju1990@gmail.com>
To: Greg KH <gregkh@linuxfoundation.org>, jirislaby@kernel.org
Cc: linux-serial@vger.kernel.org,
linux-kernel <linux-kernel@vger.kernel.org>
Subject: [BUG] tty: serial: possible deadlock in uart_remove_one_port() and uart_hangup()
Date: Sat, 29 Jan 2022 17:34:05 +0800 [thread overview]
Message-ID: <ab5d9322-6bea-9845-c61b-fb68e3bb3a87@gmail.com> (raw)
Hello,
My static analysis tool reports a possible deadlock in the tty driver in
Linux 5.10:
uart_remove_one_port()
mutex_lock(&port->mutex); --> Line 3017 (Lock A)
wait_event(state->remove_wait, ...); --> Line 3019 (Wait X)
mutex_unlock(&port->mutex); --> Line 3021 (Unlock A)
uart_hangup()
mutex_lock(&port->mutex); --> Line 1667 (Lock A)
uart_flush_buffer()
uart_port_unlock()
uart_port_deref()
wake_up(&uport->state->remove_wait); --> Line 68 (Wake X)
mutex_unlock(&port->mutex); --> Line 1684 (Unlock A)
When uart_remove_one_port() is executed, "Wait X" is performed by
holding "Lock A". If uart_hangup() is executed at this time, "Wake X"
cannot be performed to wake up "Wait X" in uart_remove_one_port(),
because "Lock A" has been already hold by uart_remove_one_port(),
causing a possible deadlock.
I am not quite sure whether this possible problem is real and how to fix
it if it is real.
Maybe we can call wait_event() before mutex_lock() in
uart_remove_one_port().
Any feedback would be appreciated, thanks :)
Best wishes,
Jia-Ju Bai
next reply other threads:[~2022-01-29 9:34 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-01-29 9:34 Jia-Ju Bai [this message]
2022-01-29 9:57 ` Greg KH
2022-01-29 10:01 ` Jia-Ju Bai
2022-02-01 6:51 ` Jia-Ju Bai
[not found] ` <20220201090740.3816-1-hdanton@sina.com>
2022-02-05 4:30 ` Jia-Ju Bai
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=ab5d9322-6bea-9845-c61b-fb68e3bb3a87@gmail.com \
--to=baijiaju1990@gmail.com \
--cc=gregkh@linuxfoundation.org \
--cc=jirislaby@kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-serial@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
Powered by JetHome