Received: by 2002:a05:6a10:f347:0:0:0:0 with SMTP id d7csp13926634pxu; Mon, 4 Jan 2021 08:09:19 -0800 (PST) X-Google-Smtp-Source: ABdhPJyK84rDwweCmh/RsT4J+B+C791eKLXtGTuf7I+gV8Q94L4FmElYu6DO+DKrv0DsifssuPWx X-Received: by 2002:a17:906:5182:: with SMTP id y2mr68612233ejk.92.1609776559214; Mon, 04 Jan 2021 08:09:19 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1609776559; cv=none; d=google.com; s=arc-20160816; b=Dw1PGZqxUtTPgj9Q1LtYdhaANlgr3w05u426yXId7UBQav1cgyDj/WLpyosPGQaNJO uSDVrsETyJZoAHY52HPFs0ZC7bguXLj+BupMzvvZex7/rAUvWMSoyhakWkO5Ji14+BWF V+dQGb3e+eYOz8eq6Hj9t4fFdTuxtML343nhuUk2wMoXP+52a6ZnTIOSFR1WjE4rZ3eM FK1LrbtzeePfXP9447pEKVrLRpa0Mjn2iS4j4j6gZCPv9bh26FVlaXxAya3BPHNX3BP3 k49gFGb8y+WWdqRwP5P756KPKIfGZ9DO5B+Nk1+xKHablPGWrELGzXjIeK+LM7dgjPQH VaHw== 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=erJJh/4NHcD38DbCrNVn26DZge1xU/zmMPHr0OLH5vU=; b=snPG14sG8oKPsSPyhwYksAgh+Mmd0RBE/T1Mu7+IHDn7daR6CyHXmnCNOjuejWrwi/ AqU26a1cImIavFwAOuUp+2NFvjNkLd+BOl5nKd5EOcrKNVhSvb72MeCQ6SJhy/dt2mv+ symQaKEp+t/ORDjN//9TBXCb1lYx/BwrPdP6mQTJW3hZnaSM2oydI98JV+/xUox+cSUd QXzcw67q3uhGhtGM9+DJk6/lyQfA0i8IiJZieHmCOkaJSc15Fben8akYVdYIP36kungQ uIiRoU0qFLPNN92pXLVnHM2fpjSOxW/BsrXv7Iwd6pzvjC1i/wwVUQ6lInSm7L6BP+tz uJjw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=Mt8ebnkb; 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 dm7si29370328ejc.350.2021.01.04.08.08.55; Mon, 04 Jan 2021 08:09:19 -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=Mt8ebnkb; 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 S1729114AbhADQFl (ORCPT + 99 others); Mon, 4 Jan 2021 11:05:41 -0500 Received: from mail.kernel.org ([198.145.29.99]:40456 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729101AbhADQDW (ORCPT ); Mon, 4 Jan 2021 11:03:22 -0500 Received: by mail.kernel.org (Postfix) with ESMTPSA id 527792253D; Mon, 4 Jan 2021 16:03:06 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1609776186; bh=zGv/m5AikMZ667F9yl+zvQX9024+DMSLSU/2yaYPhcc=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=Mt8ebnkbUz2wTWJz43FsheVzHCSoj4SdT3wSnbu9HtRoJFNdPxfAhzG0L0mAB5jk/ IKFXchEccwxJr4erURCHQBQJLDUU1vInwoGfQFszVqXi6eUFFy6JyBmOt5nROV/Loc /8SoCeFKGSkNi8i3exGD15hTDmakY0bDxF3iJXr0= 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 5.10 60/63] ALSA: pcm: Clear the full allocated memory at hw_params Date: Mon, 4 Jan 2021 16:57:53 +0100 Message-Id: <20210104155711.713575360@linuxfoundation.org> X-Mailer: git-send-email 2.30.0 In-Reply-To: <20210104155708.800470590@linuxfoundation.org> References: <20210104155708.800470590@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 47b155a49226f..9f3f8e953ff04 100644 --- a/sound/core/pcm_native.c +++ b/sound/core/pcm_native.c @@ -755,8 +755,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