Received: by 2002:ac0:e34a:0:0:0:0:0 with SMTP id g10csp55691imn; Tue, 26 Jul 2022 22:27:21 -0700 (PDT) X-Google-Smtp-Source: AGRyM1uZfq9OWz1bdnhxJv26PBAugV4iDsv0JgWaIVR9v4Uiiamx1C2ZNJX8+KmO4bXAncjAvLF6 X-Received: by 2002:a05:6a02:11b:b0:40d:dfdc:95d7 with SMTP id bg27-20020a056a02011b00b0040ddfdc95d7mr17756157pgb.536.1658899641235; Tue, 26 Jul 2022 22:27:21 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1658899641; cv=none; d=google.com; s=arc-20160816; b=k5y89c0wvUFiCyTOtbF7Tx/66aYFrpQLUOvk5g82CCzYYTdAZ+aix7huTRDafTvCUc 6lQM9M7nDylk+TLlFfKryXfmo63or77IC2+TL5L3JdvRuBlSRLscVn/tRr/nc7kP469f byzq+gejXtbVQKUUzKb+ffO3MmUEUH9IRAKwdetl3yoZ8iQMJautwrE85sbB++nJICjV oZGe1P/cAPFzdGpXDbFfDzEksCLfD46OG054fydCWHkp3ikAD+ydyC1oaOrhFu2R9muR lpZclyppSxu6lPOAH2tQB/gBm8MxfXp2KXU6yUDF5dEOB9bjDbfETTEE00JHnHMkO5FH 7Lfw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:mime-version:user-agent:references:in-reply-to :subject:cc:to:from:message-id:date:dkim-signature:dkim-signature; bh=bdqmQ5p2ejZx38NuBZXzRSiBR0XeVRrw8M3dUjIZMMw=; b=bDqYSmfBZ7YVy0zHQRFiWtx/ZEs2PmkF9GHo24OYArzxjHaxuMfN3C88MmkpHo94NL NfzwRBElTJStwxT81hRmvRuoYnvQdi2OJTPwV/sZ4X32ErQ11g2NpAiKUb6DqwScuFaV Rp85oKhd+TC5HwAKSpxHLxbgWTIaIarg6jm3ESE6fw3bDO1k0DOx7xi0ZcTXWrVbjEWW fw2yr9uSiV9Vr44D17Vp2aVCYjM59I2KlUi+NrESk63nZD1ISJfMnJBNf6RRTH0AdLUu maZ/lreUo41CUoe7u1NBovv5YptF1vllDOZ/16YiIZlMpcsWgEtkE+9wOieRmu7OfoXZ WNbQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@suse.de header.s=susede2_rsa header.b=UvMxtc8L; dkim=neutral (no key) header.i=@suse.de header.s=susede2_ed25519; 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=suse.de Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id k18-20020a056a00135200b0052589c13629si20942473pfu.249.2022.07.26.22.27.04; Tue, 26 Jul 2022 22:27:21 -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=@suse.de header.s=susede2_rsa header.b=UvMxtc8L; dkim=neutral (no key) header.i=@suse.de header.s=susede2_ed25519; 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=suse.de Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231497AbiG0FZj (ORCPT + 99 others); Wed, 27 Jul 2022 01:25:39 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:36592 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229507AbiG0FZi (ORCPT ); Wed, 27 Jul 2022 01:25:38 -0400 Received: from smtp-out2.suse.de (smtp-out2.suse.de [195.135.220.29]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id D981B3DBC3 for ; Tue, 26 Jul 2022 22:25:35 -0700 (PDT) Received: from imap2.suse-dmz.suse.de (imap2.suse-dmz.suse.de [192.168.254.74]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-521) server-digest SHA512) (No client certificate requested) by smtp-out2.suse.de (Postfix) with ESMTPS id 1FA0820156; Wed, 27 Jul 2022 05:25:34 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_rsa; t=1658899534; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to:references:references; bh=bdqmQ5p2ejZx38NuBZXzRSiBR0XeVRrw8M3dUjIZMMw=; b=UvMxtc8LNEj6R91u/dPgYCdwo81tvHkxZHFcc5ChPMt6KGXFEh5ZazTsiTYgGUUKdht70S ZBNK/V/prwer8fk6Ef/L4arzxq/Ejb6ovKOUj1HeVWAiwaHJSxXcQJ3L6UXVvE7CjDUuXU RpocNP/tRbeaUhXCsyS54EiRHL5+37Q= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_ed25519; t=1658899534; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to:references:references; bh=bdqmQ5p2ejZx38NuBZXzRSiBR0XeVRrw8M3dUjIZMMw=; b=yu0yTJPq1NYJt+Rw/fdkL6xr9Uq6K6UfnKT1yAWtwPbiJDzGYALauCC7nIMWm1vfVPDOmg /+0lxs6uQVVERHBA== Received: from imap2.suse-dmz.suse.de (imap2.suse-dmz.suse.de [192.168.254.74]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-521) server-digest SHA512) (No client certificate requested) by imap2.suse-dmz.suse.de (Postfix) with ESMTPS id D9A8213A7C; Wed, 27 Jul 2022 05:25:33 +0000 (UTC) Received: from dovecot-director2.suse.de ([192.168.254.65]) by imap2.suse-dmz.suse.de with ESMTPSA id bFNyNE3M4GJjZQAAMHmgww (envelope-from ); Wed, 27 Jul 2022 05:25:33 +0000 Date: Wed, 27 Jul 2022 07:25:33 +0200 Message-ID: <87tu73p1o2.wl-tiwai@suse.de> From: Takashi Iwai To: Dipanjan Das Cc: Greg KH , perex@perex.cz, tiwai@suse.com, consult.awy@gmail.com, alsa-devel@alsa-project.org, linux-kernel@vger.kernel.org, syzkaller@googlegroups.com, fleischermarius@googlemail.com, its.priyanka.bose@gmail.com Subject: Re: KASAN: vmalloc-out-of-bounds Write in snd_pcm_hw_params In-Reply-To: References: <874jz82kx0.wl-tiwai@suse.de> User-Agent: Wanderlust/2.15.9 (Almost Unreal) Emacs/27.2 Mule/6.0 MIME-Version: 1.0 (generated by SEMI-EPG 1.14.7 - "Harue") Content-Type: text/plain; charset=US-ASCII X-Spam-Status: No, score=-4.4 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_MED,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 On Tue, 26 Jul 2022 23:40:48 +0200, Dipanjan Das wrote: > > On Sat, Jul 23, 2022 at 3:17 AM Takashi Iwai wrote: > > > > On Sat, 23 Jul 2022 09:00:08 +0200, > > Greg KH wrote: > > > > > > Wondeful, do you have a fix for this that solves the reported problem > > > that you have tested with the reproducer? > > > > ... or at least more detailed information. > > Here is our analysis of the bug in the kernel v5.10.131. > > During allocation, the `size` of the DMA buffer is not page-aligned: > https://elixir.bootlin.com/linux/v5.10.131/source/sound/core/memalloc.c#L149. > However, in sound/core/pcm_native.c:798 > (https://elixir.bootlin.com/linux/v5.10.131/source/sound/core/pcm_native.c#L798), > the `size` variable is page-aligned before memset-ing the `dma_area`. > >From the other BUG_ON assertions in other parts of the code, it looks > like the DMA area is not supposed to be equal to or greater than > 0x200000 bytes. However, due to page-alignment, the `size` can indeed > get rounded up to 0x200000 which causes the out of bound access. > > > Last but not least, you should check whether it's specific to your > > 5.10.x kernel or it's also seen with the latest upstream, too. > > The bug is not reproducible on the latest mainline, because in > sound/core/memalloc.c:66 > (https://github.com/torvalds/linux/blob/5de64d44968e4ae66ebdb0a2d08b443f189d3651/sound/core/memalloc.c#L66) > the allocation function `snd_dma_alloc_dir_pages()` now page-aligns > the `size` right before allocating the DMA buffer. Therefore, any > subsequent page-alignment, like the one in `snd_pcm_hw_params()` does > not cause an out of bound access. Thanks for the analysis. A good news is that, at least for the vmalloc() case, it's a kind of false-positive; vmalloc() always takes the full pages, so practically seen, the size is page-aligned. It's fooling the memory checker, though. But the similar problem could be seen with genalloc calls, and this was fixed by the upstream commit 5c1733e33c888a3cb7f576564d8ad543d5ad4a9e ALSA: memalloc: Align buffer allocations in page size I suppose you can simply backport this commit to 5.10.y. Could you confirm that this fixes your problem? thanks, Takashi