Received: by 2002:ac0:e34a:0:0:0:0:0 with SMTP id g10csp36664imn; Tue, 26 Jul 2022 21:33:58 -0700 (PDT) X-Google-Smtp-Source: AGRyM1ukPu42FpSG7FPAhuFsWVizkB8rqC/WQqJ71cMvuFu070nzoj81gf3TwVlkla4benl4HOw3 X-Received: by 2002:a17:907:7628:b0:72b:4d6f:ce8a with SMTP id jy8-20020a170907762800b0072b4d6fce8amr16252034ejc.59.1658896438293; Tue, 26 Jul 2022 21:33:58 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1658896438; cv=none; d=google.com; s=arc-20160816; b=tS7GgKtah/URsMcfzj2JJjOk4zsaFBhiC29244jmE1e4ns7xHLY+P1U4QRMr1mAPQ7 B8VzlXr3qhfeyV5AnZGV9nNRvZ3QkO/pxv/uAv5OFzA9qraURf2r0+PNVvKufnYzsug9 p4IcI3z1JTGpqkb9Nb+umReI3sYBuMlTUwB20cdA3j4rAEbVUfvJSo0NVgW5a1ZIlgiD 47O2NgybMdqu5Guo7RsH1HmmtnQ/s5VCwCe0FjoBEyQcpXLMukqNWHswkz89VSVGTwDu sqCWUTHhU6kwDBPzuuFCyX7mk4DrCd1SDnJ5GsT3IPdOsv7XaDYzQ7mrwRp0yYndZ2w4 ifbQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:cc:to:subject:message-id:date:from:in-reply-to :references:mime-version:dkim-signature; bh=tIslpZQHFFNT/K9JXOkB7aUsG71ZAPk/2bQTBwz7ToQ=; b=ziPfsL0zvvQnSOuxonV+b3H6amiA4E3lpMCW6H+88i7/RfAFkakb9QU+PjE/XrSm+g 7cHvwdBiKIQFjDHElPCeHGEqyz4S0VOj1WIzubdSYr2z2d7HhKqfNQMu9mrZqVl9baxZ K1sAurPdhheh7MWRsFLpMnMUnQlFyuKTpBNTXetck58GYs57Uu1df5s84QKNzNqN/S9f 6GCcjjOdaiE5LxGUgo1TRKS9kN+x5cP18xSwgb95g01nsGM9zLRFM+jyGhxeFNae6BxN tjTbZgC8/gYAKEHrqK0AYpHrGoO3apYXYDguT28BrWIePWwvb1PteW0y2Enqg23tJ6Gz lB4g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20210112 header.b=KUQtujJA; 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=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id u23-20020a1709060b1700b0072b0c1b8f1bsi12541217ejg.727.2022.07.26.21.33.33; Tue, 26 Jul 2022 21:33:58 -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=@gmail.com header.s=20210112 header.b=KUQtujJA; 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=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S240131AbiG0EG7 (ORCPT + 99 others); Wed, 27 Jul 2022 00:06:59 -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-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" X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,FREEMAIL_FROM, RCVD_IN_DNSWL_NONE,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, 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