Received: by 2002:a05:6a10:6744:0:0:0:0 with SMTP id w4csp4457818pxu; Mon, 12 Oct 2020 21:19:13 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzQOgHCYvwyiwQgCpiaD7DPrm3EpE+zYXhG8ogKnuMCeOfoSayhsc80t4048MgabOFAPRmw X-Received: by 2002:a17:906:a1d8:: with SMTP id bx24mr30564481ejb.161.1602562753001; Mon, 12 Oct 2020 21:19:13 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1602562752; cv=none; d=google.com; s=arc-20160816; b=K2rL3hERHZIqlTLYScgYEcviFvW6HrOysGuRtqzoZxeAf2RgM36E9S5Tf9nmKEQcsR tEEiIJrF1pwzK5imwYSLuR7tIHxKndLZcL9EMd779wXk561j99d07MW5rVZtE1Y6MDfm PePMCo3Ad4X7/fe9tirFTnsf9Xcr8WvYkhyoHoW9WuFxj1hcxIrBm8c1yH5VNt5tiyJU R1cRxVb8ZwShXKpc05Bt8T+25N955tpHOlLoCfPkIh3Sd3dUl4lMLDK6OV5uLYEewcpr 7VZNIRi1wSClBLz4QCL7KLGLt1sA1PB1snHQnRAc3mbYXVuSuykhmygMiW4vpUrYuOF8 kVXg== 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=qgmtNie/zntd1O8Xi3/aeMkTtA9q5iGd/FaFCpPsSPs=; b=DE6ozSKhpif/2aa4TF/DAYbUCIRzsYgACWQ6HAGCzYTd2xZtzfXwpgHd15POzbto44 HxZnAKSV1HC3aZGochVihxhkNKF2RplPUmFj6PQA9TpAGd5Swc+fbfLdIav42sUKCYwm 1KYE/4HpfP5wNLAIQ6kbxjFQ3M6GKig86j/aQQE78q1t7jl5cNL4lKwtjlTH0yIDXtVl taPoxsxwHCeSR5zAYR58PADERth6R30xOFRqo8MjWZRO/u043mRCVeV3s+qjDJp5TJUL oGxGBBb1jzj1GfMV6cuaHIbJ2iWLL4IceMvWTQmx1z/slemw6nsQw+q1LJ9nSyUqIGqD 0tpw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20161025 header.b=W5D1O2Lh; 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 z97si13830458ede.514.2020.10.12.21.18.23; Mon, 12 Oct 2020 21:19:12 -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=W5D1O2Lh; 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 S2388701AbgJLOVN (ORCPT + 99 others); Mon, 12 Oct 2020 10:21:13 -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-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