diff options
| author | Takashi Iwai <tiwai@suse.de> | 2026-11-03 16:58:40 +0100 |
|---|---|---|
| committer | Takashi Iwai <tiwai@suse.de> | 2026-11-05 08:54:46 +0100 |
| commit | 9017bc3d13da0ea4e63be618c87143a7b69185e6 (patch) | |
| tree | 0f88b78e9f824c9e8269c5e3142bf3738b1f7f2a | |
| parent | f65c917397c77daeb7e6d0893ebe89107ddd5692 (diff) | |
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.
Fixes: 0df63e44c3e3 ("[ALSA] Add O_APPEND flag support to PCM")
Cc: stable@vger.kernel.org
Reported-by: Bo Cao <treebacker@foxmail.com>
Link: https://lore.kernel.org/tencent_E90BB4F086165FAA3313723567A5C675EA06@qq.com
Link: https://patch.msgid.link/20261103155844.120838-1-tiwai@suse.de
Signed-off-by: Takashi Iwai <tiwai@suse.de>
| -rw-r--r-- | sound/core/pcm.c | 2 | ||||
| -rw-r--r-- | sound/core/pcm_local.h | 6 | ||||
| -rw-r--r-- | sound/core/pcm_native.c | 6 |
3 files changed, 8 insertions, 6 deletions
diff --git a/sound/core/pcm.c b/sound/core/pcm.c index 064df4cd3b50..6c8274414c22 100644 --- a/sound/core/pcm.c +++ b/sound/core/pcm.c @@ -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; diff --git a/sound/core/pcm_local.h b/sound/core/pcm_local.h index ecb21697ae3a..4b134d435c24 100644 --- a/sound/core/pcm_local.h +++ b/sound/core/pcm_local.h @@ -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 */ diff --git a/sound/core/pcm_native.c b/sound/core/pcm_native.c index 35152fae74ca..bec797398acf 100644 --- a/sound/core/pcm_native.c +++ b/sound/core/pcm_native.c @@ -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)) |
