Received: by 2002:a5d:925a:0:0:0:0:0 with SMTP id e26csp694074iol; Thu, 9 Jun 2022 11:53:06 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwwE+0DZvaXenlEwFcc0NFAuTask8JGc7j5/H7vTsjjK6rSNOsJVZn+sXBdEvaTSvR9g7OJ X-Received: by 2002:a17:902:d653:b0:163:78e0:552f with SMTP id y19-20020a170902d65300b0016378e0552fmr41050634plh.63.1654800786655; Thu, 09 Jun 2022 11:53:06 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1654800786; cv=none; d=google.com; s=arc-20160816; b=Kyu3jxUdsICfsTnIEZ9vSGQ2mVTMG/Ynu0at6cYaSNcc3bTdiw0/7EL0Q97zKS/8M7 LkEacH0GgLCYAlk6JEu3AkS6PqYjXEG4GkES6kWqZ0oi4Jzt194a9c0QN3uIW9BmDwEl NpBveoUzIbz3s5Te5O7jwTjV+304WU33XniMGhUCHhKHwTmUSkknIkr57VdTU4KKqtCI T4uFv2qdJohxAB57w3nqINX4osZILq76JtR5mOV2X3XJfTnx6N9mkzGLQdd8tey74U8C ldqKt5eV92WtCtuoTo7kUX39Cg1pJoTitASjzX1ro7brDUpTkusUv/qNK0F4JUkb4rZu fq2Q== 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=lZmFRyplZFrFLoO+ATeHLa4N7zJRWugh0qo8UpTNm2o=; b=lH/LTuiqxiPDcV5SlvbzVFFwXINP+aSAR72qTyNzM4Mckn2BG6OwENKdi5m9l+Hf7s b6u3Ub5RfjAu/DdbX3oeueok1Kodpz7DpOnTBJzLMsDfI8MKLDcvGn91w9BhIbXg8IGF GHwlI2tI9nXW6aAYiZoKUfY6dKiwia3rH8/o+GBZe4XxSZchQWWaW1aesGmsaEojJFST /AyNR9QgTSKyyDoBnCFYj0S1kBIZuP/b8NRk+FWv7kgfG3pSV/vtpO/ksANOdz/InBdm a7qZstggoRG2Wsx1+D994l4yvzel+Gr9yBoXxTu8ofGxMWmtLKRhErksbNvOmRxAwv7m Wi0g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20210112 header.b=RWIKj3WM; 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 h1-20020a636c01000000b003fd97d4ed97si715070pgc.21.2022.06.09.11.52.52; Thu, 09 Jun 2022 11:53:06 -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=RWIKj3WM; 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 S1345289AbiFISMt (ORCPT + 99 others); Thu, 9 Jun 2022 14:12:49 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:35860 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235143AbiFISMs (ORCPT ); Thu, 9 Jun 2022 14:12:48 -0400 Received: from mail-il1-x132.google.com (mail-il1-x132.google.com [IPv6:2607:f8b0:4864:20::132]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 9F7AF3B090A for ; Thu, 9 Jun 2022 11:12:46 -0700 (PDT) Received: by mail-il1-x132.google.com with SMTP id p1so19320835ilj.9 for ; Thu, 09 Jun 2022 11:12:46 -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=lZmFRyplZFrFLoO+ATeHLa4N7zJRWugh0qo8UpTNm2o=; b=RWIKj3WMK49P5Zmpj6ScWuednCPkicoLBfUdsszcedTzAn1hnIqJ27HJKwQeuxPkrf FiSeR3HEOThstP9AOalEwdFA0TH8lUcYMkiRKoCY8c5qoGXFJnROeuqfgRbHNmIjm2yv ZxuNgbtHELNgHBed7GTqcDNM+LUhtOVYMilQtlqIwX3k+wWIDF/5cLAVDUw2N0DjZL/x E4L0zHb3ycHhOAFu6gi1c6mtkslLKqSzU++q6y2hQk+hfDD54GLbLlFUtIBhWp0/dvYf IYr+Lo4RLmmU08ARY0Zd+CT39p0kl1BDRG7Zuvec6P+JPdrP70aTUNLRNNzdk8omy+H6 Q/zw== 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=lZmFRyplZFrFLoO+ATeHLa4N7zJRWugh0qo8UpTNm2o=; b=KKnNPrp9kedLy/QxShZpeE/xNWtnIhPPEDVL33IFpy6EzQ+jtnw7fVwCEUbCVfnrnt PEAgUB8Dc6Q2g+ur7Jjd9KhzZRfWxiLr1q3hGb/O6Rhfcvc7UnKwcZ/bl8lpBwi++SeZ XN+p5AW3eHikzrCGic4EpiJzFG3dfES5pp51sQvtN+SkQwIhj3GXrnPStOYGtfqxeNMM dbuSpEdvNpV/6NZ7Y1t4a+AzSKCa7hJ7/GA8ggjZrqelcZDey1YASVF8eKVPmbzqkEnI HcLFdQ8Oq+E2LbSvrCZDOE0+O3mtFq8jmYpXZ1cCWNZ3wkoQLWaYqs3I6IxLvBN6WXnr 3PPg== X-Gm-Message-State: AOAM5301xLrQoSZfBteuP1aGeR8lqeiA85krJWKg8E6idyJD4xGHNAm7 0mpW5QdcVyfPNb8ow2PIIdvfql45LpdUKCL6BYU= X-Received: by 2002:a92:3609:0:b0:2c6:3595:2a25 with SMTP id d9-20020a923609000000b002c635952a25mr23142353ila.233.1654798365958; Thu, 09 Jun 2022 11:12:45 -0700 (PDT) MIME-Version: 1.0 References: <4c76a95aff79723de76df146a10888a5a9196faf.1654011120.git.andreyknvl@google.com> In-Reply-To: From: Andrey Konovalov Date: Thu, 9 Jun 2022 20:12:35 +0200 Message-ID: Subject: Re: [PATCH 3/3] kasan: fix zeroing vmalloc memory with HW_TAGS To: Marco Elver Cc: andrey.konovalov@linux.dev, Alexander Potapenko , Dmitry Vyukov , Andrey Ryabinin , kasan-dev , Andrew Morton , Linux Memory Management List , LKML , Andrey Konovalov 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,T_SCC_BODY_TEXT_LINE 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 Wed, Jun 1, 2022 at 2:28 PM Marco Elver wrote: > > On Tue, May 31, 2022 at 05:43PM +0200, andrey.konovalov@linux.dev wrote: > > From: Andrey Konovalov > > > > HW_TAGS KASAN skips zeroing page_alloc allocations backing vmalloc > > mappings via __GFP_SKIP_ZERO. Instead, these pages are zeroed via > > kasan_unpoison_vmalloc() by passing the KASAN_VMALLOC_INIT flag. > > > > The problem is that __kasan_unpoison_vmalloc() does not zero pages > > when either kasan_vmalloc_enabled() or is_vmalloc_or_module_addr() fail. > > > > Thus: > > > > 1. Change __vmalloc_node_range() to only set KASAN_VMALLOC_INIT when > > __GFP_SKIP_ZERO is set. > > > > 2. Change __kasan_unpoison_vmalloc() to always zero pages when the > > KASAN_VMALLOC_INIT flag is set. > > > > 3. Add WARN_ON() asserts to check that KASAN_VMALLOC_INIT cannot be set > > in other early return paths of __kasan_unpoison_vmalloc(). > > > > Also clean up the comment in __kasan_unpoison_vmalloc. > > > > Fixes: 23689e91fb22 ("kasan, vmalloc: add vmalloc tagging for HW_TAGS") > > Signed-off-by: Andrey Konovalov > > --- > > mm/kasan/hw_tags.c | 30 ++++++++++++++++++++++-------- > > mm/vmalloc.c | 10 +++++----- > > 2 files changed, 27 insertions(+), 13 deletions(-) > > > > diff --git a/mm/kasan/hw_tags.c b/mm/kasan/hw_tags.c > > index 9e1b6544bfa8..c0ec01eadf20 100644 > > --- a/mm/kasan/hw_tags.c > > +++ b/mm/kasan/hw_tags.c > > @@ -263,21 +263,31 @@ void *__kasan_unpoison_vmalloc(const void *start, unsigned long size, > > u8 tag; > > unsigned long redzone_start, redzone_size; > > > > - if (!kasan_vmalloc_enabled()) > > - return (void *)start; > > + if (!kasan_vmalloc_enabled() || !is_vmalloc_or_module_addr(start)) { > > + struct page *page; > > + const void *addr; > > + > > + /* Initialize memory if required. */ > > + > > This whole block of code looks out-of-place in this function, since it's > not at all related to unpoisoning but a fallback if KASAN-vmalloc is off > but we still want to initialize the memory. > > Maybe to ease readability here I'd change it to look like: Sounds good, will do in v2! Thanks!