From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=100.103.45.18 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796500425; b=nXnB2Z6EtEqNA1ngrnytJCzZDW+SZwRJlr3pncxhEId3eKDGerrRVLSyZlkbNC1uiPtO C9vWa6ORAYrvgajKqeftd8C0RJ7gyvyRZE3+Hga5UQyHVRDsCCFb1h0jQZdLy6IajIENP M3nRXDrs/AwGtTQB2GjxaJfZgsX+wy6+pK7n8Coqz/1Hc78da4pcw5CKkENW1vvNhrALA VOgOnaxYeNzu0FWgcigi537+M0u6NveBg2qsfgKLX98udnowh7agnVbn7oWAWz50ZrzHy pt4qYvCoSYX13Ke2U5etZ3f6UOJ/q0MNkzr4c+Ro10c2C4ZCxXnExWyozR592N/ybZQ== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796500425; h=Received:DKIM-Signature:Message-ID:From:Subject:Reply-To:To:Cc: In-Reply-To:References:Content-Type:Content-Transfer-Encoding:Date; bh=DSbKfwQA39cM7hT0Qmu6XD2+SL/lqf6mV3fHmkgiMvg=; b=aNN1Eg8BC7xzn8OJuDrIIG/PZ5FOaTfOzYf2+AFydOvOdyjNNw3AO2ilYVUTDgQLpifI wokw0JL/TlyYEWZ51yy4pbMhzS/r9R5wPtRwGfDeKeeUje+8uo40aenNMdm7L/aIeNc3C xCAH0ggaTl+Z1+ejCA3bNIi3CDkW03/S3MrozJF9xRIbAMyb9HcIqUvlwPbLh+slCOkkE uNDPQumDJDSasuZ9A17rcnH7SNRrHwE2pRI5Mv1TJsQHHTDisys2uKkNQJBB5EDdzH2yY agQHH5NwStUQRHxcv8c7uKu7quU4hJmjJpasxiOcwHnMx+A4Sk8QacDRwQFJeQ0cwrg== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b="IQu/wSJa"; arc=none smtp.remote-ip=100.103.45.18 Received: from smtp.kernel.org (quasi.space.kernel.org [100.103.45.18]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (prime256v1)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 4C571606A32F for ; Sat, 5 Dec 2026 19:53:45 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=IQu/wSJa Received: by smtp.kernel.org (Postfix) with ESMTPSA id CCBD91F00A11; Sat, 5 Dec 2026 19:53:44 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1796500424; bh=DSbKfwQA39cM7hT0Qmu6XD2+SL/lqf6mV3fHmkgiMvg=; h=From:Subject:Reply-To:To:Cc:In-Reply-To:References:Date; b=IQu/wSJaoY1Yhb8w29CZCbqnwjUo2zxMk2in3XUGTa4KtjQXUnbzDCYmMdWOe/6iS IEMHS/x8w4cLanBiwKcDPUaEWzDWGdfwyEblpahOcMGQgW3aQa3CvYsi0p0ZdArqAT q8+UGlYS59Z5SQde/+8K1C+N+4/YQm2UwQd+p5v3AjvnW3dO2VaBDEQCodGFkugw9c fxkIffJqABB012KFCYjVHx+htgVNloErsaRiNJa6mEbjo+z8mUOYD2Jgkx+ZOnaNsU HyWqNs8Q0h/076U8ElQIegPiwDyhPFPrTsLM9nUZCuqgpCjexg7uNhg/kDMCWVwBeF STBmhSLjZejAA== Message-ID: From: sashiko-bot@kernel.org Subject: Re: [PATCH v2 2/2] ALSA: usb-audio: Reuse active sync endpoint format for implicit feedback Reply-To: sashiko-reviews@lists.linux.dev To: "Lee Volkov" Cc: linux-sound@vger.kernel.org In-Reply-To: <20261205192928.27775-3-voilthuman@gmail.com> References: <20261205192928.27775-1-voilthuman@gmail.com> <20261205192928.27775-3-voilthuman@gmail.com> Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable Date: Sat, 05 Dec 2026 19:53:44 +0000 X-Mailing-List: linux-sound@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list Thank you for your contribution! Sashiko AI review found 5 potential issues to consider: - [Medium] ALSA: usb-audio: active sync_fmt reuse may open wrong endpoint - [Medium] ALSA: usb-audio: active sync_fmt reuse allows conflicting shared iface altsets - [Medium] sound/usb: TOCTOU between sync format lookup and snd_usb_endpoint_open() - [Low] ALSA: usb-audio: Fixes tag should cite bf6313a0ff76 instead of 5d15f1eb4560 - [Low] ALSA: usb-audio: unlocked read of subs->sync_endpoint in snd_usb_hw_params() -- commit 53b72b9d9802712afce88d75226c95a44262bed2 Author: Lee Volkov > ALSA: usb-audio: Reuse active sync endpoint format for implicit feedback > > On devices where implicit feedback shares a capture endpoint with > multiple altsettings (such as Solid State Logic SSL 12, where 16/12ch > capture altsets support up to 96 kHz and 10ch Altset 3 supports up to > 192 kHz), opening capture on a non-first altsetting (e.g. Altset 3 at > 48 or 96 kHz) and then starting playback triggers a failure: > > snd_usb_find_implicit_fb_sync_format() scans subs->fmt_list from the > first entry and picks Altset 1 because it also matches the rate and > channel-agnostic check, ignoring that the shared sync endpoint is > already open in Altset 3. snd_usb_endpoint_open() then rejects the > mismatch in endpoint_compatible() and fails playback with -EINVAL > ("Incompatible EP setup for 0x81"). > > Pass the caller's current subs->sync_endpoint (ref_ep) so we look up the > live sync endpoint with snd_usb_get_endpoint() under chip->mutex and > only reuse ep->cur_audiofmt when it is in use by another stream > (ep !=3D ref_ep || ep->opened > 1). This prevents a repeated hw_params() > call without hw_free() from pinning the sync endpoint to the caller's > own about-to-be-closed format. > > Fixes: 5d15f1eb4560 ("ALSA: usb-audio: Choose audioformat of a counter-pa= rt substream") > Cc: stable@vger.kernel.org > Signed-off-by: Lee Volkov [Severity: Low] Should the Fixes tag cite bf6313a0ff76 ("ALSA: usb-audio: Refactor endpoint management") instead of 5d15f1eb4560 ("ALSA: usb-audio: Choose audioformat of a counter-part substream")? Commit 5d15f1eb4560 only changed the shared-altset fallback branch in snd_usb_find_implicit_fb_sync_format(). Scanning subs->fmt_list without checking the active sync endpoint format and rejecting mismatches in endpoint_compatible() was introduced by bf6313a0ff76 and later factored out into sound/usb/implicit.c by 9fddc15e8039 ("ALSA: usb-audio: Factor out the implicit feedback quirk code"). > diff --git a/sound/usb/implicit.c b/sound/usb/implicit.c > index bd4d569a8190c..755df2b1d2e53 100644 > --- a/sound/usb/implicit.c > +++ b/sound/usb/implicit.c [ ... ] > @@ -475,6 +478,26 @@ snd_usb_find_implicit_fb_sync_format(struct snd_usb_= audio *chip, > if (!subs) > goto end; > =20 > + /* > + * If the shared sync endpoint is already open by another stream in a > + * compatible format, reuse that active audioformat instead of picking > + * another altsetting and failing endpoint_compatible() later. > + */ > + scoped_guard(mutex, &chip->mutex) { > + ep =3D snd_usb_get_endpoint(chip, target->sync_ep); > + if (ep && ep->opened && ep->cur_audiofmt && > + (ep !=3D ref_ep || ep->opened > 1) && > + match_endpoint_audioformats(subs, ep->cur_audiofmt, > + params_rate(params), > + params_channels(params), > + params_format(params))) > + active_fmt =3D ep->cur_audiofmt; > + } > + if (active_fmt) { > + sync_fmt =3D active_fmt; > + goto end; > + } [Severity: Medium] Can returning ep->cur_audiofmt without checking membership in subs->fmt_list cause snd_usb_hw_params() to open the wrong endpoint? snd_usb_hw_params() calls snd_usb_endpoint_open() with is_sync_ep set to (fmt =3D=3D sync_fmt), which selects fp->endpoint when false: sound/usb/endpoint.c:snd_usb_endpoint_open() { ... int ep_num =3D is_sync_ep ? fp->sync_ep : fp->endpoint; ... } If another stream already opened target->sync_ep with is_sync_ep =3D true (for example via the shared-altset fallback or explicit sync), ep->cur_audiofmt points to that stream's format (fmt1) where fmt1->endpoint is its data endpoint rather than target->sync_ep. Returning fmt1 makes fmt =3D=3D sync_fmt false, so snd_usb_endpoint_open() opens fmt1->endpoint = and binds the other stream's outbound endpoint as sync_source, stalling implicit-feedback playback. This also bypasses find_matching_substream()'s fmt_type filter when another fmt_type stream holds target->sync_ep. Snapshotting active_fmt =3D ep->cur_audiofmt under chip->mutex and matching fp =3D=3D active_fmt inside the existing subs->fmt_list loop would guarantee both endpoint and fmt_type match. [Severity: Medium] Can reusing ep->cur_audiofmt allow playback and capture to open different altsettings on a shared USB interface? On devices where playback and capture share one USB interface with multiple altsettings, capture can open Altset 2 while playback later requests Altset 1 at the same sample rate and PCM format. Because match_endpoint_audioformats() still returns non-zero when channels differ, this returns capture's Altset 2 format instead of letting endpoint_compatible() reject the mismatch with -EINVAL. snd_usb_endpoint_open() increments iface_ref->opened without checking for altsetting mismatches, and snd_usb_endpoint_prepare() skips endpoint_set_interface() once iface_ref->need_setup is false, leaving the interface in Altset 2 while playback submits Altset 1 URBs. Reusing ep->cur_audiofmt only when ep->cur_audiofmt->iface !=3D target->iface || ep->cur_audiofmt->altsetting =3D=3D target->altsetting avoids this. [Severity: Medium] Can a concurrent capture hw_params() race with this lookup and still fail playback with -EINVAL? snd_usb_hw_params() drops chip->mutex here and then runs blocking USB autoresume, power-domain, stop/drain, and close_endpoints() operations before opening subs->sync_endpoint under a separate chip->mutex acquisition: CPU0 (playback) CPU1 (capture) snd_usb_hw_params() snd_usb_find_implicit_fb_sync_format() lock(&chip->mutex) ep->opened =3D=3D 0 -> Altset 1 unlock(&chip->mutex) snd_usb_lock_shutdown() snd_usb_autoresume() (blocks) snd_usb_hw_params() ... snd_usb_endpoint_open() ep->cur_audiofmt =3D Altset 3 snd_usb_endpoint_open(Altset 1) endpoint_compatible() <-- fails with -EINVAL The same window affects repeated playback hw_params() without hw_free() if capture opens ep before close_endpoints() runs. Resolving the active format under the same chip->mutex acquisition that opens subs->sync_endpoint (after close_endpoints()) would eliminate this race. [ ... ] > diff --git a/sound/usb/pcm.c b/sound/usb/pcm.c > index 57a26492dd614..5f19cbf2557c5 100644 > --- a/sound/usb/pcm.c > +++ b/sound/usb/pcm.c > @@ -507,6 +507,7 @@ int snd_usb_hw_params(struct snd_usb_substream *subs, > sync_fmt =3D snd_usb_find_implicit_fb_sync_format(chip, fmt, > hw_params, > !subs->direction, > + subs->sync_endpoint, > &sync_fixed_rate); > if (!sync_fmt) { > usb_audio_dbg(chip, [Severity: Low] Does reading subs->sync_endpoint here race with snd_usb_stream_disconnect() under KCSAN? snd_usb_hw_params() has not yet called snd_usb_lock_shutdown(chip) at this point, while __usb_audio_disconnect() clears subs->sync_endpoint under register_mutex without holding runtime->buffer_mutex: CPU0 CPU1 snd_usb_hw_params() __usb_audio_disconnect() atomic_inc_return(&chip->shutdown) snd_refcount_sync(&chip->usage_count) read subs->sync_endpoint snd_usb_stream_disconnect() subs->sync_endpoint =3D NULL <-- data race snd_usb_lock_shutdown() ref_ep is only compared by pointer value and snd_usb_lock_shutdown() later aborts with -EIO, so this is a benign KCSAN data race on repeated hw_params() during disconnect. Moving the lookup under snd_usb_lock_shutdown(chip) or using READ_ONCE()/WRITE_ONCE() avoids it. --=20 Sashiko AI review =C2=B7 https://sashiko.dev/#/patchset/20261205192928.2777= 5-1-voilthuman@gmail.com?part=3D2