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.4 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=ham 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 2FF48C4363A for ; Fri, 30 Oct 2020 13:46:56 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id 75121206CB for ; Fri, 30 Oct 2020 13:46:55 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="ADogkMye" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 75121206CB 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 A15476B006C; Fri, 30 Oct 2020 09:46:54 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 99F6B6B0070; Fri, 30 Oct 2020 09:46:54 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 840496B0071; Fri, 30 Oct 2020 09:46:54 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0106.hostedemail.com [216.40.44.106]) by kanga.kvack.org (Postfix) with ESMTP id 5231C6B006C for ; Fri, 30 Oct 2020 09:46:54 -0400 (EDT) Received: from smtpin14.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay04.hostedemail.com (Postfix) with ESMTP id EC2B91EF3 for ; Fri, 30 Oct 2020 13:46:53 +0000 (UTC) X-FDA: 77428717506.14.owner70_3e0459a27296 Received: from filter.hostedemail.com (10.5.16.251.rfc1918.com [10.5.16.251]) by smtpin14.hostedemail.com (Postfix) with ESMTP id CDDF418229835 for ; Fri, 30 Oct 2020 13:46:53 +0000 (UTC) X-HE-Tag: owner70_3e0459a27296 X-Filterd-Recvd-Size: 6261 Received: from mail-oi1-f193.google.com (mail-oi1-f193.google.com [209.85.167.193]) by imf26.hostedemail.com (Postfix) with ESMTP for ; Fri, 30 Oct 2020 13:46:53 +0000 (UTC) Received: by mail-oi1-f193.google.com with SMTP id k65so6682570oih.8 for ; Fri, 30 Oct 2020 06:46:53 -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=L9KsQ649Ydk+F62S7OnKir8xMXm76fswU9q4GRYaxwA=; b=ADogkMyeqzMi65mLW89eeqxIGlmWBYfTZ3bx3nTmGY2wkQ6ew8sNjqD3uCULVKqUBx onwBT2ZjgdJeC+Ep0EzvoTvRnAW+7Iiyz/5yg7sD3QireG2CCRHS4HyyFb0a9sVm4Gkx oK82pyK24ABm86duxNdYoH4hRNUNuqmxLkaaFdx57gQBJ1bVnIgROlYmlYkkJWUifom+ jVyfyKxvVyc1QRuPHf7ZI42FxPpsi/MDAFg5vR+O2aNlLtDCXRhTiwTAI53bIKW7tEOt sxaK6rXBYliu3y15wi8dcdrb3eape6+JDJFEJWvX3eZs2nbse3syqEqt/L1LVuSMUunF HVTQ== 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=L9KsQ649Ydk+F62S7OnKir8xMXm76fswU9q4GRYaxwA=; b=exFMRyr87cKAlU+R1JasPi/oUDaxaOmYuTz8QWvahjAlTyivZ1nYGn8wmoeIzuaKXl K2a5W562sa59pYLEmK/iFi7l4rncfixMeB/8KKcKk/oaY1S8jC5d/QEel/+AnYRgUWSf G+bkhmxnw157zBF6fr7fG3oCqzDl2E4eHd74IWyZGpFm/4TmaxJ3mej3okppdXmd12or StRTIit1msOGRusDulUgdYdOz8MKGAqAMgGXUkutZNnvv4llvsODEnDO1eNx9TwpJqG8 xE3VTeXwCLWam1HZmoQzhXSia4LsESO/Oj3iOuEE+xNe9fY9fSPNX6N2UUbWrpEqXkgu KcIw== X-Gm-Message-State: AOAM533AEc+bPaWQbxuZQSAyXBcacQhuKryi0uQ+RRBsU0w+BS12M2o1 eHWzZRW6n7KC4BTODxUho35ftizX+z59qltMMJ8mFw== X-Google-Smtp-Source: ABdhPJxtllrD/ti+v3NOGXiV4JmOCXFOuYxncPEQf23c9uErySYb6wPEvDGJEVT3VNX7Kda0gfhJ/kKTgntzgs7XD78= X-Received: by 2002:a54:4812:: with SMTP id j18mr1740133oij.70.1604065612340; Fri, 30 Oct 2020 06:46:52 -0700 (PDT) MIME-Version: 1.0 References: <20201029131649.182037-1-elver@google.com> <20201029131649.182037-7-elver@google.com> In-Reply-To: From: Marco Elver Date: Fri, 30 Oct 2020 14:46:40 +0100 Message-ID: Subject: Re: [PATCH v6 6/9] kfence, kasan: make KFENCE compatible with KASAN To: Jann Horn Cc: Andrew Morton , Alexander Potapenko , "H . Peter Anvin" , "Paul E . McKenney" , Andrey Konovalov , 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 , Jonathan Cameron , Jonathan Corbet , Joonsoo Kim , =?UTF-8?Q?J=C3=B6rn_Engel?= , Kees Cook , Mark Rutland , Pekka Enberg , Peter Zijlstra , SeongJae Park , Thomas Gleixner , Vlastimil Babka , Will Deacon , "the arch/x86 maintainers" , "open list:DOCUMENTATION" , kernel list , kasan-dev , Linux ARM , Linux-MM 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 Fri, 30 Oct 2020 at 03:50, Jann Horn wrote: > > On Thu, Oct 29, 2020 at 2:17 PM Marco Elver wrote: > > 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 > > Reviewed-by: Jann Horn Thanks! > with one nit: > > [...] > > diff --git a/mm/kasan/common.c b/mm/kasan/common.c > [...] > > @@ -141,6 +142,14 @@ void kasan_unpoison_shadow(const void *address, size_t size) > > */ > > address = reset_tag(address); > > > > + /* > > + * We may be called from SL*B internals, such as ksize(): with a size > > + * not a multiple of machine-word size, avoid poisoning the invalid > > + * portion of the word for KFENCE memory. > > + */ > > + if (is_kfence_address(address)) > > + return; > > It might be helpful if you could add a comment that explains that > kasan_poison_object_data() does not need a similar guard because > kasan_poison_object_data() is always paired with > kasan_unpoison_object_data() - that threw me off a bit at first. Well, KFENCE objects should never be poisoned/unpoisoned because the kasan_alloc and free hooks have a kfence guard, and none of the code in sl*b.c that does kasan_{poison,unpoison}_object_data() should be executed for KFENCE objects. But I just noticed that kernel/scs.c seems to kasan_poison and unpoison objects, and keeps them poisoned for most of the object lifetime. I think we better add a kfence guard to kasan_poison_shadow() as well. Thanks, -- Marco