Received: by 2002:a25:8b12:0:0:0:0:0 with SMTP id i18csp1075644ybl; Wed, 14 Aug 2019 10:17:59 -0700 (PDT) X-Google-Smtp-Source: APXvYqyJP/OlitMZtgKuwoVt4nGPrN1yXyycXrkXK4nS/MmKiM5Th/sCGctryF5pPbLCAETz/QuS X-Received: by 2002:a17:90a:a489:: with SMTP id z9mr766679pjp.24.1565803079342; Wed, 14 Aug 2019 10:17:59 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1565803079; cv=none; d=google.com; s=arc-20160816; b=TU3XCa/nn3/NmElYLfYRFLLTJKy5qD/DgzO7h1rJvOkiNwM39aJ4679SN7Agq81iFG 84AZVlG/SC3xbx8eTy+8lMvwFm4efHbf9a057B3GBbDZTsoJSCMLOrlnaCjmg/CNMRBg OCEd9jQpC95+nKEJr0H1wC5PBUE07LJ+OMU/zulVkGdz8Kg99gd0uHXgQsxTNfwXEsm5 VB4eeNQHHQLjaO91vp+zhhSWz5Vlb42J6oitNq935dva4E7TnanZibJkh/mR2sTq4Spq N43vwJ+KaCbdvEkdKcdR9rmB9l4S03TegId/zoGde1/HOmpDdzRmHKP11wRzwD3bgKCq L0sw== 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=x5zoysayzQDWl8N07HV9YGBMBuzZsX0lFejGl0q8Jp0=; b=MJrnruZVVtCHIB6od4KNARK1cDgwdmgTD3GxcS9fhf6cGoPEKMTHdpXStwgCUz+3Z8 nurEOiZcqvwPvt5nzHpGMnoFYY7jtMJPmo/x80r/ztZKUPVhzE+zRXgSNuXrkC/QTZia VSoIFVu0oymSryW+gJ82K6NozBYFvBhUOKUawuRZ0ccGt3ich2uQ6AFD46D5WDtBwjxa /J++g3fcwy3N1EE9qHp3hs+stkkPpIAkdN5K4mwhQqFYKPp7+w/nhQcrfHeHmfjPxpsu O90U8VoAK+c84S9MMVVb2vsxw7rs3s0TFWATGmv7Mqng5M9X3iewk6Wz6vpYt5wwqLMy i6Xw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=jnPPFBp1; 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 r139si60320pfc.276.2019.08.14.10.17.43; Wed, 14 Aug 2019 10:17:59 -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=jnPPFBp1; 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 S1730932AbfHNRNk (ORCPT + 99 others); Wed, 14 Aug 2019 13:13:40 -0400 Received: from mail.kernel.org ([198.145.29.99]:37920 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1730888AbfHNRNi (ORCPT ); Wed, 14 Aug 2019 13:13:38 -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 A4B1620665; Wed, 14 Aug 2019 17:13:37 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1565802818; bh=z851h45O7JFYDbYorJHDPsmBa98oYdmzXl0lcIKxDjs=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=jnPPFBp1czrqjxw3FzO5CrrxAP0ei/ksEM4coT6kDLTUVrcVUe2uMWW2ihGIq5c0I 4skc+RRqoRUrhkQNM+JarHm9MkgowoWiVs6/2bjxyfjYIYdeUr67ALfZqLMHBXG2vq cqkwqXTcnw3RHeYH8MuVm3woUWNlx3789vql+UiM= 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.14 37/69] ALSA: compress: Prevent bypasses of set_params Date: Wed, 14 Aug 2019 19:01:35 +0200 Message-Id: <20190814165747.987235739@linuxfoundation.org> X-Mailer: git-send-email 2.22.0 In-Reply-To: <20190814165744.822314328@linuxfoundation.org> References: <20190814165744.822314328@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 cf1317546b0ff..1538fbc7562b8 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