Received: by 2002:a25:8b12:0:0:0:0:0 with SMTP id i18csp1080922ybl; Wed, 14 Aug 2019 10:23:07 -0700 (PDT) X-Google-Smtp-Source: APXvYqz1KN0rPsF4Shf+DmXPG3pq13+M5sUZcpfTuoVzW4nHPddF/NdZpF0IOSxdJCYKNAdUczc4 X-Received: by 2002:a17:902:f213:: with SMTP id gn19mr494344plb.152.1565803387526; Wed, 14 Aug 2019 10:23:07 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1565803387; cv=none; d=google.com; s=arc-20160816; b=r7noBPchTxeSQ4erGZA+iqmnMa1YZV+Koyo3KyneoBxtWs9tADDXEYU66QpEtMmr2m NL80GjnK8meUlRbnVB48TJQ8dIQHOCa4TqIIK2cvEWuSNdD4xPAoEW8WCJUJLeNGQZpC VSli1xmAIAuSVp96+3ImGW6ZUWqhadGFiH/YmvGdU2epILQUnkNyn2iZOI3Re/7zhvQJ uDlj0prD8YUp9MtNSkdwW1OnG2YJ/ADsc6YQEw6BwNrSRx2Hh3x8i280jUNRt+zm8Bbi /U2rInDrClx7qgwAtOVmZCPonDtrQH2OKfH3I7a68Prfz6K9VO8tlYvacbCnOg0cpo3F yx+A== 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=CQqUYU+2AgtVsg/MoNVlOb9ZKm6Wjw4Ywyu3mcai27w=; b=0fmeGd3s2TqAXMOm6ycyKbHpPzekjpoFzSL1/EnClnnyU4GkQvHKeQek98TeA2BlC2 uhke7rNMtLuCdr78/RSTOsVJ2pDYm8+V2g7ie8M/pHmh1Dn8BvkABAoj1BKakWtqNP6Q aY3F4ZucH287l7kUmVgObyU9V4zzHrbZv6StHD0TksNVDRFtysiY1/IrkyCBjqcgmslk PQcLdXTMwyM+rsBW5dg+4YRGjXzJVHLxaABs6wsqWFyJS11wc0bgHe0ETE5JsLImjZ+5 42TgUhe3gNumLQorYbrtB6ST+K5tP3BR7gWWmgF7DHRx2SuuupHNawMit7AQIYGnrf82 oosw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=VpPLmlvQ; 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 a19si195847pgv.180.2019.08.14.10.22.50; Wed, 14 Aug 2019 10:23:07 -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=VpPLmlvQ; 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 S1730464AbfHNRUw (ORCPT + 99 others); Wed, 14 Aug 2019 13:20:52 -0400 Received: from mail.kernel.org ([198.145.29.99]:33038 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1730465AbfHNRKV (ORCPT ); Wed, 14 Aug 2019 13:10:21 -0400 Received: from localhost (83-86-89-107.cable.dynamic.v4.ziggo.nl [83.86.89.107]) (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 80AF32133F; Wed, 14 Aug 2019 17:10:20 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1565802621; bh=794wgnbXaWkTJ0/bmNdN8SC03enKj458fY9bChFr2W4=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=VpPLmlvQqVeGSN6dviMvlj7Tf3xlYqy5pWhb3EgIfJ3Eqg0PfiH1e6m0aw3Kp7ddc ViYOqDREWi0JLeZRhIy348eBFPdOg8w9nIEeA2MXSFuEqnvB5yFB4DFOI3h7sR/MSi U7KiWFQZK3k5KAmYgulsBqX73z+oEqWdcT0M8TII= 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.19 53/91] ALSA: compress: Prevent bypasses of set_params Date: Wed, 14 Aug 2019 19:01:16 +0200 Message-Id: <20190814165751.843021519@linuxfoundation.org> X-Mailer: git-send-email 2.22.0 In-Reply-To: <20190814165748.991235624@linuxfoundation.org> References: <20190814165748.991235624@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 44e81cf302401..5e74f518bd598 100644 --- a/sound/core/compress_offload.c +++ b/sound/core/compress_offload.c @@ -712,9 +712,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); @@ -802,9 +808,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) { @@ -841,9 +852,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