FAILED: patch "[PATCH] ALSA: pcm: Prevent O_APPEND open on OSS streams" failed to apply to 6.6-stable tree
Subsystems (2)
Sasha Levin
maintainerThe patch below does not apply to the 6.6-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-6.6.y
git checkout FETCH_HEAD
git cherry-pick -x 9017bc3d13da0ea4e63be618c87143a7b69185e6
# <resolve conflicts, build, test, etc.>
git commit -s
git send-email --to '<[email protected]>' --in-reply-to '[email protected]' --subject-prefix 'PATCH 6.6.y' 'HEAD^..'
Thanks,
Sasha
------------------ original commit in Linus's tree ------------------
From 9017bc3d13da0ea4e63be618c87143a7b69185e6 Mon Sep 17 00:00:00 2001
From: Takashi Iwai <[email protected]>
Date: Tue, 3 Nov 2026 16:58:40 +0100
Subject: [PATCH] ALSA: pcm: Prevent O_APPEND open on OSS streams
ALSA PCM core accepts to re-use the existing stream when O_APPEND is passed, and it's been used for dmix, etc. However, this mode isn't supposed to be used for OSS: the OSS stream allows re-configuration via its hw_params/hw_refine procedure even while it's being mmapped, so it implies the usage of only a single stream. Because of this assumption, the sanity check is skipped for OSS streams, and if user may attach to an existing OSS stream with O_APPEND, it may result in a UAF of the mapped pages which could be used as a privilege escalation exploit.
For addressing it, this patch simply prohibits the O_APPEND behavior on the OSS stream. O_APPEND is never used for OSS layer itself, so this can't break for the right applications.
--- sound/core/pcm.c | 2 ++ sound/core/pcm_local.h | 6 ++++++ sound/core/pcm_native.c | 6 ------ 3 files changed, 8 insertions(+), 6 deletions(-)
sound/core/pcm.c +2 -0
@@ -929,6 +929,8 @@ int snd_pcm_attach_substream(struct snd_pcm *pcm, int stream,return -ENODEV ;if (!SUBSTREAM_BUSY (substream))return -EBADFD ; +if (is_oss_stream (substream)) +return -EINVAL ; substream->ref_count++; *rsubstream = substream;return 0 ;
sound/core/pcm_local.h +6 -0
@@ -80,4 +80,10 @@ static inline void snd_pcm_dma_buffer_sync(struct snd_pcm_substream *substream, snd_dma_buffer_sync(snd_pcm_get_dma_buf(substream), mode); } +#if IS_ENABLED (CONFIG_SND_PCM_OSS ) +#define is_oss_stream (substream) ((substream)->oss.oss) +#else +#define is_oss_stream (substream) false +#endif +#endif /* __SOUND_CORE_PCM_LOCAL_H */
sound/core/pcm_native.c +0 -6
@@ -749,12 +749,6 @@ int snd_pcm_runtime_buffer_set_silence(struct snd_pcm_runtime *runtime) }EXPORT_SYMBOL_GPL (snd_pcm_runtime_buffer_set_silence); -#if IS_ENABLED (CONFIG_SND_PCM_OSS ) -#define is_oss_stream (substream) ((substream)->oss.oss) -#else -#define is_oss_stream (substream) false -#endif -static void pcm_qos_req_clear (struct snd_pcm_substream *substream) {if (cpu_latency_qos_request_active (&substream->latency_pm_qos_req))
Signature · 1 line
2.53.0
Sasha Levin
maintainerPATCH 1/2 ALSA: pcm: Optimize cpu_latency_qos_*() calls
From: Takashi Iwai <[email protected]>
[ Upstream commit 9f6f4e97fd53908aecb0979507d9ff10a22288eb ]
We have a few cpu_latency_qos_*() calls in PCM callbacks, but they seem suboptimal in a few aspects:
- We call them at each time when the hw_params changed, but explicitly do remove and (re-)add; this could be cpu_latency_qos_update_request(), instead
- The setup of cpu_latency_qos_*() doesn't have to be in hw_params at all; it's not the place where the actual parameters are set up, but rather better at the prepare callback.
- The hw_free calls cpu_latency_qos_remove_request() unconditionally, which may be poking a WARNING when it wasn't queued.
For addressing the issues above, this patch cleans up and reorganize the cpu_latency_qos_*() calls in the PCM core by a couple helper functions. Now, they are set up at prepare callback, and cleared at hw_free and release callbacks via the new helpers.
Stable-dep-of: 9017bc3d13da ("ALSA: pcm: Prevent O_APPEND open on OSS streams")
--- sound/core/pcm_native.c | 35 +++++++++++++++++++++++++---------- 1 file changed, 25 insertions(+), 10 deletions(-)
sound/core/pcm_native.c +25 -10
@@ -726,11 +726,32 @@ EXPORT_SYMBOL_GPL(snd_pcm_runtime_buffer_set_silence);#define is_oss_stream (substream) false#endif +static void pcm_qos_req_clear (struct snd_pcm_substream *substream) +{ +if (cpu_latency_qos_request_active (&substream->latency_pm_qos_req)) +cpu_latency_qos_remove_request (&substream->latency_pm_qos_req); +} + +static void pcm_qos_req_update (struct snd_pcm_substream *substream,int usecs) +{ +if (usecs <0 ) { +pcm_qos_req_clear (substream); +return ; + } + +if (cpu_latency_qos_request_active (&substream->latency_pm_qos_req)) +cpu_latency_qos_update_request (&substream->latency_pm_qos_req, + usecs); +else +cpu_latency_qos_add_request (&substream->latency_pm_qos_req, + usecs); +} +static int snd_pcm_hw_params (struct snd_pcm_substream *substream,struct snd_pcm_hw_params *params) {struct snd_pcm_runtime *runtime; -int err, usecs; +int err;unsigned int bits;snd_pcm_uframes_t frames;
@@ -837,12 +858,6 @@ static int snd_pcm_hw_params(struct snd_pcm_substream *substream,snd_pcm_timer_resolution_change (substream);snd_pcm_set_state (substream,SNDRV_PCM_STATE_SETUP ); -if (cpu_latency_qos_request_active (&substream->latency_pm_qos_req)) -cpu_latency_qos_remove_request (&substream->latency_pm_qos_req); - usecs =period_to_usecs (runtime); -if (usecs >=0 ) -cpu_latency_qos_add_request (&substream->latency_pm_qos_req, - usecs); err =0 ; _error:if (err) {
@@ -921,7 +936,7 @@ static int snd_pcm_hw_free(struct snd_pcm_substream *substream) goto unlock; result =do_hw_free (substream);snd_pcm_set_state (substream,SNDRV_PCM_STATE_OPEN ); -cpu_latency_qos_remove_request (&substream->latency_pm_qos_req); +pcm_qos_req_clear (substream); unlock:snd_pcm_buffer_access_unlock (runtime);return result;
@@ -1976,6 +1991,7 @@ static int snd_pcm_do_prepare(struct snd_pcm_substream *substream, err = substream->ops->prepare (substream);if (err <0 )return err; +pcm_qos_req_update (substream,period_to_usecs (substream->runtime));return snd_pcm_do_reset (substream, state); }
@@ -2750,8 +2766,7 @@ void snd_pcm_release_substream(struct snd_pcm_substream *substream) substream->ops->close (substream); substream->hw_opened =0 ; } -if (cpu_latency_qos_request_active (&substream->latency_pm_qos_req)) -cpu_latency_qos_remove_request (&substream->latency_pm_qos_req); +pcm_qos_req_clear (substream);if (substream->pcm_release) { substream->pcm_release (substream); substream->pcm_release =NULL ;
Signature · 1 line
2.53.0
Sasha Levin
maintainerPATCH 2/2 ALSA: pcm: Prevent O_APPEND open on OSS streams
From: Takashi Iwai <[email protected]>
[ Upstream commit 9017bc3d13da0ea4e63be618c87143a7b69185e6 ]
ALSA PCM core accepts to re-use the existing stream when O_APPEND is passed, and it's been used for dmix, etc. However, this mode isn't supposed to be used for OSS: the OSS stream allows re-configuration via its hw_params/hw_refine procedure even while it's being mmapped, so it implies the usage of only a single stream. Because of this assumption, the sanity check is skipped for OSS streams, and if user may attach to an existing OSS stream with O_APPEND, it may result in a UAF of the mapped pages which could be used as a privilege escalation exploit.
For addressing it, this patch simply prohibits the O_APPEND behavior on the OSS stream. O_APPEND is never used for OSS layer itself, so this can't break for the right applications.
--- sound/core/pcm.c | 2 ++ sound/core/pcm_local.h | 6 ++++++ sound/core/pcm_native.c | 6 ------ 3 files changed, 8 insertions(+), 6 deletions(-)
sound/core/pcm.c +2 -0
@@ -933,6 +933,8 @@ int snd_pcm_attach_substream(struct snd_pcm *pcm, int stream,return -ENODEV ;if (!SUBSTREAM_BUSY (substream))return -EBADFD ; +if (is_oss_stream (substream)) +return -EINVAL ; substream->ref_count++; *rsubstream = substream;return 0 ;
sound/core/pcm_local.h +6 -0
@@ -80,4 +80,10 @@ static inline void snd_pcm_dma_buffer_sync(struct snd_pcm_substream *substream, snd_dma_buffer_sync(snd_pcm_get_dma_buf(substream), mode); } +#if IS_ENABLED (CONFIG_SND_PCM_OSS ) +#define is_oss_stream (substream) ((substream)->oss.oss) +#else +#define is_oss_stream (substream) false +#endif +#endif /* __SOUND_CORE_PCM_LOCAL_H */
sound/core/pcm_native.c +0 -6
@@ -720,12 +720,6 @@ int snd_pcm_runtime_buffer_set_silence(struct snd_pcm_runtime *runtime) }EXPORT_SYMBOL_GPL (snd_pcm_runtime_buffer_set_silence); -#if IS_ENABLED (CONFIG_SND_PCM_OSS ) -#define is_oss_stream (substream) ((substream)->oss.oss) -#else -#define is_oss_stream (substream) false -#endif -static void pcm_qos_req_clear (struct snd_pcm_substream *substream) {if (cpu_latency_qos_request_active (&substream->latency_pm_qos_req))
Signature · 1 line
2.53.0