Received: by 2002:a05:6a10:22f:0:0:0:0 with SMTP id 15csp1378830pxk; Fri, 2 Oct 2020 08:10:28 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxnNSLNNn3t3rwUXprHgYqzPzhkjhf/c9gRPMUQDxaEhp4vGxDMZNfvCHcuViKWrNvxEEII X-Received: by 2002:a05:6402:22b7:: with SMTP id cx23mr2921943edb.246.1601651428738; Fri, 02 Oct 2020 08:10:28 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1601651428; cv=none; d=google.com; s=arc-20160816; b=q4BgW5R1UhrK4y4oxtDVcO9GA43eomTsNXvHvPNIgyf/iVGDWeedCdsvgPQSKGn+Ar e8lCRFqheiWWXWlwt5fxxTcv1yTXOoAlBlZYMlosrn6GzUjgppXc4a9Kw8PWJv4h43Bk 3RePkjSXyEs7V0k1T6FO4doUjjboD4H2URiBSWWmb5lCnzzIfw/5W/DuPw0karEPnh7b npLFLWYgiUfUug0Cu2EYSdDpVeBR8kvMKX1gADaexEf4SdSCKjPI3CyJxTnDBs6cIv+X 4YY/sP55fQEsaXE2F6WAa5uTasgru+eiR0tgDQUGmhUr3OkGk81A2eFUj7OT1KP5TZue uarg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:content-disposition:mime-version :references:message-id:subject:cc:to:from:date; bh=aXoY4wv1t31SpFa5r7xA33qM0R5wn6W6imB4roqYL/M=; b=cg6RrVx/S1pIgFNgHMR/MoFBlsxCSgvsi3kSqXioMO28Es0tWZ6phZobRxlnT5qOUN RdLZzYInzC6pMDfSvXoOfUdeFFnPhA1Q3QBZ3Hurfv2jvKQhYtJY/l3rQzMLd7D5pLjR 90DBGWPJoIXcCXf0qsj2JbzvC1A6l7T7MINUS0x8vCE3xNX7mO9fHVjeoWRz6WWBD+TT m5qHnkeXI+pRruuq8U4GuUFPbm4UbYVhkdzWf/qMqbBlEkoy+ictKcxgo/lmIzf1Ywbc wFYAgRE/STQCbaD1e9/gGptTJgaUUrmb12iD8GTfeEWTO31St9sUsJcHEYzZpuP/s6SN hFfg== ARC-Authentication-Results: i=1; mx.google.com; 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=fail (p=NONE sp=NONE dis=NONE) header.from=arm.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id z12si1291594edm.560.2020.10.02.08.10.05; Fri, 02 Oct 2020 08:10:28 -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; 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=fail (p=NONE sp=NONE dis=NONE) header.from=arm.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2388093AbgJBPG6 (ORCPT + 99 others); Fri, 2 Oct 2020 11:06:58 -0400 Received: from foss.arm.com ([217.140.110.172]:38574 "EHLO foss.arm.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2387939AbgJBPG5 (ORCPT ); Fri, 2 Oct 2020 11:06:57 -0400 Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.121.207.14]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id B12B41396; Fri, 2 Oct 2020 08:06:56 -0700 (PDT) Received: from C02TD0UTHF1T.local (unknown [10.57.49.154]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id 45F5C3F73B; Fri, 2 Oct 2020 08:06:50 -0700 (PDT) Date: Fri, 2 Oct 2020 16:06:43 +0100 From: Mark Rutland To: Dmitry Vyukov Cc: Jann Horn , Marco Elver , 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 , Eric Dumazet , Greg Kroah-Hartman , Hillf Danton , Ingo Molnar , Jonathan.Cameron@huawei.com, Jonathan Corbet , Joonsoo Kim , Kees Cook , Pekka Enberg , Peter Zijlstra , sjpark@amazon.com, Thomas Gleixner , Vlastimil Babka , Will Deacon , the arch/x86 maintainers , "open list:DOCUMENTATION" , kernel list , kasan-dev , Linux ARM , Linux-MM , SeongJae Park Subject: Re: [PATCH v4 01/11] mm: add Kernel Electric-Fence infrastructure Message-ID: <20201002150643.GA5601@C02TD0UTHF1T.local> References: <20200929133814.2834621-1-elver@google.com> <20200929133814.2834621-2-elver@google.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Fri, Oct 02, 2020 at 04:22:59PM +0200, Dmitry Vyukov wrote: > On Fri, Oct 2, 2020 at 9:54 AM Jann Horn wrote: > > > > On Fri, Oct 2, 2020 at 8:33 AM Jann Horn wrote: > > > On Tue, Sep 29, 2020 at 3:38 PM Marco Elver wrote: > > > > This adds the Kernel Electric-Fence (KFENCE) infrastructure. KFENCE is a > > > > low-overhead sampling-based memory safety error detector of heap > > > > use-after-free, invalid-free, and out-of-bounds access errors. > > > > > > > > KFENCE is designed to be enabled in production kernels, and has near > > > > zero performance overhead. Compared to KASAN, KFENCE trades performance > > > > for precision. The main motivation behind KFENCE's design, is that with > > > > enough total uptime KFENCE will detect bugs in code paths not typically > > > > exercised by non-production test workloads. One way to quickly achieve a > > > > large enough total uptime is when the tool is deployed across a large > > > > fleet of machines. > > [...] > > > > +/* > > > > + * The pool of pages used for guard pages and objects. If supported, allocated > > > > + * statically, so that is_kfence_address() avoids a pointer load, and simply > > > > + * compares against a constant address. Assume that if KFENCE is compiled into > > > > + * the kernel, it is usually enabled, and the space is to be allocated one way > > > > + * or another. > > > > + */ > KFENCE needs the range to be covered by struct page's and that's what > creates problems for arm64. But I would assume most other users don't > need that. I've said this in a few other sub-threads, but the issue being attributed to arm64 is a red herring, and indicates a more fundamental issue that also applies to x86, which will introduce a regression for existing correctly-written code. I don't think that's acceptable for a feature expected to be deployed in production kernels, especially given that the failures are going to be non-deterministic and hard to debug. The code in question is mostly going to be in drivers, and it's very likely you may not hit it in local testing. If it is critical to avoid a pointer load here, then we need to either: * Build some infrastructure for patching constants. The x86 static_call work is vaguely the right shape for this. Then we can place the KFENCE region anywhere (e.g. within the linear/direct map), and potentially dynamically allocate it. * Go audit usage of {page,phys}_to_virt() to find any va->{page,pa}->va round-trips, and go modify that code to do something else which avoids a round-trip. When I last looked at this it didn't seem viable in general since in many cases the physcial address was the only piece of information which was retained. I'd be really curious to see how using an immediate compares to loading an __ro_after_init pointer value. Thanks, Mark.