linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Desmond Cheong Zhi Xi <desmondcheongzx@gmail.com>
To: Jiacheng Xu <578001344xu@gmail.com>
Cc: netdev@vger.kernel.org, linux-bluetooth@vger.kernel.org,
	Jakub Kicinski <kuba@kernel.org>,
	"open list:NETWORKING [GENERAL]" <netdev@vger.kernel.org>,
	Eric Dumazet <edumazet@google.com>,
	linux-kernel@vger.kernel.org, marcel@holtmann.org,
	johan.hedberg@gmail.com, David Miller <davem@davemloft.net>,
	luiz.dentz@gmail.com, Paolo Abeni <pabeni@redhat.com>
Subject: Re: possible deadlock in rfcomm_sk_state_change
Date: Mon, 29 Aug 2022 23:48:01 -0700	[thread overview]
Message-ID: <f53dfd70-f8b3-8401-3f5a-d738b2f242e1@gmail.com> (raw)
In-Reply-To: <CAO4S-mfTNEKCs8ZQcT09wDzxX8MfidmbTVzaFMD3oG4i7Ytynw@mail.gmail.com>

+cc Bluetooth and Networking maintainers

Hi Jiacheng,

On 28/8/22 04:03, Jiacheng Xu wrote:
> Hi,
> 
> I believe the deadlock is more than possible but actually real.
> I got a poc that could stably trigger the deadlock.
> 
> poc: https://drive.google.com/file/d/1PjqvMtHsrrGM1MIRGKl_zJGR-teAMMQy/view?usp=sharing
> 
> Description/Root cause:
> In rfcomm_sock_shutdown(), lock_sock() is called when releasing and
> shutting down socket.
> However, lock_sock() has to be called once more when the sk_state is
> changed because the
> lock is not always held when rfcomm_sk_state_change() is called. One
> such call stack is:
> 
>    rfcomm_sock_shutdown():
>      lock_sock();
>      __rfcomm_sock_close():
>        rfcomm_dlc_close():
>          __rfcomm_dlc_close():
>            rfcomm_dlc_lock();
>            rfcomm_sk_state_change():
>              lock_sock();
> 
> Besides the recursive deadlock, there is also an
> issue of a lock hierarchy inversion between rfcomm_dlc_lock() and
> lock_sock() if the socket is locked in rfcomm_sk_state_change().


Thanks for the poc and for following the trail all the way to the root 
cause - this was a known issue and I didn't realize the patch wasn't 
applied.

>  > Reference: 
https://lore.kernel.org/all/20211004180734.434511-1-desmondcheongzx@gmail.com/
> 

Fwiw, I tested the patch again with syzbot. It still applies cleanly to 
the head of bluetooth-next and seems to address the root cause.

Any thoughts from the maintainers on this issue and the proposed fix?

Best,
Desmond

  reply	other threads:[~2022-08-30  6:48 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-08-27 16:19 possible deadlock in rfcomm_sk_state_change Jiacheng Xu
2022-08-28 11:03 ` Jiacheng Xu
2022-08-30  6:48   ` Desmond Cheong Zhi Xi [this message]
2022-08-30 17:41     ` Luiz Augusto von Dentz
2022-08-30 19:23       ` Luiz Augusto von Dentz

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=f53dfd70-f8b3-8401-3f5a-d738b2f242e1@gmail.com \
    --to=desmondcheongzx@gmail.com \
    --cc=578001344xu@gmail.com \
    --cc=davem@davemloft.net \
    --cc=edumazet@google.com \
    --cc=johan.hedberg@gmail.com \
    --cc=kuba@kernel.org \
    --cc=linux-bluetooth@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=luiz.dentz@gmail.com \
    --cc=marcel@holtmann.org \
    --cc=netdev@vger.kernel.org \
    --cc=pabeni@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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).