mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Takashi Iwai <tiwai@suse.de>
To: Hillf Danton <hdanton@sina.com>
Cc: alsa-devel@alsa-project.org,
	Mikhail Gavrilov <mikhail.v.gavrilov@gmail.com>,
	LKML <linux-kernel@vger.kernel.org>
Subject: Re: [PATCH 2/9] ALSA: usb-audio: Fix possible race at sync of urb completions
Date: Tue, 22 Apr 2025 13:03:24 +0200	[thread overview]
Message-ID: <8734e0tq4j.wl-tiwai@suse.de> (raw)
In-Reply-To: <20250422102933.4239-1-hdanton@sina.com>

On Tue, 22 Apr 2025 12:29:31 +0200,
Hillf Danton wrote:
> 
> On Tue, 22 Apr 2025 09:03:20 +0200 Takashi Iwai wrote:
> > On Tue, 22 Apr 2025 01:38:59 +0200, Hillf Danton wrote:
> > > On Mon, 21 Apr 2025 16:36:30 +0200 Takashi Iwai wrote:
> > > > On Mon, 21 Apr 2025 12:43:42 +0200, Hillf Danton wrote:
> > > > > I misread "Which reads and writes are you trying to solve?" though I
> > > > > showed the read/write, but it is a bad case particulay with UAF.
> > > > > 
> > > > > Could you tell us what will happen if the race is not fixed? Could ep
> > > > > be freed with in-flight urbs for example?
> > > > 
> > > > Before the patch, wait_clear_urbs() might return earlier than actually
> > > > all pending eps are finished, so it can be UAF.
> > > > 
> > > Got it.
> > > 
> > > > > Is it still race if the wait loop in wait_clear_urbs() ends before the
> > > > > urb complete callbace completes, given the last sentence in your commit
> > > > > message? If nope, igore my noise please.
> > > > 
> > > > Well, your concern about the missing barrier -- that would
> > > > wait_clear_urbs() missing the refcount decrement, hence it would be
> > > > rather to make the return delayed.  So it shouldn't lead to further
> > > > UAF, but at most it might lead to an unnecessary delay.
> > > > 
> > > > That said, I'm willing to take a fix even for a theoretical issue if
> > > > it clarifies what it really fixes.  But scratching a random surface
> > > > isn't what we want.
> > > > 
> > > Thank you for shedding light on the race, given
> > > a) the mb in 26fbe9772b8c ("USB: core: Fix hang in usb_kill_urb by adding memory barriers")
> > > b) the urb complete callback is invoked in giveback, see __usb_hcd_giveback_urb()
> > > 
> > > use the urb routines instead to close the race.
> > 
> > I'm afraid that it can break things as of this form; the stopped
> > stream might be restarted without reinitializing URBs.  That is, this
> > isn't called only from disconnect or close, but also just for stopping
> > the stream in the middle, too.
> > 
> I'd like to test the change proposed locally, so please tippoint me to
> the test programs that could trigger the break.

Well, you need to follow the code logic.  The function isn't called
only from release / disconnect, but also from the code pattern:
 trigger(STOP) -> prepare -> sync_stop
and the URBs aren't released / re-initialized in this case.

For the problem you raised, I suppose it's better to stick with your
first approach with the manual barriers.  But you'd need to describe
exactly what it does and why it needed as a proper patch.


thanks,

Takashi

      parent reply	other threads:[~2025-04-22 11:03 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <20210929080844.11583-1-tiwai@suse.de>
     [not found] ` <20210929080844.11583-3-tiwai@suse.de>
     [not found]   ` <20250418103533.4078-1-hdanton@sina.com>
2025-04-18 11:08     ` Takashi Iwai
     [not found]       ` <20250418144518.4097-1-hdanton@sina.com>
2025-04-19  6:50         ` Takashi Iwai
     [not found]           ` <20250419080410.4148-1-hdanton@sina.com>
2025-04-20  7:49             ` Takashi Iwai
     [not found]               ` <20250421051832.4179-1-hdanton@sina.com>
2025-04-21  7:23                 ` Takashi Iwai
     [not found]                   ` <20250421104343.4197-1-hdanton@sina.com>
2025-04-21 14:36                     ` Takashi Iwai
     [not found]                       ` <20250421233900.4221-1-hdanton@sina.com>
2025-04-22  7:03                         ` Takashi Iwai
     [not found]                           ` <20250422102933.4239-1-hdanton@sina.com>
2025-04-22 11:03                             ` Takashi Iwai [this message]

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=8734e0tq4j.wl-tiwai@suse.de \
    --to=tiwai@suse.de \
    --cc=alsa-devel@alsa-project.org \
    --cc=hdanton@sina.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mikhail.v.gavrilov@gmail.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

all inboxes | Powered by JetHome®