Skip to content

Commit 26c3f15

Browse files
charleskeepaxtiwai
authored andcommitted
ALSA: compress: Prevent bypasses of set_params
Currently, whilst in SNDRV_PCM_STATE_OPEN it is possible to call snd_compr_stop, snd_compr_drain and snd_compr_partial_drain, which allow a transition to SNDRV_PCM_STATE_SETUP. The stream should only be able to move to the setup state once it has received a SNDRV_COMPRESS_SET_PARAMS ioctl. Fix this issue by not allowing those ioctls whilst in the open state. Signed-off-by: Charles Keepax <[email protected]> Acked-by: Vinod Koul <[email protected]> Signed-off-by: Takashi Iwai <[email protected]>
1 parent 4475f8c commit 26c3f15

File tree

1 file changed

+24
-6
lines changed

1 file changed

+24
-6
lines changed

sound/core/compress_offload.c

Lines changed: 24 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -711,9 +711,15 @@ static int snd_compr_stop(struct snd_compr_stream *stream)
711711
{
712712
int retval;
713713

714-
if (stream->runtime->state == SNDRV_PCM_STATE_PREPARED ||
715-
stream->runtime->state == SNDRV_PCM_STATE_SETUP)
714+
switch (stream->runtime->state) {
715+
case SNDRV_PCM_STATE_OPEN:
716+
case SNDRV_PCM_STATE_SETUP:
717+
case SNDRV_PCM_STATE_PREPARED:
716718
return -EPERM;
719+
default:
720+
break;
721+
}
722+
717723
retval = stream->ops->trigger(stream, SNDRV_PCM_TRIGGER_STOP);
718724
if (!retval) {
719725
snd_compr_drain_notify(stream);
@@ -801,9 +807,14 @@ static int snd_compr_drain(struct snd_compr_stream *stream)
801807
{
802808
int retval;
803809

804-
if (stream->runtime->state == SNDRV_PCM_STATE_PREPARED ||
805-
stream->runtime->state == SNDRV_PCM_STATE_SETUP)
810+
switch (stream->runtime->state) {
811+
case SNDRV_PCM_STATE_OPEN:
812+
case SNDRV_PCM_STATE_SETUP:
813+
case SNDRV_PCM_STATE_PREPARED:
806814
return -EPERM;
815+
default:
816+
break;
817+
}
807818

808819
retval = stream->ops->trigger(stream, SND_COMPR_TRIGGER_DRAIN);
809820
if (retval) {
@@ -840,9 +851,16 @@ static int snd_compr_next_track(struct snd_compr_stream *stream)
840851
static int snd_compr_partial_drain(struct snd_compr_stream *stream)
841852
{
842853
int retval;
843-
if (stream->runtime->state == SNDRV_PCM_STATE_PREPARED ||
844-
stream->runtime->state == SNDRV_PCM_STATE_SETUP)
854+
855+
switch (stream->runtime->state) {
856+
case SNDRV_PCM_STATE_OPEN:
857+
case SNDRV_PCM_STATE_SETUP:
858+
case SNDRV_PCM_STATE_PREPARED:
845859
return -EPERM;
860+
default:
861+
break;
862+
}
863+
846864
/* stream can be drained only when next track has been signalled */
847865
if (stream->next_track == false)
848866
return -EPERM;

0 commit comments

Comments
 (0)