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=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 41122C5517A for ; Fri, 30 Oct 2020 15:20:23 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id D8CD022241 for ; Fri, 30 Oct 2020 15:20:22 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="Msw/AdRy" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726871AbgJ3PUB (ORCPT ); Fri, 30 Oct 2020 11:20:01 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:42536 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726999AbgJ3PUA (ORCPT ); Fri, 30 Oct 2020 11:20:00 -0400 Received: from mail-oi1-x243.google.com (mail-oi1-x243.google.com [IPv6:2607:f8b0:4864:20::243]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id D9123C0613D6 for ; Fri, 30 Oct 2020 08:19:46 -0700 (PDT) Received: by mail-oi1-x243.google.com with SMTP id k65so6983124oih.8 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=L14SX1mnQPGXlfhbFPBu+pa936c0fUpqJrbjHZVeFv06GGu97+DFh9sziBT/F5IEwQ 8G9XRnid1j4eozEQ8dvpc3EAKgOgcxrG72Y3RDeLFsWS+bqDYn5/ZHMFS+wpnonwoguG dJEE2IHxcb4tZz4XV9aHMgqWfP22Asq/gPa/PBe3tE6zaNrRQ0GSCCq1m2E9tsf9zngc AHke6Mvf/ubqcJRU+YhYCJpMyY6l7E/BVZoOJxmrUpPpVBxnXUSW7BPLIKyQzs8woaFE yeREMRr1N4slbmXaQvgdm/kPYBHFabvQD/95dfbs28orFxpOqwl3u6wVzwzWrUqPnfLj 2rAQ== X-Gm-Message-State: AOAM530p17L4sHf3vitymbn6XwfMA55VwzOHnF+WJxrKFEWMkkgGrpqz Rb7CscioQZwbIeUXBWmyrMRjORT7oinuR2aay1a/xw== 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" Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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.