From: Takashi Iwai Subject: Re: [PATCH v2 2/4] ALSA: compress: Prevent bypasses of set_params Date: Tue, 23 Jul 2019 12:08:41 +0200 Message-ID: References: <20190722092436.651-1-ckeepax@opensource.cirrus.com> <20190722092436.651-2-ckeepax@opensource.cirrus.com> Mime-Version: 1.0 (generated by SEMI 1.14.6 - "Maruoka") Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Return-path: Received: from mx1.suse.de (mx2.suse.de [195.135.220.15]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by alsa1.perex.cz (Postfix) with ESMTPS id 06DA2F8044A for ; Tue, 23 Jul 2019 12:08:42 +0200 (CEST) In-Reply-To: <20190722092436.651-2-ckeepax@opensource.cirrus.com> List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: alsa-devel-bounces@alsa-project.org Sender: "Alsa-devel" To: Charles Keepax Cc: patches@opensource.cirrus.com, vkoul@kernel.org, alsa-devel@alsa-project.org List-Id: alsa-devel@alsa-project.org On Mon, 22 Jul 2019 11:24:34 +0200, Charles Keepax wrote: > > 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 Applied, thanks. Takashi > --- > > No changes since v1. > > Thanks, > Charles > > sound/core/compress_offload.c | 30 ++++++++++++++++++++++++------ > 1 file changed, 24 insertions(+), 6 deletions(-) > > diff --git a/sound/core/compress_offload.c b/sound/core/compress_offload.c > index d79aee6b9edd2..40dae723c59db 100644 > --- a/sound/core/compress_offload.c > +++ b/sound/core/compress_offload.c > @@ -711,9 +711,15 @@ static int snd_compr_stop(struct snd_compr_stream *stream) > { > int retval; > > - if (stream->runtime->state == SNDRV_PCM_STATE_PREPARED || > - stream->runtime->state == SNDRV_PCM_STATE_SETUP) > + switch (stream->runtime->state) { > + case SNDRV_PCM_STATE_OPEN: > + case SNDRV_PCM_STATE_SETUP: > + case SNDRV_PCM_STATE_PREPARED: > return -EPERM; > + default: > + break; > + } > + > retval = stream->ops->trigger(stream, SNDRV_PCM_TRIGGER_STOP); > if (!retval) { > snd_compr_drain_notify(stream); > @@ -801,9 +807,14 @@ static int snd_compr_drain(struct snd_compr_stream *stream) > { > int retval; > > - if (stream->runtime->state == SNDRV_PCM_STATE_PREPARED || > - stream->runtime->state == SNDRV_PCM_STATE_SETUP) > + switch (stream->runtime->state) { > + case SNDRV_PCM_STATE_OPEN: > + case SNDRV_PCM_STATE_SETUP: > + case SNDRV_PCM_STATE_PREPARED: > return -EPERM; > + default: > + break; > + } > > retval = stream->ops->trigger(stream, SND_COMPR_TRIGGER_DRAIN); > if (retval) { > @@ -840,9 +851,16 @@ static int snd_compr_next_track(struct snd_compr_stream *stream) > static int snd_compr_partial_drain(struct snd_compr_stream *stream) > { > int retval; > - if (stream->runtime->state == SNDRV_PCM_STATE_PREPARED || > - stream->runtime->state == SNDRV_PCM_STATE_SETUP) > + > + switch (stream->runtime->state) { > + case SNDRV_PCM_STATE_OPEN: > + case SNDRV_PCM_STATE_SETUP: > + case SNDRV_PCM_STATE_PREPARED: > return -EPERM; > + default: > + break; > + } > + > /* stream can be drained only when next track has been signalled */ > if (stream->next_track == false) > return -EPERM; > -- > 2.11.0 > >