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 82FACC4363A for ; Fri, 30 Oct 2020 15:19:49 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id D49022225C for ; Fri, 30 Oct 2020 15:19:48 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="Msw/AdRy" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org D49022225C 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 552686B006E; Fri, 30 Oct 2020 11:19:48 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 501676B0070; Fri, 30 Oct 2020 11:19:48 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 3A1216B0071; Fri, 30 Oct 2020 11:19:48 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0207.hostedemail.com [216.40.44.207]) by kanga.kvack.org (Postfix) with ESMTP id 01AAC6B006E for ; Fri, 30 Oct 2020 11:19:47 -0400 (EDT) Received: from smtpin08.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay02.hostedemail.com (Postfix) with ESMTP id 93DC93623 for ; Fri, 30 Oct 2020 15:19:47 +0000 (UTC) X-FDA: 77428951614.08.help88_521570927297 Received: from filter.hostedemail.com (10.5.16.251.rfc1918.com [10.5.16.251]) by smtpin08.hostedemail.com (Postfix) with ESMTP id 723EE1819E772 for ; Fri, 30 Oct 2020 15:19:47 +0000 (UTC) X-HE-Tag: help88_521570927297 X-Filterd-Recvd-Size: 7832 Received: from mail-oi1-f193.google.com (mail-oi1-f193.google.com [209.85.167.193]) by imf32.hostedemail.com (Postfix) with ESMTP for ; Fri, 30 Oct 2020 15:19:46 +0000 (UTC) Received: by mail-oi1-f193.google.com with SMTP id 9so6991030oir.5 for ; Fri, 30 Oct 2020 08:19:46 -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=Od+UUSBMiEqFH2KlwfDgZow7v7NLfac8lHnjw8U4wHg=; b=Msw/AdRyc5nqCZQjTL62/j3DAPrGVm/qwHs2dRbaIBJuK+/frX27C5rJQ5k8W7I6Qs 9j3/TqOiiYCnARGKa24Ac1lPztggkK0h9SNklfhqqPpwK8pONUpeHNAkYCM/hc/EOYpB bARGijsJ2eUveDGExQ3R7cb2KJ8RziSFXX6qMQdIkXAzsgEC/f6PCmc/SvBqaey74nnX ZoBLFHoiotr3hOSMqn2LTxiAYctu58P9xSQBTsHQ3DJhc9XIEwO7m7myKRHD29rrE8K9 UyqdV7np7wugfiefBYXEG4dXmZcekmzP69/zLUhSANWfnmABr8xzI3guqJw9TvQJcurB r14A== 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=Od+UUSBMiEqFH2KlwfDgZow7v7NLfac8lHnjw8U4wHg=; b=UFs4OpZNA4Bs+UO6GroVBL64sx6C7S/h6/h4NOwVAFXVwl/bIdwyFTnr5J8I7p+g54 rMwgZLHBQ6NHf2u7tPMmVq8FvcLKrEhnK7DwThB/J9tGjz8ybFW4Ni3q1eQG7K5wmw0G ER7MZASe75YdMleCgvccsQ6YD6X/S04CyJMsxxlnaet8GzqEpableEBvOByak96lvL8d H3XDibzBRNCnz6B4GpGitlT40uX/lk2F0XAJSVgYCLQtIZN3pummgscHEy0p6n2Xmg5Z sIeEDnEc2bL9m8+Xyb7WfIG/86q1udideV4sRkcpja0tt3KdmaFLwUAkW5WFXADA/ro8 CYzA== X-Gm-Message-State: AOAM530kTGqidj/paRPeZg1QwZfrUMY2UXpfseNBJxzA6+5bD4w0vmgg 7NW5bEtSMhe20++b98/S5izObHiYFG/9A6RtfbmepA== X-Google-Smtp-Source: ABdhPJwaDMBPSAvV/BhwOTbOOrTIc57OvUTldHxUnQO/NP/hqPklvwPxyUHr9DEfl0srWqfr3ZmYyytpffNXWuRPHTA= X-Received: by 2002:aca:4f55:: with SMTP id d82mr1984254oib.172.1604071185897; Fri, 30 Oct 2020 08:19:45 -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 16:19:34 +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 16:09, Jann Horn wrote: > > On Fri, Oct 30, 2020 at 2:46 PM Marco Elver wrote: > > 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. > > FWIW, I wouldn't be surprised if other parts of the kernel also ended > up wanting to have in-object redzones eventually - e.g. inside skb > buffers, which have a struct skb_shared_info at the end. AFAIU at the > moment, KASAN can't catch small OOB accesses from these buffers > because of the following structure. Sure, and it might also become more interesting with MTE-based KASAN. But, currently we recommend not to enable generic KASAN+KFENCE, because it'd be redundant if the instrumentation price for generic (or SW-tag) KASAN is already paid. The changes here are also mostly for testing KFENCE itself. That may change with MTE-based KASAN, however, which may have modes where stack traces aren't collected and having KFENCE to get actionable debug-info across a fleet of machines may still be wanted. But that story is still evolving. The code here is only for the generic and SW-tag based KASAN modes, and MTE will have its own kasan_{un,}poison_shadow (afaik it's being renamed to kasan_{un,}poison_memory) which works just fine with KFENCE AFAIK. > > I think we better add a kfence guard to > > kasan_poison_shadow() as well. > > Sounds good.