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=-16.4 required=3.0 tests=BAYES_00,DKIMWL_WL_MED, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,MENTIONS_GIT_HOSTING,SPF_HELO_NONE,SPF_PASS, USER_IN_DEF_DKIM_WL autolearn=ham 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 86B79C433E2 for ; Thu, 10 Sep 2020 16:22:28 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id EE3DB208A9 for ; Thu, 10 Sep 2020 16:22:27 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="cIEj1NRa" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org EE3DB208A9 Authentication-Results: mail.kernel.org; dmarc=fail (p=reject dis=none) header.from=google.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=owner-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix) id 55B6E6B0099; Thu, 10 Sep 2020 12:22:27 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 4E5E36B009C; Thu, 10 Sep 2020 12:22:27 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 3AD118E0005; Thu, 10 Sep 2020 12:22:27 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0024.hostedemail.com [216.40.44.24]) by kanga.kvack.org (Postfix) with ESMTP id 204F76B0099 for ; Thu, 10 Sep 2020 12:22:27 -0400 (EDT) Received: from smtpin22.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay01.hostedemail.com (Postfix) with ESMTP id DA8E1180AD811 for ; Thu, 10 Sep 2020 16:22:26 +0000 (UTC) X-FDA: 77247669492.22.screw11_41150fa270e7 Received: from filter.hostedemail.com (10.5.16.251.rfc1918.com [10.5.16.251]) by smtpin22.hostedemail.com (Postfix) with ESMTP id AB79D18038E67 for ; Thu, 10 Sep 2020 16:22:26 +0000 (UTC) X-HE-Tag: screw11_41150fa270e7 X-Filterd-Recvd-Size: 7587 Received: from mail-oi1-f193.google.com (mail-oi1-f193.google.com [209.85.167.193]) by imf14.hostedemail.com (Postfix) with ESMTP for ; Thu, 10 Sep 2020 16:22:26 +0000 (UTC) Received: by mail-oi1-f193.google.com with SMTP id 185so6447407oie.11 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=ShY2z+gYbBwW0IejLbS8YnultRkb1VaCyGeYMSnnnt/+EEUvNgKsOEYIDIKGAS0Zlo FoGqkIvJuB3mLTNMRblRNKjp5J9l2p1gb7ncZn4OvvhS3Tb9me5Uwd8l5M5qjD+D01kH RStMIE51C8VwijlXaQCTI5FQE+G04HfzRie57GcWIl5NY7LPhi7vYmRdhUm/v/K2OjiO DUoKTxMBcw51pWcqYN1wPrkcqkdRCO0qQWWMsBBPu1wJs+xAJwBiZ8GgZcR121B0DYrM MTNayLBiHIsqrm6ilONFvGVaHKREa0h4Dl76oK4Wh+zyGAQT7Jc9PqFE2UeWd8d0UmwE rC7w== X-Gm-Message-State: AOAM533nma5rBqCxAF1fOt24+u5CHM6FufH/C1t6Xq2i+0ksn4dzAZlW MkotI/noflo7EPJ63SC+McyRP8DqMNy489g6Fl7G5A== X-Google-Smtp-Source: ABdhPJzKNGteSKAUrvVsUcBoSfx3F9MALvWpVeqSzgYD6tFzAaSmto/tK7cbRNgR8Dn3g9SKOUDKEr5MqvOYL+UKHww= 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" X-Rspamd-Queue-Id: AB79D18038E67 X-Spamd-Result: default: False [0.00 / 100.00] X-Rspamd-Server: rspam05 X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: 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.