Received: by 2002:a05:6a10:9e8c:0:0:0:0 with SMTP id y12csp1255670pxx; Fri, 30 Oct 2020 06:04:42 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxihqbAsUPM32cdWFwP13qa157tJDW2Bf9M18hJAXFI0yA86rnVRs4SzvshnoW161xeuIt0 X-Received: by 2002:a17:906:d7b9:: with SMTP id pk25mr2320252ejb.486.1604063081806; Fri, 30 Oct 2020 06:04:41 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1604063081; cv=none; d=google.com; s=arc-20160816; b=VfQtizCE0FCTGWdJixja1oWFDwt7Smurcd+S66k0NBnFlgcgLQcDtcYwAVFSs5XvnH R1vDMR6v1PU9DkRWAiWGXIToyCzsZ/IxbFi4c0GHEdncvhwNxX4u0F0ZOu2O0NjLCHQb xjS/GLx4A3SHXiSBKkeE37pWt3f0r0cfrFOhNzHN3JD+qdHT2RmtVSX7uL8ohPgMO83e 4tZ0B2++41mBr4W+RhSiw90poMixmOH5hBje2+m+8zBj8uXYK5gDJBQBwrEv0FB2pObC 7fSze841z7h3Gqp7MDKkunvGyhizGwPVAYKYQI+ccUCgMVKalGZd86/vv5Enb6o01Cbd dl2g== 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=6fvLoA2ACGsw9h6fUs2eRqYp5Vxv5mvJOqpZ7bS2dDQ=; b=qKmnkvBWp5JUdMsir9Yq/n4CrvgNaPcteYxmXVyM745LyvHMhh0pIxSy0sM6wEZyC/ thuBeBAaO7eccN5iHUK6yNMRmgVEEu+LQAtOTMChqySpGmSSVq1R2ShHT7MoV6qGkxFY MUsOPbOFvZzKffu1zxtP2fWJRaQBQfD2GWYeQZJXU55Q/6Q7Bsu1gIl+WRt8coSawZTf vdvsoM/PCTrHho01UC8tnRi/f4kB3w7wQdOjUJxOJXXGsaUqRfmjD+9WWmCRIzzuqPF7 Tznl25E48a0tQs+t80VhE5ZTGjTlZf0ZVTU6L5m/ECMa8ivHitGraabLtYvGI919X++7 dVyQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20161025 header.b=EcnjjxiP; 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 s13si4181829ejv.213.2020.10.30.06.04.16; Fri, 30 Oct 2020 06:04:41 -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=EcnjjxiP; 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 S1726224AbgJ3NAX (ORCPT + 99 others); Fri, 30 Oct 2020 09:00:23 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:48924 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725975AbgJ3NAX (ORCPT ); Fri, 30 Oct 2020 09:00:23 -0400 Received: from mail-ot1-x343.google.com (mail-ot1-x343.google.com [IPv6:2607:f8b0:4864:20::343]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id C9B13C0613D2 for ; Fri, 30 Oct 2020 06:00:22 -0700 (PDT) Received: by mail-ot1-x343.google.com with SMTP id f97so5442569otb.7 for ; Fri, 30 Oct 2020 06:00:22 -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=6fvLoA2ACGsw9h6fUs2eRqYp5Vxv5mvJOqpZ7bS2dDQ=; b=EcnjjxiP6NX5FOHbnvNYmhlYHqWJtONYAPuq8+BRYNiuIp2YO2/sOS9Osbx/2Z8fds cavi4AMu92psgd64iFC5tpy/7TL45oFgxjicTtltEsKFVUt6JXV7p81kQyb3ejUqk/EZ BlY3uE1nOqTBTw7LncwS2dhHg3Wxa2kxCH5MYvtBdvp2960pONdBmb/43b2Jd5fu6jCL PI2m8wzHjpVcycrn2PKUUwJ4Jv4DGkEDw+gaz8pqzhGls/nj8/37bYUnvxGLUdJWy4Hl PEqSbyNGilparldS8VWKLveX96xtr9BDYwGalBxqK2owNxr2aqbxS0yZ5FG4yrq3UV7S AaoQ== 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=6fvLoA2ACGsw9h6fUs2eRqYp5Vxv5mvJOqpZ7bS2dDQ=; b=jzCl3eu/BfM1Q6/4aQAWV05AMVYGetjciAXLWyHjI9godLqQMxDkHivRrQeHnxHEjJ VS+PbXW/m+Zef6sBbkJjiMNzJs2JdWwGqrC8xXbZfjUgDE16HlTgX3MjYL/AFIV835Tj kitO0uRUVySpgFhb7OiWj2/+7rT4MaBtYBan0dWfXtOrfa8sD4aHSF9FbcWnJyd5y2wc Vc80LCmd2L9YEKsgd3cyXY+XcXwp4fug0fqp6okFMsjxfxFBDRREvlpJ6NmP1VWtdWfb /zSSr2ktjcqCNRAp69owHnTGQiXX0CpTX8VOTAAwFS2LPgd60E54fT0GdH2rGfZ0toFO P/hA== X-Gm-Message-State: AOAM533kX3uUB/Qpeif1oOqP0hMf0Hs3lc812nUjVkgbT3DtDakdt5VN YXbnninH2aAUsSyWgbA9JJZE7Pbp6tqYjpY+F5M8hw== X-Received: by 2002:a9d:34d:: with SMTP id 71mr1421371otv.251.1604062821578; Fri, 30 Oct 2020 06:00:21 -0700 (PDT) MIME-Version: 1.0 References: <20201029131649.182037-1-elver@google.com> <20201029131649.182037-3-elver@google.com> In-Reply-To: From: Marco Elver Date: Fri, 30 Oct 2020 14:00:09 +0100 Message-ID: Subject: Re: [PATCH v6 2/9] x86, kfence: enable KFENCE for x86 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 , =?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" Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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; > > We can also get to this point due to an attempt to execute a data > page. That's very unlikely (given that the same thing would also crash > if you tried to do it with normal heap memory, and KFENCE allocations > are extremely rare); but we might want to try to avoid handling such > faults as KFENCE faults, since KFENCE will assume that it has resolved > the fault and retry execution of the faulting instruction. Once kernel > protection keys are introduced, those might cause the same kind of > trouble. > > So we might want to gate this on a check like "if ((error_code & > X86_PF_PROT) == 0)" (meaning "only handle the fault if the fault was > caused by no page being present", see enum x86_pf_error_code). Good point. Will fix in v7. > 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. ;-) I'll try to add a generic note to the Kconfig entry, but what you mention here seems quite x86-specific. Thanks, -- Marco