Received: by 2002:a05:6a10:22f:0:0:0:0 with SMTP id 15csp1207777pxk; Thu, 10 Sep 2020 09:32:47 -0700 (PDT) X-Google-Smtp-Source: ABdhPJydI0IrsopK7fU/LCRtZRcgl4h5WD8vEmfE77xLoXa9gDRw/GJf5FZbMFVfJ58RnA4qJAKr X-Received: by 2002:a17:906:a985:: with SMTP id jr5mr10097051ejb.549.1599755567164; Thu, 10 Sep 2020 09:32:47 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1599755567; cv=none; d=google.com; s=arc-20160816; b=zmrMAl7Di9DfoBLe89yGwZMup0pTZKNoBuVPgL2GmT9erDPRhROMw1lPKG+Ys18YEA yghEpB393wCe8qRIiOhNXlBmhW+RT+F/Meel0R+rxrfdy/aURpXYzwW2vOGgLdtHy19Y ZJIb2JV2LsAr7m2A8cAxQ1+HqlXDZ6LFBpml66d+hSL+h4bRisA0ehp4V34p//oVjr1V kNCKOCtYgP9pWijxvV5AYL9yEaX5+6W15mB7BWCW+slibrQdFRd0cp3PSYVKaG9hxafD Ujc4bGGS2ja1LQzrB4VWyovmC9nmwzFrHxNrFN3ynvIpi1unuSJjP+acWO7rjwcLt8Ma BxbA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:dkim-signature; bh=G8lEmdXJHmLOdLPgAHRWZC3Ha8HGaj35IzxQ2qyGHjk=; b=usLgeprvYYZ6bi+MT3W9LEWSCehX5gBuHNMMmrpGEVY3gSqj27ur6eAzpJzcC5gIo3 6HjUOzDvXEbhSypx6yOYDejcYUGf7iARv/9YhW1jN8rTda/nd/hrK9q4mYRnxwARDl8a WByes9jgIrRRtuqTJ0z9ZeFM4xLfDFXqDtzJ+RiVq4KseROubaRgZijzKYfxcZVAPbSp xMFhcarp/HY6a/5GcWbbGTTb9S20ytmDDFSPecItzsWij4RreuZZrfeQ9ldhiplVcQrO 4WbwD1Ozvh32I2vYfdwPdWCfsAt6PpiYS1piqqhwLj/JERjm7DKNJcR7c4Z+UFi1UkXF DWCg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20161025 header.b=cIEj1NRa; 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 k21si3951671eje.480.2020.09.10.09.32.23; Thu, 10 Sep 2020 09:32:47 -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=cIEj1NRa; 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 S1726868AbgIJQ0p (ORCPT + 99 others); Thu, 10 Sep 2020 12:26:45 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:45440 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726821AbgIJQW0 (ORCPT ); Thu, 10 Sep 2020 12:22:26 -0400 Received: from mail-oi1-x242.google.com (mail-oi1-x242.google.com [IPv6:2607:f8b0:4864:20::242]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 61A33C061795 for ; Thu, 10 Sep 2020 09:22:26 -0700 (PDT) Received: by mail-oi1-x242.google.com with SMTP id n2so6497231oij.1 for ; Thu, 10 Sep 2020 09:22:26 -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=G8lEmdXJHmLOdLPgAHRWZC3Ha8HGaj35IzxQ2qyGHjk=; b=cIEj1NRaBj3M+vU2iU5O6NxPxOz2OWM1BzVMyxB4iPiscMa9JGHXkOCcWTjuRKdQn+ WW3XmjV4GSKBqibNlmOnZMdYU1FSj7QhwWIM4h/5UvZyFxO1GuT1DC2ZsFq0IUK2urFK 2xOEYLoylWBJQlA1j2lpZSv00UpBNmW7Y1O7vtigGc8RFmSFpUQtNLAmtMH8+BCCLOfD HLUSvIKlP7HTRs8ocXFmIkKXrDHKTqU+YDL2DcPRmJ8isxfkmVK7mlxvfqUmKnQTJif1 xV8/VTAG5c5yDEDHCOjSpoYUil7R3ci2GtAoq5lF1msz4i3k3XT/em3WjQHx7Fe5Yx5E EoIg== 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=G8lEmdXJHmLOdLPgAHRWZC3Ha8HGaj35IzxQ2qyGHjk=; b=HDms5HONW5RHub+7AxsfQX7O8b09FocAyjBWBk3mjzi9qbtbYOE5ugDwU+nGGyFdjR XngiG+lFCcpyWH/0vkxag84tw8pZTwRol6Qm5KmrAvyxVVFioRDOre1blSv0RoL4qnXd hZUB1kDj+f4zh2ySggpNyd8jqrX12N/paSjjNRuOdtRCumCGTNLIVdbTYCh4HJNMYZ/s Jg6AfnsKhiFlnaZ3gdXGOAIqT3ILWZyRAFD7DTjh/g7fCZPCb+EG/R7PSsqvb25NTYwM Jc06QtwlcZflwG5AFtDh8vFTKDmBzulca9n0whmZ8cJ3lwmwKikJRz8sp1CX/nbpWTKH C6Rg== X-Gm-Message-State: AOAM531f7jVSoy0kysrNpXGjMVzqY68ZkafmvCKFbjssNKE9iXEwYwu3 m9u+OOjNfh85v9xdN/x/s/+1zKkaAagVY9ez2+vfvg== X-Received: by 2002:aca:54d1:: with SMTP id i200mr508579oib.172.1599754945387; Thu, 10 Sep 2020 09:22:25 -0700 (PDT) MIME-Version: 1.0 References: <20200907134055.2878499-1-elver@google.com> <20200907134055.2878499-2-elver@google.com> In-Reply-To: From: Marco Elver Date: Thu, 10 Sep 2020 18:22:14 +0200 Message-ID: Subject: Re: [PATCH RFC 01/10] mm: add Kernel Electric-Fence infrastructure To: Dmitry Vyukov Cc: Alexander Potapenko , Andrew Morton , Catalin Marinas , Christoph Lameter , David Rientjes , Joonsoo Kim , Mark Rutland , Pekka Enberg , "H. Peter Anvin" , "Paul E. McKenney" , Andrey Konovalov , Andrey Ryabinin , Andy Lutomirski , Borislav Petkov , Dave Hansen , Eric Dumazet , Greg Kroah-Hartman , Ingo Molnar , Jann Horn , Jonathan Corbet , Kees Cook , Peter Zijlstra , Qian Cai , Thomas Gleixner , Will Deacon , "the arch/x86 maintainers" , "open list:DOCUMENTATION" , LKML , kasan-dev , Linux ARM , Linux-MM Content-Type: text/plain; charset="UTF-8" Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Thu, 10 Sep 2020 at 17:48, Dmitry Vyukov wrote: > > On Thu, Sep 10, 2020 at 5:06 PM Marco Elver wrote: > > > On Mon, Sep 7, 2020 at 3:41 PM Marco Elver wrote: > > > > +config KFENCE_NUM_OBJECTS > > > > + int "Number of guarded objects available" > > > > + default 255 > > > > + range 1 65535 > > > > + help > > > > + The number of guarded objects available. For each KFENCE object, 2 > > > > + pages are required; with one containing the object and two adjacent > > > > + ones used as guard pages. > > > > > > Hi Marco, > > > > > > Wonder if you tested build/boot with KFENCE_NUM_OBJECTS=65535? Can a > > > compiler create such a large object? > > > > Indeed, I get a "ld: kernel image bigger than KERNEL_IMAGE_SIZE". > > Let's lower it to something more reasonable. > > > > The main reason to have the limit is to constrain random configs and > > avoid the inevitable error reports. > > > > > > +config KFENCE_FAULT_INJECTION > > > > + int "Fault injection for stress testing" > > > > + default 0 > > > > + depends on EXPERT > > > > + help > > > > + The inverse probability with which to randomly protect KFENCE object > > > > + pages, resulting in spurious use-after-frees. The main purpose of > > > > + this option is to stress-test KFENCE with concurrent error reports > > > > + and allocations/frees. A value of 0 disables fault injection. > > > > > > I would name this differently. "FAULT_INJECTION" is already taken for > > > a different thing, so it's a bit confusing. > > > KFENCE_DEBUG_SOMETHING may be a better name. > > > It would also be good to make it very clear in the short description > > > that this is for testing of KFENCE itself. When I configure syzbot I > > > routinely can't figure out if various DEBUG configs detect user > > > errors, or enable additional unit tests, or something else. > > > > Makes sense, we'll change the name. > > > > > Maybe it should depend on DEBUG_KERNEL as well? > > > > EXPERT selects DEBUG_KERNEL, so depending on DEBUG_KERNEL doesn't make sense. > > > > > > +/* > > > > + * Get the canary byte pattern for @addr. Use a pattern that varies based on the > > > > + * lower 3 bits of the address, to detect memory corruptions with higher > > > > + * probability, where similar constants are used. > > > > + */ > > > > +#define KFENCE_CANARY_PATTERN(addr) ((u8)0xaa ^ (u8)((unsigned long)addr & 0x7)) > > > > > > (addr) in macro body > > > > Done for v2. > > > > > > + seq_con_printf(seq, > > > > + "kfence-#%zd [0x" PTR_FMT "-0x" PTR_FMT > > > > > > PTR_FMT is only used in this file, should it be declared in report.c? > > > > It's also used by the test. > > > > > Please post example reports somewhere. It's hard to figure out all > > > details of the reporting/formatting. > > > > They can be seen in Documentation added later in the series (also > > viewable here: https://github.com/google/kasan/blob/kfence/Documentation/dev-tools/kfence.rst) > > > Looking at the first report. I got impression we are trying to skip > __kfence frames, but this includes it: > > kfence-#17 [0xffffffffb672f000-0xffffffffb672f01f, size=32, > cache=kmalloc-32] allocated in: > __kfence_alloc+0x42d/0x4c0 > __kmalloc+0x133/0x200 > > Is it working as intended? We're not skipping them for the allocation/free stacks. We can skip the kfence+kmalloc frame as well.