Received: by 2002:ac0:e34a:0:0:0:0:0 with SMTP id g10csp481610imn; Wed, 27 Jul 2022 11:25:04 -0700 (PDT) X-Google-Smtp-Source: AGRyM1upSMzLCY3RUo3A0YiZzZHTMjG6A/MrYTryKshV2aw+mWNCGcgh1ByySdCiJIOxdZNtD0TH X-Received: by 2002:a63:d456:0:b0:41a:aa82:cd9e with SMTP id i22-20020a63d456000000b0041aaa82cd9emr20365543pgj.271.1658946303673; Wed, 27 Jul 2022 11:25:03 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1658946303; cv=none; d=google.com; s=arc-20160816; b=clt5EUb2F+B3XaW6M0mwVYtJ4HCKra3vZW5gTMwtEol7JPzbMjpsLkiQTogyVrzjMw 7KWsxYtTafN73ueOgcXYxCCkgJLMsglQDNuN0CcfgWCLIwduokmEApML8Z889Oi10zE1 wBWytr26ysSuVSbKdNHqVucc7QrUHMI1bbhMAZdzFQ2OhbOCeDFZZ4W7/eCOvQu8ebii rmPIEOfL8EjgMH8bD0z4EphdVpLR6Y1an/Gs8vmJl3VfTQObundzUh242AR7onbQWDCz SvztTtwcIMjiwYnhcYPk/SP4xoOomcK0alFLCbHzBAnCIdplNtanVa6bSAp/grm1FXkK SbRA== 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=yfo9ji1RL1McdTrpmh41QybOZWnpq+RFZM24z0ew7No=; b=KHXb/3rxx1eLl8srPB8YxlDqPNuSNUQrvx3W2IT+0X2fEgp1CwvgZqLVS1qUbv9Yxj Cc1EgnnKe2kcn4oDh/7XXv8Tshlbtmejr4QUFULdUmd3LmCEk8VisYiu3l7lTI2Khnoi 4AtXvENw8dbfY290aDYo4SFE8ytiKV/DMvtyuArNHugcIzuYoch3eF2nA0nEwHJNMAK+ 1QiD2p+hy8R76iHtC5UVb18Z4H3ExE3Aw4LR+3G3cCSucwT/XztEValgg9MpwCdOBIXX x5cwr7226xK6VkrWuV0NLctG3Y9nz7rPhWFGTWq6KnR9Es8ZU9aY09S5hkAliMg6q8Y3 PpEA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=oqyhqkrh; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 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 out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id x185-20020a6331c2000000b00419c799df14si21149027pgx.178.2022.07.27.11.24.47; Wed, 27 Jul 2022 11:25:03 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=oqyhqkrh; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 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 S236502AbiG0QeF (ORCPT + 99 others); Wed, 27 Jul 2022 12:34:05 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:46914 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S237994AbiG0Qd1 (ORCPT ); Wed, 27 Jul 2022 12:33:27 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [IPv6:2604:1380:4641:c500::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 393FA4C63A; Wed, 27 Jul 2022 09:26:41 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id 6E9ED61A08; Wed, 27 Jul 2022 16:26:33 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 7957AC433D7; Wed, 27 Jul 2022 16:26:32 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1658939192; bh=IEo2m9o6KKrcSAAzgwAsEjTKgLNYFDTVee/FfJ2LAD4=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=oqyhqkrhUMvJNIDITcjUhLbfYVnMUMuqxyed8HlSeO0R+9alOdsijCvnZrJRzmmnv /uxbxVuSMUHZ0ZHdv+gI2eDXfP9oDnk27PFbKvQT65/KF4pHgfSeNbliFiht37/iGz ZQ28VPU8P7jbNkBxx8gqXeMJrefRUxk3M04uztow= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Lars-Peter Clausen , Takashi Iwai Subject: [PATCH 4.19 44/62] ALSA: memalloc: Align buffer allocations in page size Date: Wed, 27 Jul 2022 18:10:53 +0200 Message-Id: <20220727161005.890833787@linuxfoundation.org> X-Mailer: git-send-email 2.37.1 In-Reply-To: <20220727161004.175638564@linuxfoundation.org> References: <20220727161004.175638564@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-7.7 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_HI, SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Takashi Iwai commit 5c1733e33c888a3cb7f576564d8ad543d5ad4a9e upstream. Currently the standard memory allocator (snd_dma_malloc_pages*()) passes the byte size to allocate as is. Most of the backends allocates real pages, hence the actual allocations are aligned in page size. However, the genalloc doesn't seem assuring the size alignment, hence it may result in the access outside the buffer when the whole memory pages are exposed via mmap. For avoiding such inconsistencies, this patch makes the allocation size always to be aligned in page size. Note that, after this change, snd_dma_buffer.bytes field contains the aligned size, not the originally requested size. This value is also used for releasing the pages in return. Reviewed-by: Lars-Peter Clausen Link: https://lore.kernel.org/r/20201218145625.2045-2-tiwai@suse.de Signed-off-by: Takashi Iwai Signed-off-by: Greg Kroah-Hartman --- sound/core/memalloc.c | 1 + 1 file changed, 1 insertion(+) --- a/sound/core/memalloc.c +++ b/sound/core/memalloc.c @@ -179,6 +179,7 @@ int snd_dma_alloc_pages(int type, struct if (WARN_ON(!dmab)) return -ENXIO; + size = PAGE_ALIGN(size); dmab->dev.type = type; dmab->dev.dev = device; dmab->bytes = 0;