Received: by 2002:a25:8b12:0:0:0:0:0 with SMTP id i18csp545601ybl; Fri, 23 Aug 2019 04:59:20 -0700 (PDT) X-Google-Smtp-Source: APXvYqwq7Jf0E68g1MCP3Qcz/br6OTrqd2hIZuVYn1LRzaCCsZ+alYObu1ocGGFNWhbXye4E1bck X-Received: by 2002:a17:902:6842:: with SMTP id f2mr4482965pln.39.1566561560834; Fri, 23 Aug 2019 04:59:20 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1566561560; cv=none; d=google.com; s=arc-20160816; b=y9vgaGmoScfCo1cysyy7rp3z0yQE2nyi1X3CeTi9iIyf79qjpG09jRbW7+s0jpct/P nfHFXnbD6/SRSDjgZD9mddwxtA7rtvjBOUgV5SvZFu1WlV2OU3RqjutaJ2C9gihqOjQo 03SPNn+wGf+fenll2tSTT3wSgPL7mCNZQ5nnkRR9xCMO0hclWg3n8tFhVb29XADp0x8n aOrPv13bpA7jqHnn6YRWBNbh/AfWn+jQxojpNybw/dH/EMmZf0x2P9j0AYZIMqMG4yRe diVLHaPnZP6WvE/cDS07r+ZM9Qq7Cvx/Ci4cSH5LC6szd+AOP72lI4kntVFyQQFV8c6v oT4g== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=gNF2Miu48INvrkAEbVfs4Nw++PYZlckKMHmC1vx4iSQ=; b=xetljRGS3+xWcyosG3QxumQFEqhgGHFoBcALCSylv4BVCcnUmXeF1R5zEcEqIbq+hx gR9/f4GRXeL82eA3K8u+Lbl8+2fm7Zmt8rVdZnWLgH658zlALJVZj+LlMJS1CTaU6YHx vTars0UHenL0ZJrjrzzhHVkiTxfTIxtNJGirjmZekYTG3WtP0fp4YkSlq5ZQHRn1jC2t czjxIb7HwQtFzZs1xaRDTes8wutj7oHKr7UO4TecsMjwAGXQbhkd8HfMw8/GPieJh4G0 zUMpflwRe7HtUrj774EJUNHVuO5s2E9O9Era8jbkwXc2tax1M6eh0YPf1TDlv65SmFrq 86UQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=iQwVQ86I; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id b18si2239902pls.125.2019.08.23.04.59.01; Fri, 23 Aug 2019 04:59:20 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=iQwVQ86I; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2403942AbfHVRtM (ORCPT + 99 others); Thu, 22 Aug 2019 13:49:12 -0400 Received: from mail.kernel.org ([198.145.29.99]:40142 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2389818AbfHVRWR (ORCPT ); Thu, 22 Aug 2019 13:22:17 -0400 Received: from localhost (wsip-184-188-36-2.sd.sd.cox.net [184.188.36.2]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id F0EE523400; Thu, 22 Aug 2019 17:22:16 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1566494537; bh=c2aGwSnqIaoyFvTTMzz/8AWODC8ihLJ526QwK1gtMRQ=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=iQwVQ86IW0JfQBKuajV0Tm5ZOn0atZ359lBDIPYZW9MhROrTOKSJhxKpgzMSgixPh M+4QKLB0AZHwdwXT3eQOa7hTX+rfaOrAIjNytIDhA4r2ddyJQIQS9wdIZINRkIVUKI 8glCi7GnCxGZG2NB7JANhbhNf3DdRdGgoC42GFCI= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Charles Keepax , Vinod Koul , Takashi Iwai , Sasha Levin Subject: [PATCH 4.4 16/78] ALSA: compress: Prevent bypasses of set_params Date: Thu, 22 Aug 2019 10:18:20 -0700 Message-Id: <20190822171832.514498053@linuxfoundation.org> X-Mailer: git-send-email 2.23.0 In-Reply-To: <20190822171832.012773482@linuxfoundation.org> References: <20190822171832.012773482@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org [ Upstream commit 26c3f1542f5064310ad26794c09321780d00c57d ] 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 Acked-by: Vinod Koul Signed-off-by: Takashi Iwai Signed-off-by: Sasha Levin --- 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 16269e7ff3904..d0a21a5867673 100644 --- a/sound/core/compress_offload.c +++ b/sound/core/compress_offload.c @@ -688,9 +688,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); @@ -739,9 +745,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) { @@ -778,9 +789,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.20.1