lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [<thread-prev] [day] [month] [year] [list]
Date:   Mon, 28 Mar 2022 11:28:52 +0300
From:   Heikki Krogerus <heikki.krogerus@...ux.intel.com>
To:     Jack Pham <quic_jackp@...cinc.com>
Cc:     Jia-Ju Bai <baijiaju1990@...il.com>,
        Greg KH <gregkh@...uxfoundation.org>, kyletso@...gle.com,
        andy.shevchenko@...il.com, unixbhaskar@...il.com,
        subbaram@...eaurora.org, mrana@...eaurora.org,
        "linux-usb@...r.kernel.org" <linux-usb@...r.kernel.org>,
        linux-kernel <linux-kernel@...r.kernel.org>
Subject: Re: [BUG] usb: typec: ucsi: possible deadlock in ucsi_pr_swap() and
 ucsi_handle_connector_change()

On Fri, Mar 25, 2022 at 01:39:59PM -0700, Jack Pham wrote:
> Hi Heikki,
> 
> On Wed, Feb 09, 2022 at 04:30:31PM +0200, Heikki Krogerus wrote:
> > On Wed, Feb 09, 2022 at 11:50:57AM +0800, Jia-Ju Bai wrote:
> > > Hello,
> > > 
> > > My static analysis tool reports a possible deadlock in the ucsi driver in
> > > Linux 5.16:
> > > 
> > > ucsi_pr_swap()
> > >   mutex_lock(&con->lock); --> Line 962 (Lock A)
> > >   wait_for_completion_timeout(&con->complete, ...) --> Line 981 (Wait X)
> > > 
> > > ucsi_handle_connector_change()
> > >   mutex_lock(&con->lock); --> Line 763 (Lock A)
> > >   complete(&con->complete); --> Line 782 (Wake X)
> > >   complete(&con->complete); --> Line 807 (Wake X)
> > > 
> > > When ucsi_pr_swap() is executed, "Wait X" is performed by holding "Lock A".
> > > If ucsi_handle_connector_change() is executed at this time, "Wake X" cannot
> > > be performed to wake up "Wait X" in ucsi_handle_connector_change(), because
> > > "Lock A" has been already held by ucsi_handle_connector_change(), causing a
> > > possible deadlock.
> > > I find that "Wait X" is performed with a timeout, to relieve the possible
> > > deadlock; but I think this timeout can cause inefficient execution.
> > > 
> > > I am not quite sure whether this possible problem is real.
> > > Any feedback would be appreciated, thanks :)
> > 
> > This is probable a regression from commit ad74b8649bea ("usb: typec:
> > ucsi: Preliminary support for alternate modes"). Can you test does
> > this patch fix the issue (attached)?
> 
> We encountered a slightly different twist to this bug.  Instead of
> deadlocking, we see that the dr_swap() / pr_swap() operations actually
> jump out of the wait_for_completion_timeout() immediately, even before
> any partner change occurs.  This is because the con->complete may
> already have its done flag set to true from the first time
> ucsi_handle_connector_change() runs, and is never reset after that.
> 
> In addition to the unlocking below, I think we need to also add
> reinit_completion() calls at the start of ucsi_{pr,dr}_swap().

OK. I'll add that to the patch.

thanks,

-- 
heikki

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ