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 X-Spam-Level: X-Spam-Status: No, score=-17.9 required=3.0 tests=BAYES_00,DKIMWL_WL_MED, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_PATCH,MAILING_LIST_MULTI,SIGNED_OFF_BY,SPF_HELO_NONE,SPF_PASS, USER_IN_DEF_DKIM_WL autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 84009C4727C for ; Tue, 29 Sep 2020 13:13:48 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id 01FD32145D for ; Tue, 29 Sep 2020 13:13:47 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="Lq57cMFj" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 01FD32145D Authentication-Results: mail.kernel.org; dmarc=fail (p=reject dis=none) header.from=google.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=owner-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix) id EAEC96B006E; Tue, 29 Sep 2020 09:13:46 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id E5D5D6B0070; Tue, 29 Sep 2020 09:13:46 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id D26126B0071; Tue, 29 Sep 2020 09:13:46 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0051.hostedemail.com [216.40.44.51]) by kanga.kvack.org (Postfix) with ESMTP id BC5036B006E for ; Tue, 29 Sep 2020 09:13:46 -0400 (EDT) Received: from smtpin18.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay04.hostedemail.com (Postfix) with ESMTP id 79C2C3644 for ; Tue, 29 Sep 2020 13:13:46 +0000 (UTC) X-FDA: 77316141252.18.toes79_1417a252718a Received: from filter.hostedemail.com (10.5.16.251.rfc1918.com [10.5.16.251]) by smtpin18.hostedemail.com (Postfix) with ESMTP id 144D51021F704 for ; Tue, 29 Sep 2020 13:13:43 +0000 (UTC) X-HE-Tag: toes79_1417a252718a X-Filterd-Recvd-Size: 7408 Received: from mail-wm1-f68.google.com (mail-wm1-f68.google.com [209.85.128.68]) by imf31.hostedemail.com (Postfix) with ESMTP for ; Tue, 29 Sep 2020 13:13:42 +0000 (UTC) Received: by mail-wm1-f68.google.com with SMTP id y15so4769399wmi.0 for ; Tue, 29 Sep 2020 06:13:42 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20161025; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=JTFDtrWAFNtSx+STL9ivxdzcSQCqNLxR2RvvS87FYs8=; b=Lq57cMFjJdsZitlNgytm7PsrAOH3c5fyYhhIrlpRYUvEz+9FkNlEgU3qVOAcJ0wuFW +xn3neApnxiN+gj66GSFdigtNadD1ZHNCZXv6sfa8RiQSsMF+f+o1kSNYXryQqzMasHX JT2aFyQzlCtJVcEDR2ut0tjnkOERq4fG8VuBM1ZPGHKWT0P+DWCh0/AvKZ9yWyZv76fE +OdQA9RlpxxFeDDERUSkYcdO0ltny8r91ypfnmSGwOja5+NxtDYhJSkAHbo7m9XlWxGG CMDIWJ0JlfEe51eyKpYc23+bWPe9XFUr+IGASvf+0qQZlj8kKWMYiJlvOiXFpznXleA5 Iz7g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=JTFDtrWAFNtSx+STL9ivxdzcSQCqNLxR2RvvS87FYs8=; b=jDXy2Xs1Hjo3WugAjyWUros6iQs2j11PEPDfv/XkvqffmK0yM67U/HQq32ij+eSCj2 fDV7tFrSOwfv1/bGvWgUCnOMAGUmTe2WTO5Zz91jCHu8xRyeoCzL1/puX++a4o39Nb9R 1g+4j5C9w40bXdA/hptYr2ytpzDjbweL7IjHAIwQeEHxP76/JJJNUWXT9bP8JkLRQFGd jHGg/9Oj36yMXF8h9qi7IqgtcdrZAwKM1N4ouAX0mChrQotIgnHcrerK2tAVW7akwvLQ TCl6sUfgicdwUPfdC39oOpImfQ3kAkK6+bcMvaJ8K0xG0xnGDfG8YasbcTxLxp9K4hMT c5ew== X-Gm-Message-State: AOAM533Zzs+KpqbWK3vCNf9RPq+u7uIJv/VnJ2RsjDRMSJUVPobSq3OZ 4jNF4LkEyC5s9A+fh8ptbVs93wJmTdTpzTI1gfkq6g== X-Google-Smtp-Source: ABdhPJzw/Zb4GAgOYha9l6GBhoHEbXOYGxJdrW488S4mgz+iiVYDyyZg9YqgYZzaKC9YtLUJm/IWtLrVjvkYqHlU+Hs= X-Received: by 2002:a7b:c749:: with SMTP id w9mr4247992wmk.29.1601385221422; Tue, 29 Sep 2020 06:13:41 -0700 (PDT) MIME-Version: 1.0 References: <20200921132611.1700350-1-elver@google.com> <20200921132611.1700350-7-elver@google.com> In-Reply-To: From: Alexander Potapenko Date: Tue, 29 Sep 2020 15:13:30 +0200 Message-ID: Subject: Re: [PATCH v3 06/10] kfence, kasan: make KFENCE compatible with KASAN To: Andrey Konovalov Cc: Marco Elver , Andrew Morton , "H. Peter Anvin" , "Paul E . McKenney" , Andrey Ryabinin , Andy Lutomirski , Borislav Petkov , Catalin Marinas , Christoph Lameter , Dave Hansen , David Rientjes , Dmitry Vyukov , Eric Dumazet , Greg Kroah-Hartman , Hillf Danton , Ingo Molnar , Jann Horn , Jonathan.Cameron@huawei.com, Jonathan Corbet , Joonsoo Kim , Kees Cook , Mark Rutland , Pekka Enberg , Peter Zijlstra , sjpark@amazon.com, Thomas Gleixner , Vlastimil Babka , Will Deacon , "the arch/x86 maintainers" , "open list:DOCUMENTATION" , LKML , kasan-dev , Linux ARM , Linux Memory Management List Content-Type: text/plain; charset="UTF-8" X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: On Tue, Sep 29, 2020 at 2:21 PM Andrey Konovalov wrote: > > On Mon, Sep 21, 2020 at 3:26 PM Marco Elver wrote: > > > > From: Alexander Potapenko > > > > We make KFENCE compatible with KASAN for testing KFENCE itself. In > > particular, KASAN helps to catch any potential corruptions to KFENCE > > state, or other corruptions that may be a result of freepointer > > corruptions in the main allocators. > > > > To indicate that the combination of the two is generally discouraged, > > CONFIG_EXPERT=y should be set. It also gives us the nice property that > > KFENCE will be build-tested by allyesconfig builds. > > > > Reviewed-by: Dmitry Vyukov > > Co-developed-by: Marco Elver > > Signed-off-by: Marco Elver > > Signed-off-by: Alexander Potapenko > > --- > > lib/Kconfig.kfence | 2 +- > > mm/kasan/common.c | 7 +++++++ > > 2 files changed, 8 insertions(+), 1 deletion(-) > > > > diff --git a/lib/Kconfig.kfence b/lib/Kconfig.kfence > > index 4c2ea1c722de..6825c1c07a10 100644 > > --- a/lib/Kconfig.kfence > > +++ b/lib/Kconfig.kfence > > @@ -10,7 +10,7 @@ config HAVE_ARCH_KFENCE_STATIC_POOL > > > > menuconfig KFENCE > > bool "KFENCE: low-overhead sampling-based memory safety error detector" > > - depends on HAVE_ARCH_KFENCE && !KASAN && (SLAB || SLUB) > > + depends on HAVE_ARCH_KFENCE && (!KASAN || EXPERT) && (SLAB || SLUB) > > depends on JUMP_LABEL # To ensure performance, require jump labels > > select STACKTRACE > > help > > diff --git a/mm/kasan/common.c b/mm/kasan/common.c > > index 950fd372a07e..f5c49f0fdeff 100644 > > --- a/mm/kasan/common.c > > +++ b/mm/kasan/common.c > > @@ -18,6 +18,7 @@ > > #include > > #include > > #include > > +#include > > #include > > #include > > #include > > @@ -396,6 +397,9 @@ static bool __kasan_slab_free(struct kmem_cache *cache, void *object, > > tagged_object = object; > > object = reset_tag(object); > > > > + if (is_kfence_address(object)) > > + return false; > > + > > if (unlikely(nearest_obj(cache, virt_to_head_page(object), object) != > > object)) { > > kasan_report_invalid_free(tagged_object, ip); > > @@ -444,6 +448,9 @@ static void *__kasan_kmalloc(struct kmem_cache *cache, const void *object, > > if (unlikely(object == NULL)) > > return NULL; > > > > + if (is_kfence_address(object)) > > + return (void *)object; > > + > > redzone_start = round_up((unsigned long)(object + size), > > KASAN_SHADOW_SCALE_SIZE); > > redzone_end = round_up((unsigned long)object + cache->object_size, > > -- > > 2.28.0.681.g6f77f65b4e-goog > > > > With KFENCE + KASAN both enabled we need to bail out in all KASAN > hooks that get called from the allocator, right? Do I understand > correctly that these two are the only ones that are called for > KFENCE-allocated objects due to the way KFENCE is integrated into the > allocator? Yes, these two places were sufficient; we've checked that KFENCE and KASAN work together.