FAILED: patch "[PATCH] ALSA: aloop: Don't constrain playback params in notify mode" failed to apply to 5.15-stable tree
Subsystems (2)
Sasha Levin
maintainerThe patch below does not apply to the 5.15-stable tree.
If someone wants it applied there, or to any other stable or longterm tree, then please email the backport, including the original git commit id to <[email protected]>.
To reproduce the conflict and resubmit, you may use the following commands:
git fetch https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git/ linux-5.15.y
git checkout FETCH_HEAD
git cherry-pick -x ded106036984a9dd766e7e1451b02e2d15c81438
# <resolve conflicts, build, test, etc.>
git commit -s
git send-email --to '<[email protected]>' --in-reply-to '[email protected]' --subject-prefix 'PATCH 5.15.y' 'HEAD^..'
Thanks,
Sasha
------------------ original commit in Linus's tree ------------------
From ded106036984a9dd766e7e1451b02e2d15c81438 Mon Sep 17 00:00:00 2001
From: Henrik Enquist <[email protected]>
Date: Sat, 3 Oct 2026 15:26:11 +0200
Subject: [PATCH] ALSA: aloop: Don't constrain playback params in notify mode
With notify enabled (the pcm_notify module parameter or the "PCM Notify" control), the playback side of a cable may change format, rate and channels while a capture is running. loopback_check_format() then stops the capture and notifies the "PCM Slave" controls, so that the capture application can reopen with the new parameters. For this reason loopback_open() still gives a notify mode playback the unconstrained loopback_pcm_hardware.
Since commit 898dfe4687f4 ("ALSA: aloop: Fix racy hw constraints adjustment") the hw rules refine against the shared cable->hw instead of the substream's own runtime->hw. This pins the playback side to the parameters of an open capture whatever the notify setting is. A player probing the device sees only the capture's rate, format and channels, and the format change path in loopback_check_format() can't be reached by a new playback.
Skip the format, rate and channels rules for the playback substream when notify is enabled. Skip the period bytes rule as well: with a sound timer source, params_change() already takes the period size from a notify mode playback, and keeping the old capture's period bytes leaves a playback at another rate with a period that doesn't match the timer. The capture side stays constrained to the cable parameters.
The capture stop this makes reachable again was hardened by commit 826af7fa62e3 ("ALSA: aloop: Fix racy access at PCM trigger") and commit e5c33cdc6f40 ("ALSA: aloop: Fix peer runtime UAF during format-change stop"), which need to be applied first when backporting.
Reproducer, with notify enabled on the cable:
arecord -D hw:Loopback,1,0 -r 44100 -f S32_LE -c 2 /dev/null & aplay -D hw:Loopback,0,0 96k.wav
Before: aplay is forced to 44100 Hz and the capture keeps running.
After: aplay runs at 96000 Hz, the capture is stopped and "PCM Slave Rate" reports 96000.
--- sound/drivers/aloop.c | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+)
sound/drivers/aloop.c +20 -0
@@ -1073,6 +1073,18 @@ static unsigned int get_cable_index(struct snd_pcm_substream *substream)return !substream->stream; } +/* +* In notify mode the playback side may change format, rate, channels and, +* with a sound timer, the period size. A running capture that no longer +* matches is stopped by loopback_check_format(). +* call in loopback->cable_lock +*/ +static bool loopback_playback_unconstrained (struct loopback_pcm *dpcm) +{ +return dpcm->substream->stream ==SNDRV_PCM_STREAM_PLAYBACK && +get_notify (dpcm); +} +static int rule_format (struct snd_pcm_hw_params *params,struct snd_pcm_hw_rule *rule) {
@@ -1082,6 +1094,8 @@ static int rule_format(struct snd_pcm_hw_params *params,snd_mask_none (&m); scoped_guard(mutex, &dpcm->loopback->cable_lock) { +if (loopback_playback_unconstrained (dpcm)) +return 0 ; m.bits[0 ] = (u_int32_t )cable->hw.formats; m.bits[1 ] = (u_int32_t)(cable->hw.formats >>32 ); }
@@ -1096,6 +1110,8 @@ static int rule_rate(struct snd_pcm_hw_params *params,struct snd_interval t; scoped_guard(mutex, &dpcm->loopback->cable_lock) { +if (loopback_playback_unconstrained (dpcm)) +return 0 ; t.min = cable->hw.rate_min; t.max = cable->hw.rate_max; }
@@ -1112,6 +1128,8 @@ static int rule_channels(struct snd_pcm_hw_params *params,struct snd_interval t; scoped_guard(mutex, &dpcm->loopback->cable_lock) { +if (loopback_playback_unconstrained (dpcm)) +return 0 ; t.min = cable->hw.channels_min; t.max = cable->hw.channels_max; }
@@ -1128,6 +1146,8 @@ static int rule_period_bytes(struct snd_pcm_hw_params *params,struct snd_interval t; scoped_guard(mutex, &dpcm->loopback->cable_lock) { +if (loopback_playback_unconstrained (dpcm)) +return 0 ; t.min = cable->hw.period_bytes_min; t.max = cable->hw.period_bytes_max; }
Signature · 1 line
2.53.0
Sasha Levin
maintainerPATCH 1/1 ALSA: aloop: Don't constrain playback params in notify mode
From: Henrik Enquist <[email protected]>
[ Upstream commit ded106036984a9dd766e7e1451b02e2d15c81438 ]
With notify enabled (the pcm_notify module parameter or the "PCM Notify" control), the playback side of a cable may change format, rate and channels while a capture is running. loopback_check_format() then stops the capture and notifies the "PCM Slave" controls, so that the capture application can reopen with the new parameters. For this reason loopback_open() still gives a notify mode playback the unconstrained loopback_pcm_hardware.
Since commit 898dfe4687f4 ("ALSA: aloop: Fix racy hw constraints adjustment") the hw rules refine against the shared cable->hw instead of the substream's own runtime->hw. This pins the playback side to the parameters of an open capture whatever the notify setting is. A player probing the device sees only the capture's rate, format and channels, and the format change path in loopback_check_format() can't be reached by a new playback.
Skip the format, rate and channels rules for the playback substream when notify is enabled. Skip the period bytes rule as well: with a sound timer source, params_change() already takes the period size from a notify mode playback, and keeping the old capture's period bytes leaves a playback at another rate with a period that doesn't match the timer. The capture side stays constrained to the cable parameters.
The capture stop this makes reachable again was hardened by commit 826af7fa62e3 ("ALSA: aloop: Fix racy access at PCM trigger") and commit e5c33cdc6f40 ("ALSA: aloop: Fix peer runtime UAF during format-change stop"), which need to be applied first when backporting.
Reproducer, with notify enabled on the cable:
arecord -D hw:Loopback,1,0 -r 44100 -f S32_LE -c 2 /dev/null & aplay -D hw:Loopback,0,0 96k.wav
Before: aplay is forced to 44100 Hz and the capture keeps running.
After: aplay runs at 96000 Hz, the capture is stopped and "PCM Slave Rate" reports 96000.
--- sound/drivers/aloop.c | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+)
sound/drivers/aloop.c +20 -0
@@ -960,6 +960,11 @@ static int rule_format(struct snd_pcm_hw_params *params,snd_mask_none (&m);mutex_lock (&dpcm->loopback->cable_lock); +if (dpcm->substream->stream ==SNDRV_PCM_STREAM_PLAYBACK && +get_notify (dpcm)) { +mutex_unlock (&dpcm->loopback->cable_lock); +return 0 ; + } m.bits[0 ] = (u_int32_t )cable->hw.formats; m.bits[1 ] = (u_int32_t)(cable->hw.formats >>32 );mutex_unlock (&dpcm->loopback->cable_lock);
@@ -974,6 +979,11 @@ static int rule_rate(struct snd_pcm_hw_params *params,struct snd_interval t;mutex_lock (&dpcm->loopback->cable_lock); +if (dpcm->substream->stream ==SNDRV_PCM_STREAM_PLAYBACK && +get_notify (dpcm)) { +mutex_unlock (&dpcm->loopback->cable_lock); +return 0 ; + } t.min = cable->hw.rate_min; t.max = cable->hw.rate_max;mutex_unlock (&dpcm->loopback->cable_lock);
@@ -990,6 +1000,11 @@ static int rule_channels(struct snd_pcm_hw_params *params,struct snd_interval t;mutex_lock (&dpcm->loopback->cable_lock); +if (dpcm->substream->stream ==SNDRV_PCM_STREAM_PLAYBACK && +get_notify (dpcm)) { +mutex_unlock (&dpcm->loopback->cable_lock); +return 0 ; + } t.min = cable->hw.channels_min; t.max = cable->hw.channels_max;mutex_unlock (&dpcm->loopback->cable_lock);
@@ -1006,6 +1021,11 @@ static int rule_period_bytes(struct snd_pcm_hw_params *params,struct snd_interval t;mutex_lock (&dpcm->loopback->cable_lock); +if (dpcm->substream->stream ==SNDRV_PCM_STREAM_PLAYBACK && +get_notify (dpcm)) { +mutex_unlock (&dpcm->loopback->cable_lock); +return 0 ; + } t.min = cable->hw.period_bytes_min; t.max = cable->hw.period_bytes_max;mutex_unlock (&dpcm->loopback->cable_lock);
Signature · 1 line
2.53.0