Received: by 2002:a05:6a10:9e8c:0:0:0:0 with SMTP id y12csp1355178pxx; Fri, 30 Oct 2020 08:11:22 -0700 (PDT) X-Google-Smtp-Source: ABdhPJx363Zk4GEzAO5WJ8UZmaOm8F1XKvZlG1CS8DzQLY5hkUuuyU3SOaXRCgTd9sLVJedfIWX0 X-Received: by 2002:a17:906:7e0b:: with SMTP id e11mr3068872ejr.217.1604070682072; Fri, 30 Oct 2020 08:11:22 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1604070682; cv=none; d=google.com; s=arc-20160816; b=Tzz3hY+edp/IIkU4CzUQdYaKuV7PIMS+KQ2PukBG8HJ21anYr+RrQNlFTDZj6YuzJm dtzdgtpmXDHs2JZepzTURwEnvIEegTCrmQscDfwQlnY8+/USU0kxiDNCQlDBF6k6VHjZ EsUet6VdLZMZZ7cOCaDmzKmDh/ORDx81qI+s9I41gs1qVemhKaQxPh6m4oNTl2Qff4G2 CBEMqLjq89gnEZ1zRweb8gAILwSE3VqGHfWXCYztmvso88P8z2y8ovBGLENL9yR1hZbr 9BHBnYN1s6hYyJMcoPVkLMtnlsM4SLrnlwpog+BC+Io63FOdnVt9eJnYuj563fl1EvlC h0EA== 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=Mk8TOBtLAUSh5UUmmftefVTpJAKNzTPUbZbR4xmTmm4=; b=LPVXfFUKZ8cf9Cd2UyImctdR+5qx4xrXZ0iOPDj32YSVIpgMM3IluTeNN9z8Q6Qyjd WdkVXcZd3gnP4F9+q3FAfGKCDj/kY78ya9i6PhmNFQMu3Zoe0GOj4K78vmzoGut4/Iyu e3MizE+t2FNFjtT2u2qGR6BUG9rYUjF+7a4ezqVnI2MWgqKh/uUr5J4D2zfWlQSW6L54 7rEbiozy4uEnmh9rHmy7Ts3aLf6vo96NaVTkBhgKjIobjy2e9+1g7dsu3Lnd5hLRbDZE 2mJOS8MjbTeNJ8bSZLW41hs9ovo0ZiiP2xBu276e4mSHUjnItYTuvSVNl6tjZDgIpwt0 ehrw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20161025 header.b=GJxiwN9x; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id bx25si1962419ejb.270.2020.10.30.08.10.58; Fri, 30 Oct 2020 08:11:22 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@google.com header.s=20161025 header.b=GJxiwN9x; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726995AbgJ3PJ0 (ORCPT + 99 others); Fri, 30 Oct 2020 11:09:26 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:40908 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726772AbgJ3PJZ (ORCPT ); Fri, 30 Oct 2020 11:09:25 -0400 Received: from mail-lf1-x142.google.com (mail-lf1-x142.google.com [IPv6:2a00:1450:4864:20::142]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 217CFC0613D2 for ; Fri, 30 Oct 2020 08:09:25 -0700 (PDT) Received: by mail-lf1-x142.google.com with SMTP id i6so8338047lfd.1 for ; Fri, 30 Oct 2020 08:09:25 -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=Mk8TOBtLAUSh5UUmmftefVTpJAKNzTPUbZbR4xmTmm4=; b=GJxiwN9xabxRUEX1wI54H5lalSd1TYmvurtYqc/M2fA6V8U33bHNZ9KUnm+NrEFIZC Qrvcf8Oz1kmgZNU8G9hQ+3LL+ggO/PwDnFadE0BF68AW4sCZ0neyXtjFVi1hvLP2jw7o +tMXm8/POQ6ky6KAGphB5Uqn9dvqIRhiRBJegWSiGd9F0gAwKolszqsF6awnzU/IOT89 CBp89samOLM2uSJ4eB+cN7lZ/Hqu00LAQlRIY8YNBjayjS3ZLFFpVYVGo12j6uLwDEpR lWIWKskV5OFyjvLzv+TFVnFJOmKD/NODIpy3k5jGGi34kLl4uTFGiR9+v0q/Kqcx+q0W QaHA== 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=Mk8TOBtLAUSh5UUmmftefVTpJAKNzTPUbZbR4xmTmm4=; b=OposxeTuS4P6ocAz2JJDLkko9CAiR0gWuENF3I6amuEb96LM+LYYFwiMa/k3CedhR2 KrCnpSORWgU8C2kIDUtnEuS8NirLwtsQrAxlzgj/L8zkpNpc/1NJrM+zofepX6osbdBt x8cURkw9AQeBp5bGMHd1TtePAL/w739bz7VOhbewjEWCjDr3Z2ebwl0JMoTTsAQRohLc tcFIpVSF71GhKJpMGcuGIlQGJXEMZvX0sdIIq7M58EAGYY5f5/5yIWR9fmBpaoX0Iq0k HydtThY1gKIo0Km08r0SxpVFWnZ1OEdCWQCBhy0VZPWrErlSEUs26uZG8LiefMeVoe0e GPNQ== X-Gm-Message-State: AOAM533za+FZJ864ZreAZuwHWitSMKZaL/k59PoRZXQmB7EkIJvi+G68 K9ckc37HhF2iZ/G/JjxQgkQ8FsRlxFax4o8nQCN9lw== X-Received: by 2002:a05:6512:1182:: with SMTP id g2mr1077748lfr.198.1604070563207; Fri, 30 Oct 2020 08:09:23 -0700 (PDT) MIME-Version: 1.0 References: <20201029131649.182037-1-elver@google.com> <20201029131649.182037-7-elver@google.com> In-Reply-To: From: Jann Horn Date: Fri, 30 Oct 2020 16:08:56 +0100 Message-ID: Subject: Re: [PATCH v6 6/9] kfence, kasan: make KFENCE compatible with KASAN To: Marco Elver 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, 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. > I think we better add a kfence guard to > kasan_poison_shadow() as well. Sounds good.