From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-19.0 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,USER_AGENT_GIT autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 55AB5C433E9 for ; Wed, 30 Dec 2020 13:05:59 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 1CFFE22227 for ; Wed, 30 Dec 2020 13:05:59 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727605AbgL3NFo (ORCPT ); Wed, 30 Dec 2020 08:05:44 -0500 Received: from mail.kernel.org ([198.145.29.99]:54520 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726711AbgL3NFl (ORCPT ); Wed, 30 Dec 2020 08:05:41 -0500 Received: by mail.kernel.org (Postfix) with ESMTPSA id AE213222F9; Wed, 30 Dec 2020 13:04:44 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1609333485; bh=gBkpl3m4jJGJDQ83gMnX/l9iczs2j62lLFhEFweDDFg=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=CiMmd9YvaCncWtzs5yVkd02O/RgeePIlyf1obe2cBgD6rIvMLzjPS9hVCxgxPn4x6 B+SojeyRhgDo5nsJ+S060CProw7H2pwZLSdiuqc/AujHiwH5RwHZ622MgKOKVY1pOe OAmDrnuepPCCZUcJxXkcGJuA1hLEPwd8ZnQIdNX0+l0AYwyt+lwXFrOUbnDPM8wHJh 9pz4CH/0reYiOD5ZRzVeap+kDwikf4+1lW57RUW0kVo8XsZwx4Ykqg0I+OWwX7FklC jqBr7Ded0NuoZjJ7hqQpaRsM3U0z7D19W7SUrGcSHq+XMDxA5eREKt3381ACrLRTwq pJ/DBn37rpbLw== From: Sasha Levin To: linux-kernel@vger.kernel.org, stable@vger.kernel.org Cc: Takashi Iwai , Lars-Peter Clausen , Sasha Levin , alsa-devel@alsa-project.org Subject: [PATCH AUTOSEL 4.14 7/8] ALSA: pcm: Clear the full allocated memory at hw_params Date: Wed, 30 Dec 2020 08:04:35 -0500 Message-Id: <20201230130436.3637579-7-sashal@kernel.org> X-Mailer: git-send-email 2.27.0 In-Reply-To: <20201230130436.3637579-1-sashal@kernel.org> References: <20201230130436.3637579-1-sashal@kernel.org> MIME-Version: 1.0 X-stable: review X-Patchwork-Hint: Ignore Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Takashi Iwai [ Upstream commit 618de0f4ef11acd8cf26902e65493d46cc20cc89 ] The PCM hw_params core function tries to clear up the PCM buffer before actually using for avoiding the information leak from the previous usages or the usage before a new allocation. It performs the memset() with runtime->dma_bytes, but this might still leave some remaining bytes untouched; namely, the PCM buffer size is aligned in page size for mmap, hence runtime->dma_bytes doesn't necessarily cover all PCM buffer pages, and the remaining bytes are exposed via mmap. This patch changes the memory clearance to cover the all buffer pages if the stream is supposed to be mmap-ready (that guarantees that the buffer size is aligned in page size). Reviewed-by: Lars-Peter Clausen Link: https://lore.kernel.org/r/20201218145625.2045-3-tiwai@suse.de Signed-off-by: Takashi Iwai Signed-off-by: Sasha Levin --- sound/core/pcm_native.c | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/sound/core/pcm_native.c b/sound/core/pcm_native.c index 071e09c3d8557..c78db361cbbaa 100644 --- a/sound/core/pcm_native.c +++ b/sound/core/pcm_native.c @@ -721,8 +721,13 @@ static int snd_pcm_hw_params(struct snd_pcm_substream *substream, runtime->boundary *= 2; /* clear the buffer for avoiding possible kernel info leaks */ - if (runtime->dma_area && !substream->ops->copy_user) - memset(runtime->dma_area, 0, runtime->dma_bytes); + if (runtime->dma_area && !substream->ops->copy_user) { + size_t size = runtime->dma_bytes; + + if (runtime->info & SNDRV_PCM_INFO_MMAP) + size = PAGE_ALIGN(size); + memset(runtime->dma_area, 0, size); + } snd_pcm_timer_resolution_change(substream); snd_pcm_set_state(substream, SNDRV_PCM_STATE_SETUP); -- 2.27.0