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 Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id D5A53C19F21 for ; Wed, 27 Jul 2022 04:07:01 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S240174AbiG0EHA (ORCPT ); Wed, 27 Jul 2022 00:07:00 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:48826 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231168AbiG0EG6 (ORCPT ); Wed, 27 Jul 2022 00:06:58 -0400 Received: from mail-yw1-x112a.google.com (mail-yw1-x112a.google.com [IPv6:2607:f8b0:4864:20::112a]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 59F032A25A for ; Tue, 26 Jul 2022 21:06:57 -0700 (PDT) Received: by mail-yw1-x112a.google.com with SMTP id 00721157ae682-31f661b3f89so1241817b3.11 for ; Tue, 26 Jul 2022 21:06:57 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=tIslpZQHFFNT/K9JXOkB7aUsG71ZAPk/2bQTBwz7ToQ=; b=KUQtujJAjWwL90RNNQ4NGpYQsLaWmunFoO9ryhmUY4qibNJRzLDuja2VHm2YghJU/g onARSXsmS8n3KUCnD77tEw+eI0pP2RlmAHqF/KICXR7Cro2Z4Rfd3DnmdlvZ7UX1gia0 0AiiF3U7QM1wEDQpA+LDJ74YmJ+r5kIX/dR7/1HdzAMSL8w8HZk9qzFqvSuGhgD1lYl8 Ids+f7Qs8O+GhIWlu6rvn/zdRLAY34QrGHKZCwT9dfmd4jfuI8siSmDh7AMN+U2rwNG1 wByWrxeQcr80cJotnT1IRrAU3iFcH4x6D1M6p6Dzqc73p5lJuOMocvrlL9FfjBcBz1Hv nZrA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=tIslpZQHFFNT/K9JXOkB7aUsG71ZAPk/2bQTBwz7ToQ=; b=hsIgPoEd0MBiRXPnA+eGRzDRymm1iug9DVj9QGG+7gfDxkiMWHPt5BVJcJ20/71u1s OT3n6CrCx2qRL5zhk8XU1JpiyquIZHqcIjxDWP762p0PFnGG3LBr7iChSs2JbpsHB781 5EJfb/Io2i69zIgtJVmb9mF9it6CNgffS89NnIJb4heLdWpewdPtOya0m8XEJTDcFc2z y9cJg/GEJ6vJWNVeG/ZQFEJq5ESFxpWRHbE7E84vSC4TAvY/gO9SIf2YvAXfuKfb2ftZ ip/AlH+iWjc+eIqnsBNWgrb73ugXlksKiMPU3+kopjNiDQDhtNyHxpQhOBK+Fd4A4GA1 4lnQ== X-Gm-Message-State: AJIora/9X+f8wvpg8sM92FHacDOlZxOoXMqkv59tM7fomsQQM3tKoUe9 3UN6yeQCAm+Y019TXvDaAqSTJjoDP/efm0N0flM= X-Google-Smtp-Source: AGRyM1vXD6mc7sPNjd40/6i06v830sQUnZYUsuoYHjtDL0+FLAMC5vERedd5qQdHzUhcz3SOFvJ/8dK/bpRZU1Ijzww= X-Received: by 2002:a81:1ed3:0:b0:31f:5186:91c0 with SMTP id e202-20020a811ed3000000b0031f518691c0mr4441014ywe.401.1658894816509; Tue, 26 Jul 2022 21:06:56 -0700 (PDT) MIME-Version: 1.0 References: <874jz82kx0.wl-tiwai@suse.de> In-Reply-To: From: Lukas Bulwahn Date: Wed, 27 Jul 2022 06:06:45 +0200 Message-ID: Subject: Re: KASAN: vmalloc-out-of-bounds Write in snd_pcm_hw_params To: Dipanjan Das Cc: Takashi Iwai , Greg KH , Jaroslav Kysela , Takashi Iwai , consult.awy@gmail.com, alsa-devel@alsa-project.org, Linux Kernel Mailing List , syzkaller , fleischermarius@googlemail.com, its.priyanka.bose@gmail.com Content-Type: text/plain; charset="UTF-8" Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Tue, Jul 26, 2022 at 11:41 PM 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. > Great analysis! Now, you would just need to identify the specific commit in the mainline repository, where 'function `snd_dma_alloc_dir_pages()` now page-aligns the `size` right before allocating the DMA buffer.', and then ask for applying that commit to the v5.10 stable branch, following the guide from https://www.kernel.org/doc/html/latest/process/stable-kernel-rules.html. Greg KH and Sasha Levin are then going to let you know if that works or needs rework to backport. Lukas 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 Received: from alsa0.perex.cz (alsa0.perex.cz [77.48.224.243]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 3E0F4C19F21 for ; Wed, 27 Jul 2022 04:08:00 +0000 (UTC) Received: from alsa1.perex.cz (alsa1.perex.cz [207.180.221.201]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by alsa0.perex.cz (Postfix) with ESMTPS id 67F9884D; Wed, 27 Jul 2022 06:07:08 +0200 (CEST) DKIM-Filter: OpenDKIM Filter v2.11.0 alsa0.perex.cz 67F9884D DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=alsa-project.org; s=default; t=1658894878; bh=tIslpZQHFFNT/K9JXOkB7aUsG71ZAPk/2bQTBwz7ToQ=; h=References:In-Reply-To:From:Date:Subject:To:Cc:List-Id: List-Unsubscribe:List-Archive:List-Post:List-Help:List-Subscribe: From; b=jDOUg/eXew0pZFhVwmAlJvxBBIOsQHfeMGoVJ0EgrsWusJVAAKwChUaes7ssIF//u W4VoB5zJ6pHh7P0tQQJgFxnphQkTHReXh+6yXKKX8pRay7BOEqDE5WiEQggXkqLFxA 7yfEqi00Nc94caLx0C7iqocAZVGvApdm/S1j9Yfg= Received: from alsa1.perex.cz (localhost.localdomain [127.0.0.1]) by alsa1.perex.cz (Postfix) with ESMTP id C22DFF80155; Wed, 27 Jul 2022 06:07:07 +0200 (CEST) Received: by alsa1.perex.cz (Postfix, from userid 50401) id 16583F8015B; Wed, 27 Jul 2022 06:07:06 +0200 (CEST) Received: from mail-yw1-x1132.google.com (mail-yw1-x1132.google.com [IPv6:2607:f8b0:4864:20::1132]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by alsa1.perex.cz (Postfix) with ESMTPS id 6B8D5F8014E for ; Wed, 27 Jul 2022 06:06:58 +0200 (CEST) DKIM-Filter: OpenDKIM Filter v2.11.0 alsa1.perex.cz 6B8D5F8014E Authentication-Results: alsa1.perex.cz; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="KUQtujJA" Received: by mail-yw1-x1132.google.com with SMTP id 00721157ae682-31f443e276fso44775187b3.1 for ; Tue, 26 Jul 2022 21:06:58 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=tIslpZQHFFNT/K9JXOkB7aUsG71ZAPk/2bQTBwz7ToQ=; b=KUQtujJAjWwL90RNNQ4NGpYQsLaWmunFoO9ryhmUY4qibNJRzLDuja2VHm2YghJU/g onARSXsmS8n3KUCnD77tEw+eI0pP2RlmAHqF/KICXR7Cro2Z4Rfd3DnmdlvZ7UX1gia0 0AiiF3U7QM1wEDQpA+LDJ74YmJ+r5kIX/dR7/1HdzAMSL8w8HZk9qzFqvSuGhgD1lYl8 Ids+f7Qs8O+GhIWlu6rvn/zdRLAY34QrGHKZCwT9dfmd4jfuI8siSmDh7AMN+U2rwNG1 wByWrxeQcr80cJotnT1IRrAU3iFcH4x6D1M6p6Dzqc73p5lJuOMocvrlL9FfjBcBz1Hv nZrA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=tIslpZQHFFNT/K9JXOkB7aUsG71ZAPk/2bQTBwz7ToQ=; b=uc2qKJbqC7aOO9YC2LDjUPBrO80PDkKCZHNshVTg8WVcVO+dxFakYEIh55wox/Jp+6 ODwicWjmW/el5JLH38jKQWMb0FH7IEEM3j4FHT98Y8kmr03v2fE+wzlynVcCbPAviVua Gv2y7uxZH6Cx3ZMQJSdCTIlxtbvFxX2UQJvNVNHHd+yIfL3dzSy4AQPOCb841p6PRrFp 06WX5W/6oTKjVjcu3D6KTrTD+G9FU4tLSMnc5EMfRcVsh8B1BFNBWA80VR8F0V0FS4ie CWKf2WYRqQ/T8EQmD2GRs88iTADilPMBrXe13NLD/82lwZsKQDWkn6NuEOFpqYH4YkCg pVRQ== X-Gm-Message-State: AJIora+Ri9gw6mxjVfLF75w1UfZ0SqGJJyM/oFh3OncUQilHX2eVc+o+ ce+nVDjHOYb98REltQD16ajYl6dIr7Br22W+XMo= X-Google-Smtp-Source: AGRyM1vXD6mc7sPNjd40/6i06v830sQUnZYUsuoYHjtDL0+FLAMC5vERedd5qQdHzUhcz3SOFvJ/8dK/bpRZU1Ijzww= X-Received: by 2002:a81:1ed3:0:b0:31f:5186:91c0 with SMTP id e202-20020a811ed3000000b0031f518691c0mr4441014ywe.401.1658894816509; Tue, 26 Jul 2022 21:06:56 -0700 (PDT) MIME-Version: 1.0 References: <874jz82kx0.wl-tiwai@suse.de> In-Reply-To: From: Lukas Bulwahn Date: Wed, 27 Jul 2022 06:06:45 +0200 Message-ID: Subject: Re: KASAN: vmalloc-out-of-bounds Write in snd_pcm_hw_params To: Dipanjan Das Content-Type: text/plain; charset="UTF-8" Cc: alsa-devel@alsa-project.org, fleischermarius@googlemail.com, Takashi Iwai , Greg KH , Takashi Iwai , consult.awy@gmail.com, syzkaller , its.priyanka.bose@gmail.com, Linux Kernel Mailing List X-BeenThere: alsa-devel@alsa-project.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: "Alsa-devel mailing list for ALSA developers - http://www.alsa-project.org" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: alsa-devel-bounces@alsa-project.org Sender: "Alsa-devel" On Tue, Jul 26, 2022 at 11:41 PM 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. > Great analysis! Now, you would just need to identify the specific commit in the mainline repository, where 'function `snd_dma_alloc_dir_pages()` now page-aligns the `size` right before allocating the DMA buffer.', and then ask for applying that commit to the v5.10 stable branch, following the guide from https://www.kernel.org/doc/html/latest/process/stable-kernel-rules.html. Greg KH and Sasha Levin are then going to let you know if that works or needs rework to backport. Lukas