Received: by 2002:a25:1985:0:0:0:0:0 with SMTP id 127csp3869979ybz; Mon, 4 May 2020 11:13:02 -0700 (PDT) X-Google-Smtp-Source: APiQypK9yFzg2b4wsyUNW0kSqFRMrSP9N+G3Wx/Ab939P4RD57Gt+BGsgI/ETmHmJbI+DAxPocuZ X-Received: by 2002:aa7:c453:: with SMTP id n19mr15716247edr.218.1588615981895; Mon, 04 May 2020 11:13:01 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1588615981; cv=none; d=google.com; s=arc-20160816; b=V/tvlU4uyTWHGI1A/U3FfRfq1B3OREJRyoWKObNXnDl7REgcHX8XuFYNsclsAc7nqU +g7ZStGaSN27I5v9TEnjCQbNIPpnFRVlNsEG0ybHQFdgRnxjPlzoqgzjWDBg++9nvhah yaYyUyEsj4d8SG1pnzpmklU8HDf3jEt372vbhYE36w4yKBHyvPn5ZKgOWbgSbeuAgRk3 zTcb5Ak8jDVw56B9Bn6ou+HA4vjmgjx4ggai8ZXEx9N/wkiAy948jslaJ/yjOPLnpgN1 34TDvvKu7YPaEUy14urIQ2IJaSMV1YiDB3E+E1ryWQ3Ps+71LlXytlwBjRhpmVjIUt9C T98g== 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=aYLLGwVMc/u9QrxXZ9hgxSPw/qnexMv+gqw37PXWj4s=; b=KNYnV8IOEREdYuE9hRtRlVawYxypYVGN9zZhF+Nmha/ofzzqybR4jqg9Z1P2tNcTqI mSB90ZVPCreiDu6bfpog420qch99xVQVnW6RNR3kTuX+2xmCh6b3MBxqkrldrqugczsh +Sst4SM7QmVUujYX+fbUHrvV6GXieT8I44WEdBtC8RVqgi0rqpRUdacUaNRDRSZQYw7A 1y5VKus/XWF25mtMogblHbAU0wyQthmg9p9LN01r+V1NKzk8+r/U4o9njrKXo/+O0Md4 1hZb4ZyQEut3PldURdnbPPBr0ekaWI7gHgDndRVhN2K7ddMZzu59SXAlQghdCtdruYHW 7lnw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=rwdukKat; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id g12si7394024ejw.314.2020.05.04.11.12.38; Mon, 04 May 2020 11:13:01 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=rwdukKat; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1731450AbgEDSKE (ORCPT + 99 others); Mon, 4 May 2020 14:10:04 -0400 Received: from mail.kernel.org ([198.145.29.99]:35972 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1731260AbgEDSFy (ORCPT ); Mon, 4 May 2020 14:05:54 -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 A632D206B8; Mon, 4 May 2020 18:05:52 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1588615553; bh=WOwYZ/09O3hRQvZRWnR5ibcSY9bduvtiBeCePotFWM8=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=rwdukKat7RM6lwY5d6fTwtS9/EOsg6YKoUsUrZd+filzc99qNBcO8QRgsbW7UNijp GVdr33uzy4iJb8D13vwUPUNceI+iHvisxG3iDsWo2tsCrvSOonBkeR/2uDb39jZlum hJ0Bo9cefdoqXJdDXiMO6QolUqYUcC8bEmUzl+QE= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Takashi Iwai Subject: [PATCH 5.6 27/73] ALSA: pcm: oss: Place the plugin buffer overflow checks correctly Date: Mon, 4 May 2020 19:57:30 +0200 Message-Id: <20200504165507.093805332@linuxfoundation.org> X-Mailer: git-send-email 2.26.2 In-Reply-To: <20200504165501.781878940@linuxfoundation.org> References: <20200504165501.781878940@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 From: Takashi Iwai commit 4285de0725b1bf73608abbcd35ad7fd3ddc0b61e upstream. The checks of the plugin buffer overflow in the previous fix by commit f2ecf903ef06 ("ALSA: pcm: oss: Avoid plugin buffer overflow") are put in the wrong places mistakenly, which leads to the expected (repeated) sound when the rate plugin is involved. Fix in the right places. Also, at those right places, the zero check is needed for the termination node, so added there as well, and let's get it done, finally. Fixes: f2ecf903ef06 ("ALSA: pcm: oss: Avoid plugin buffer overflow") Cc: Link: https://lore.kernel.org/r/20200424193350.19678-1-tiwai@suse.de Signed-off-by: Takashi Iwai Signed-off-by: Greg Kroah-Hartman --- sound/core/oss/pcm_plugin.c | 20 ++++++++++++-------- 1 file changed, 12 insertions(+), 8 deletions(-) --- a/sound/core/oss/pcm_plugin.c +++ b/sound/core/oss/pcm_plugin.c @@ -211,21 +211,23 @@ static snd_pcm_sframes_t plug_client_siz if (stream == SNDRV_PCM_STREAM_PLAYBACK) { plugin = snd_pcm_plug_last(plug); while (plugin && drv_frames > 0) { - if (check_size && drv_frames > plugin->buf_frames) - drv_frames = plugin->buf_frames; plugin_prev = plugin->prev; if (plugin->src_frames) drv_frames = plugin->src_frames(plugin, drv_frames); + if (check_size && plugin->buf_frames && + drv_frames > plugin->buf_frames) + drv_frames = plugin->buf_frames; plugin = plugin_prev; } } else if (stream == SNDRV_PCM_STREAM_CAPTURE) { plugin = snd_pcm_plug_first(plug); while (plugin && drv_frames > 0) { plugin_next = plugin->next; + if (check_size && plugin->buf_frames && + drv_frames > plugin->buf_frames) + drv_frames = plugin->buf_frames; if (plugin->dst_frames) drv_frames = plugin->dst_frames(plugin, drv_frames); - if (check_size && drv_frames > plugin->buf_frames) - drv_frames = plugin->buf_frames; plugin = plugin_next; } } else @@ -251,26 +253,28 @@ static snd_pcm_sframes_t plug_slave_size plugin = snd_pcm_plug_first(plug); while (plugin && frames > 0) { plugin_next = plugin->next; + if (check_size && plugin->buf_frames && + frames > plugin->buf_frames) + frames = plugin->buf_frames; if (plugin->dst_frames) { frames = plugin->dst_frames(plugin, frames); if (frames < 0) return frames; } - if (check_size && frames > plugin->buf_frames) - frames = plugin->buf_frames; plugin = plugin_next; } } else if (stream == SNDRV_PCM_STREAM_CAPTURE) { plugin = snd_pcm_plug_last(plug); while (plugin) { - if (check_size && frames > plugin->buf_frames) - frames = plugin->buf_frames; plugin_prev = plugin->prev; if (plugin->src_frames) { frames = plugin->src_frames(plugin, frames); if (frames < 0) return frames; } + if (check_size && plugin->buf_frames && + frames > plugin->buf_frames) + frames = plugin->buf_frames; plugin = plugin_prev; } } else