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=-11.4 required=3.0 tests=BAYES_00,DKIMWL_WL_MED, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,USER_IN_DEF_DKIM_WL autolearn=no 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 1E0A1C43457 for ; Mon, 12 Oct 2020 14:21:15 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id D3FDE20878 for ; Mon, 12 Oct 2020 14:21:14 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="W5D1O2Lh" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2389228AbgJLOVO (ORCPT ); Mon, 12 Oct 2020 10:21:14 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:37428 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726724AbgJLOVN (ORCPT ); Mon, 12 Oct 2020 10:21:13 -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 0AEE6C0613D1 for ; Mon, 12 Oct 2020 07:21:12 -0700 (PDT) Received: by mail-oi1-x243.google.com with SMTP id m128so18860477oig.7 for ; Mon, 12 Oct 2020 07:21:12 -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=qgmtNie/zntd1O8Xi3/aeMkTtA9q5iGd/FaFCpPsSPs=; b=W5D1O2LhZGhhtUHHQ0CoKvhXXf/YejHLvjh9W17bi16WOd0iJo1QZTL1rcHvftYDMV h6XvT/lCmWVeoZLr9Tjqsc/fOiM7YbwnNwnvXem9eM/+1ZJs0pqwf/p48vjhWaDyD4CR fevht215iJjkDTi4Nl/dVbNS+ell3n3OgXOzmQQALEJPbD1Hs+2LUQ2DgtPXAcI2FXtB wvxHPK6QEYohTpdrIHAZabd9TDA5lbi7jQwcfY5cBpYSi1vec/iBwv6MfVEktJiRjr0b YdFUc251KB7K6IRHrYMSoZEFAbENaJ34qCFRqlILxCzqzjSKuJ15s+uDvLvRiavWHlIB mSIA== 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=qgmtNie/zntd1O8Xi3/aeMkTtA9q5iGd/FaFCpPsSPs=; b=h5+kem6CIi+GdvOg3DI2hdDZcnjCEpkH3QJo1r3luzqYvAylj7fFTbINAvaH/yVH00 XdxAuugFE2v9a3A6ZpisHqaeruLPmn6G8Ter+q9nccCPP2Gwm+KQoz6B0PjXXxbYTvaS BW79O8+EHmlH6rs4vNftlffAM4ZEI6Wg2kDMQwp0D20S6UZ1YdyBNGpNIEgwIYuzrtMw 9jIb6SvMYlkvF3Z5oNYxopI8qS3A+Z8ZxQPRl4XCHhqNpi+kuHXZRrWLtVGwBGqt3763 3vS5DB6IXfJwh08V6mtzrzwxSg1rp7KvQVfJUWcsSWeedreq7VCxrGH8Sjvbg5i77jlu XOVQ== X-Gm-Message-State: AOAM530vdB+gLGyQVjzv3jTojcYbwu4UGSpvjVziLU8lsfg8xP6Y927P wt2tA7BdYRqdMJkXKSHRxy9e/9su2b5A1/8ioLbevg== X-Google-Smtp-Source: ABdhPJxW8RGoOJpKn2/G8YuZtMEiJ+Fre4lLQCyuU8ImxOvZHMcKn2i477QwV30ZDV2aJL70uTEAfHUomZ6GY2lTL2g= X-Received: by 2002:a54:468f:: with SMTP id k15mr11407914oic.121.1602512471058; Mon, 12 Oct 2020 07:21:11 -0700 (PDT) MIME-Version: 1.0 References: <20200929133814.2834621-1-elver@google.com> <20200929133814.2834621-2-elver@google.com> <20201002171959.GA986344@elver.google.com> In-Reply-To: From: Marco Elver Date: Mon, 12 Oct 2020 16:20:59 +0200 Message-ID: Subject: Re: [PATCH v4 01/11] mm: add Kernel Electric-Fence infrastructure 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 , 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 , SeongJae Park Content-Type: text/plain; charset="UTF-8" Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org [ Sorry for delay, just noticed this one doesn't have a reply yet. ] On Sat, 3 Oct 2020 at 00:27, Jann Horn wrote: > On Fri, Oct 2, 2020 at 11:28 PM Marco Elver wrote: > > On Fri, 2 Oct 2020 at 21:32, Jann Horn wrote: > > > > That's another check; we don't want to make this more expensive. > > > > > > Ah, right, I missed that this is the one piece of KFENCE that is > > > actually really hot code until Dmitry pointed that out. > > > > > > But actually, can't you reduce how hot this is for SLUB by moving > > > is_kfence_address() down into the freeing slowpath? At the moment you > > > use it in slab_free_freelist_hook(), which is in the super-hot > > > fastpath, but you should be able to at least move it down into > > > __slab_free()... > > > > > > Actually, you already have hooked into __slab_free(), so can't you > > > just get rid of the check in the slab_free_freelist_hook()? > > > > I missed this bit: the loop that follows wants the free pointer, so I > > currently see how this might work. :-/ > > reverse call graph: > __slab_free > do_slab_free > slab_free > kmem_cache_free (frees a single non-kmalloc allocation) > kmem_cache_free_bulk (frees multiple) > kfree (frees a single kmalloc allocation) > ___cache_free (frees a single allocation for KASAN) > > So the only path for which we can actually loop in __slab_free() is > kmem_cache_free_bulk(); and you've already changed > build_detached_freelist() (which is used by kmem_cache_free_bulk() to > group objects from the same page) to consume KFENCE allocations before > they can ever reach __slab_free(). So we know that if we've reached > __slab_free(), then we are being called with either a single object > (which may be a KFENCE object) or with a list of objects that all > belong to the same page and don't contain any KFENCE allocations. Yes, while that is true, we still cannot execute the code in slab_free_freelist_hook(). There are several problems: - getting the freepointer which accesses object + s->offset, may result in KFENCE OOB errors. - similarly for setting the freepointer. - slab_want_init_on_free zeroing object according to memcache object_size, because it'll corrupt KFENCE's redzone if memcache object_size > actual allocation size. Leaving this here is fine, since we have determined that recent optimizations make the check in slab_free_freelist_hook() negligible. Thanks, -- Marco