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=-17.4 required=3.0 tests=BAYES_00,DKIMWL_WL_MED, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_PATCH,MAILING_LIST_MULTI,SIGNED_OFF_BY,SPF_HELO_NONE,SPF_PASS, USER_IN_DEF_DKIM_WL autolearn=unavailable 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 A3ACFC4741F for ; Fri, 30 Oct 2020 15:22:55 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id 1A74B22246 for ; Fri, 30 Oct 2020 15:22:54 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="wU+xx2bx" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 1A74B22246 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 45C986B006E; Fri, 30 Oct 2020 11:22:54 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 40DE16B0070; Fri, 30 Oct 2020 11:22:54 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 2D79E6B0071; Fri, 30 Oct 2020 11:22:54 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0015.hostedemail.com [216.40.44.15]) by kanga.kvack.org (Postfix) with ESMTP id 027E36B006E for ; Fri, 30 Oct 2020 11:22:53 -0400 (EDT) Received: from smtpin14.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay04.hostedemail.com (Postfix) with ESMTP id 9DC592470 for ; Fri, 30 Oct 2020 15:22:53 +0000 (UTC) X-FDA: 77428959426.14.house32_3805cc027297 Received: from filter.hostedemail.com (10.5.16.251.rfc1918.com [10.5.16.251]) by smtpin14.hostedemail.com (Postfix) with ESMTP id 811D118229818 for ; Fri, 30 Oct 2020 15:22:53 +0000 (UTC) X-HE-Tag: house32_3805cc027297 X-Filterd-Recvd-Size: 6768 Received: from mail-lf1-f67.google.com (mail-lf1-f67.google.com [209.85.167.67]) by imf09.hostedemail.com (Postfix) with ESMTP for ; Fri, 30 Oct 2020 15:22:52 +0000 (UTC) Received: by mail-lf1-f67.google.com with SMTP id l2so8404855lfk.0 for ; Fri, 30 Oct 2020 08:22:52 -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=5sSkbnbDNPQyj7tIyOHf0OZ0EnyY+U+Tr7Q/pQTsliQ=; b=wU+xx2bxR8RyIDjURsVJrhnOKOfcFiQYDMWEvIaeuyW5aGNhZqWf1dtpN2n4F3NsJU HppUrs7H0lk2qIrSgTeFcNiE1h+/1/elHdKv2wBA/d3Cb+Yn/qVc5aHqDX2kTRM0FlS3 nIVVV0Oy4OkmdCIJ8AKJt8+jrvs0gfNjrKK5kQeR4X3twWg+3zGMFU4Hyzs987aPU5DC 1OTUdauKuFPZWjob1v3N8JTmx5MTcCoWOPGmX0D5W73tJhSWN3+F5ksSdNjv+Chq4veK oyNBDfrWv3q2nrzVucDlW9OJlVKLQCeMpMTrtiyse23US5OjWuYJC8Eg07Fh6gR6Kzqd NT1g== 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=5sSkbnbDNPQyj7tIyOHf0OZ0EnyY+U+Tr7Q/pQTsliQ=; b=TIsjE24khB7futF/vLHJLbTm08kVjD6WxNpa+Boah3xDYsyKHptVUJKEkQymYjGs1V sQ444q1nM1oy6vHYPSX6146zpUyznTTRYPp/SYdjS7ZaHbK9enlMQN2ZJuIi5Y5Pg+PK D7RG2jcsyEoCirQpgfHFE9L+Pady9YlE4mE766aZIv82/qFv9tv9l3V9EXJNmACjKXI6 2J3ovqUD3Hdfrv+lCEjCr1WgRzcNLtkxbjR8t5xHxrfpw7OtmGXjo6YYR/8RCHVT6IXj Wqf462/lGBSyiv/GgBYBKLM8N1qcA4DFBgoSjboEdTiQtTscJPTIbR1ODgqHkKdPvOt2 xJeA== X-Gm-Message-State: AOAM532K6iJW39B7XEwFU9lSksYUSppdKOQ/hO+q6NfYz5k43P9kD1qH DfV8rQSFEgmph2B4ol13ifVR6KgyKsC78zoc7W6G/g== X-Google-Smtp-Source: ABdhPJwLZMfK+/wKcVf/f3wxYqaH0PlYsimcp5h9RqJlxCzfH0SY3Zlp7ANGGJQDqEL2L9l6kszh99qZ39iPqxje9Z8= X-Received: by 2002:a05:6512:51a:: with SMTP id o26mr1098326lfb.381.1604071371166; Fri, 30 Oct 2020 08:22:51 -0700 (PDT) MIME-Version: 1.0 References: <20201029131649.182037-1-elver@google.com> <20201029131649.182037-3-elver@google.com> In-Reply-To: From: Jann Horn Date: Fri, 30 Oct 2020 16:22:24 +0100 Message-ID: Subject: Re: [PATCH v6 2/9] x86, kfence: enable KFENCE for x86 To: Marco Elver 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 , =?UTF-8?Q?J=C3=B6rn_Engel?= , 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 Content-Type: text/plain; charset="UTF-8" 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 Fri, Oct 30, 2020 at 2:00 PM Marco Elver wrote: > On Fri, 30 Oct 2020 at 03:49, Jann Horn wrote: > > On Thu, Oct 29, 2020 at 2:17 PM Marco Elver wrote: > > > Add architecture specific implementation details for KFENCE and enable > > > KFENCE for the x86 architecture. In particular, this implements the > > > required interface in for setting up the pool and > > > providing helper functions for protecting and unprotecting pages. > > > > > > For x86, we need to ensure that the pool uses 4K pages, which is done > > > using the set_memory_4k() helper function. > > > > > > Reviewed-by: Dmitry Vyukov > > > Co-developed-by: Marco Elver > > > Signed-off-by: Marco Elver > > > Signed-off-by: Alexander Potapenko > > [...] > > > diff --git a/arch/x86/mm/fault.c b/arch/x86/mm/fault.c > > [...] > > > @@ -725,6 +726,9 @@ no_context(struct pt_regs *regs, unsigned long error_code, > > > if (IS_ENABLED(CONFIG_EFI)) > > > efi_recover_from_page_fault(address); > > > > > > + if (kfence_handle_page_fault(address)) > > > + return; [...] > > Unrelated sidenote: Since we're hooking after exception fixup > > handling, the debug-only KFENCE_STRESS_TEST_FAULTS can probably still > > cause some behavioral differences through spurious faults in places > > like copy_user_enhanced_fast_string (where the exception table entries > > are used even if the *kernel* pointer, not the user pointer, causes a > > fault). But since KFENCE_STRESS_TEST_FAULTS is exclusively for KFENCE > > development, the difference might not matter. And ordering them the > > other way around definitely isn't possible, because the kernel relies > > on being able to fixup OOB reads. So there probably isn't really > > anything we can do better here; it's just something to keep in mind. > > Maybe you can add a little warning to the help text for that Kconfig > > entry that warns people about this? > > Thanks for pointing it out, but that option really is *only* to stress > kfence with concurrent allocations/frees/page faults. If anybody > enables this option for anything other than testing kfence, it's their > own fault. ;-) Sounds fair. :P > I'll try to add a generic note to the Kconfig entry, but what you > mention here seems quite x86-specific. (FWIW, I think it could currently also happen on arm64 in the rare cases where KERNEL_DS is used. But luckily Christoph Hellwig has already gotten rid of most places that did that.)