Received: by 2002:a05:6a10:f347:0:0:0:0 with SMTP id d7csp348897pxu; Thu, 7 Jan 2021 06:40:22 -0800 (PST) X-Google-Smtp-Source: ABdhPJwL9dCj9H29ZW/rPJygYRB1RekahNV5D/XRbEeQQTfkzYX+hJ6gVCswxD9yV/NV/6LC7lFA X-Received: by 2002:a50:fe0e:: with SMTP id f14mr1951728edt.159.1610030422027; Thu, 07 Jan 2021 06:40:22 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1610030422; cv=none; d=google.com; s=arc-20160816; b=w75mhXkes2aYIVf2z2yG+/J36EBcYGc7sq6qif8IKgDL+0VLTo0G+9QAb9I8EDgq7c 00FFBwZedkye3yRIp1wz0YVf2jxSy9K76qptYeImf2bAfyquuY+GBISxMx/9DAs6xCad ZZcmL3FnX5eZ7aO8jhDSQOohVAr8hL1l++0ju4xKDpeqNDLEx+BXNy7lHIrIdsqLCg4h MtQjlhwRLcS5tY6Fujsxso2p4vtlmQdimSYpctVHrhwPPoUMuaRDEIwoEEmtRWu+j0Cg DTtVhYUjAmySXOhq4DYpyt0cX8xaUkdlOcUTANOO83svhT5/E6c93koKOzqAmBZOj5s/ y1kw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=/F94y9t/QQ6jIvWRXhq88K8oKlv76k2aXUHfgmFoKok=; b=DsOVfR6pehIPQk5AZYclHbBXmL/JEZZTfCuMN6C9wakLSUOZda5RHa+q4LMJg6Hzr4 SzEHxQEwZ38gpg3nFfz8n7wCUiGwXcnhHG9qippcajzmIvME+jvu2nXLbkYbYqpeNEBX y2IssdgqVYUX4ZmzBXbKjoq4BLYg6dbff2ZaAO9S+WTZ9EvqcadJ1lnUK9vGnU5m/8jn /TY6ZPQNkiPGAOeuznPCFjGcCKhyyicAePtXloKwY0ZNrSyRusB3yKXtypt3f2Ba1Fq9 iOEVH7xRjHBvv+IBOWMxfwYMH7hRtNeGpMoFQPxszCNJumgMyeWInsFcyQ+tstHc/Yn+ t8Tw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b="n7N/O91M"; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id o60si2288704eda.61.2021.01.07.06.39.58; Thu, 07 Jan 2021 06:40:22 -0800 (PST) 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=@linuxfoundation.org header.s=korg header.b="n7N/O91M"; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728919AbhAGOiN (ORCPT + 99 others); Thu, 7 Jan 2021 09:38:13 -0500 Received: from mail.kernel.org ([198.145.29.99]:45564 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729039AbhAGObw (ORCPT ); Thu, 7 Jan 2021 09:31:52 -0500 Received: by mail.kernel.org (Postfix) with ESMTPSA id 222792311E; Thu, 7 Jan 2021 14:31:06 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1610029867; bh=gBkpl3m4jJGJDQ83gMnX/l9iczs2j62lLFhEFweDDFg=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=n7N/O91Mno5YZ1tgMhYBcnix6I8/h7eaj6I73EpE8+/zuPCpHvIScJ4RWpy3gTu4U PJnmLCSas+yGuy3GEL38Id3vuSE9ZI59QQD1x0Urrz2wgDzLUuH8GLZRmefRB9kHPx DcciREp4KWpNCrGQXPGCkOXTLAQJraHkvJXRwX7o= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Lars-Peter Clausen , Takashi Iwai , Sasha Levin Subject: [PATCH 4.14 24/29] ALSA: pcm: Clear the full allocated memory at hw_params Date: Thu, 7 Jan 2021 15:31:39 +0100 Message-Id: <20210107143056.389471030@linuxfoundation.org> X-Mailer: git-send-email 2.30.0 In-Reply-To: <20210107143052.973437064@linuxfoundation.org> References: <20210107143052.973437064@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 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