snd_compr_set_metadata() calls stream->ops->set_metadata() straight after copy_from_user(), without ever checking runtime->state, even though the function's own comment says a parameter change should only be allowed once the stream has left the OPEN state. Every other metadata/param entry point in this file (SET_PARAMS, WRITE, ...) enforces that gate. A codec driver's set_metadata callback can assume SET_PARAMS has already run and initialised its private state; calling it while the stream is still OPEN can operate on that uninitialised state. Add the OPEN-state check the existing comment already documents. Fixes: 9727b490e543 ("ALSA: compress: add support for gapless playback") Cc: stable@vger.kernel.org Signed-off-by: Peter Ujfalusi Acked-by: Vinod Koul --- sound/core/compress_offload.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/sound/core/compress_offload.c b/sound/core/compress_offload.c index d6863336f21c..a250c6b53996 100644 --- a/sound/core/compress_offload.c +++ b/sound/core/compress_offload.c @@ -789,6 +789,9 @@ snd_compr_set_metadata(struct snd_compr_stream *stream, unsigned long arg) * we should allow parameter change only when stream has been * opened not in other cases */ + if (stream->runtime->state == SNDRV_PCM_STATE_OPEN) + return -EBADFD; + if (copy_from_user(&metadata, (void __user *)arg, sizeof(metadata))) return -EFAULT; -- 2.56.0