Received: by 2002:ac0:946b:0:0:0:0:0 with SMTP id j40csp3140761imj; Mon, 11 Feb 2019 14:48:25 -0800 (PST) X-Google-Smtp-Source: AHgI3IZKFBbHJ/CV/PiA+Ve6VBcpWR4TmvEq5RwnCqMOViLh3xkJ44NU0g9I8REczrvLqOzPgrVk X-Received: by 2002:a17:902:b615:: with SMTP id b21mr658784pls.338.1549925305686; Mon, 11 Feb 2019 14:48:25 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1549925305; cv=none; d=google.com; s=arc-20160816; b=EAfQ/XgG8NXa0sS5uCFhpSkueL7fxRwLLgrSIfDvfsiMXCTqfpes0OlQMo5nPpR0zC +k0osakiHQrOD/gnMTrvh8Z/1wvP9ttdYXR9hU+32lvOncTTHWDLDHlVpmDLV1MmL6PN M4REuj/WHHrWczrkVczMSQxEfdd89XXRowFPPv8m1iIOi1a4fR29GagmvEAPJBAhXvPj kWllJJJ3nQ9mYsb2FEKUdlaMe62a/ElpG6l7KMT//WpzR4qcUzk8D2KVaCPUI8FEUExL 6ZQ7lUt2UGZczYAd40+zUv93A1YDHBWJrKKmhfaUX5QEaMnkIyONFhyTZybsAIQBl0z5 BuWQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:cc:to:subject :message-id:date:from:in-reply-to:references:mime-version :dkim-signature; bh=VRgylvso3wvLBxYwgnVabpgJiWcttv3vvFjEQ4WQtSk=; b=tkSR2UReaMAoYeiODMWVrcwko46DcECjdSPC2aBhRC/DQOpxagP682F51lqZOiztgG ny+YlYPHcS7OWW+loIyrRjqfXlkVjotAMgpGulRssk7kx3YtAqXEiZ8igOUbIS+YkpHU 7GhMarbKuBjtRSGqdMbRgVD0Pao6oS7pMsOHU/HtVx1typR7Ypck48xjQ9Pnybh29zxT H/LutcC9xRhk85NGODJ65iLsnGTAFnbqGtMNBhG5jfpIXnOWfAwfg726yZaxqVZ3WJW3 NUxtiq1kNTYQasym9JtLt8GBcy/oieT+gdJOUUCyFfXZbfMZvqYI3gAqXf7u9nXjpUjm hlSQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=2qTB9vzR; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id 71si11637123plb.8.2019.02.11.14.48.09; Mon, 11 Feb 2019 14:48:25 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=2qTB9vzR; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727735AbfBKWr4 (ORCPT + 99 others); Mon, 11 Feb 2019 17:47:56 -0500 Received: from mail.kernel.org ([198.145.29.99]:36004 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727516AbfBKWr4 (ORCPT ); Mon, 11 Feb 2019 17:47:56 -0500 Received: from mail-wm1-f46.google.com (mail-wm1-f46.google.com [209.85.128.46]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 50B2A218A3 for ; Mon, 11 Feb 2019 22:47:54 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1549925274; bh=rV440hGDSZ3wXtwBOPW52PZyuO31p4qEHmRDqv7v/C0=; h=References:In-Reply-To:From:Date:Subject:To:Cc:From; b=2qTB9vzRMdPY0stzJ7/VKb/Y1Z1BstTZsqOtQo7ivCGfDJ8FmzkIxv43/rrWP4x3F yste5X5BVJeQIUceUmQ9K+mMQJ+St7Ye69qYVRSCNvV1Mc1QlgRp/BxHOMZ/iDkSXc xCzKOmorFsxK6wArhlpHajpEWC36AB/b12KduuZk= Received: by mail-wm1-f46.google.com with SMTP id q21so936697wmc.5 for ; Mon, 11 Feb 2019 14:47:54 -0800 (PST) X-Gm-Message-State: AHQUAuav0GNutMtG3Y1aHolJm/B4XTVG2zujgOpJI+g+hYODO6gb+Kzi gG17rxoY+rIgA1t9PF9fn5rW/ssyodc4Pm1AfjsGig== X-Received: by 2002:a7b:cc13:: with SMTP id f19mr353124wmh.83.1549925272767; Mon, 11 Feb 2019 14:47:52 -0800 (PST) MIME-Version: 1.0 References: <20190129003422.9328-1-rick.p.edgecombe@intel.com> <20190129003422.9328-6-rick.p.edgecombe@intel.com> <162C6C29-CD81-46FE-9A54-6ED05A93A9CB@gmail.com> <00649AE8-69C0-4CD2-A916-B8C8F0F5DAC3@amacapital.net> <6FE10C97-25FF-4E99-A96A-465CBACA935B@gmail.com> <3EA322C6-5645-4900-AEC6-97FC05716F75@gmail.com> In-Reply-To: <3EA322C6-5645-4900-AEC6-97FC05716F75@gmail.com> From: Andy Lutomirski Date: Mon, 11 Feb 2019 14:47:39 -0800 X-Gmail-Original-Message-ID: Message-ID: Subject: Re: [PATCH v2 05/20] x86/alternative: initializing temporary mm for patching To: Nadav Amit Cc: Andy Lutomirski , Rick Edgecombe , Ingo Molnar , LKML , X86 ML , "H. Peter Anvin" , Thomas Gleixner , Borislav Petkov , Dave Hansen , Peter Zijlstra , Damian Tometzki , linux-integrity , LSM List , Andrew Morton , Kernel Hardening , Linux-MM , Will Deacon , Ard Biesheuvel , Kristen Carlson Accardi , "Dock, Deneen T" , Kees Cook , Dave Hansen Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Mon, Feb 11, 2019 at 11:18 AM Nadav Amit wrote: > > > On Feb 11, 2019, at 11:07 AM, Andy Lutomirski wrote: > > > > I'm certainly amenable to other solutions, but this one does seem the > > least messy. I looked at my old patch, and it doesn't do what you > > want. I'd suggest you just add a percpu variable like cpu_dr7 and rig > > up some accessors so that it stays up to date. Then you can skip the > > dr7 writes if there are no watchpoints set. > > > > Also, EFI is probably a less interesting example than rare_write. > > With rare_write, especially the dynamically allocated variants that > > people keep coming up with, we'll need a swath of address space fully > > as large as the vmalloc area. and getting *that* right while still > > using the kernel address range might be more of a mess than we really > > want to deal with. > > As long as you feel comfortable with this solution, I=E2=80=99m fine with= it. > > Here is what I have (untested). I prefer to save/restore all the DRs, > because IIRC DR6 indications are updated even if breakpoints are disabled > (in DR7). And anyhow, that is the standard interface. Seems reasonable, but: > > > -- >8 -- > > From: Nadav Amit > Date: Mon, 11 Feb 2019 03:07:08 -0800 > Subject: [PATCH] mm: save DRs when loading temporary mm > > Signed-off-by: Nadav Amit > --- > arch/x86/include/asm/mmu_context.h | 18 ++++++++++++++++++ > 1 file changed, 18 insertions(+) > > diff --git a/arch/x86/include/asm/mmu_context.h b/arch/x86/include/asm/mm= u_context.h > index d684b954f3c0..4f92ec3df149 100644 > --- a/arch/x86/include/asm/mmu_context.h > +++ b/arch/x86/include/asm/mmu_context.h > @@ -13,6 +13,7 @@ > #include > #include > #include > +#include > > extern atomic64_t last_mm_ctx_id; > > @@ -358,6 +359,7 @@ static inline unsigned long __get_current_cr3_fast(vo= id) > > typedef struct { > struct mm_struct *prev; > + unsigned short bp_enabled : 1; > } temp_mm_state_t; > > /* > @@ -380,6 +382,15 @@ static inline temp_mm_state_t use_temporary_mm(struc= t mm_struct *mm) > lockdep_assert_irqs_disabled(); > state.prev =3D this_cpu_read(cpu_tlbstate.loaded_mm); > switch_mm_irqs_off(NULL, mm, current); > + > + /* > + * If breakpoints are enabled, disable them while the temporary m= m is > + * used - they do not belong and might cause wrong signals or cra= shes. > + */ Maybe clarify this? Add some mention that the specific problem is that user code could set a watchpoint on an address that is also used in the temporary mm. Arguably we should not disable *kernel* breakpoints a la perf, but that seems like quite a minor issue, at least as long as use_temporary_mm() doesn't get wider use. But a comment that this also disables perf breakpoints and that this could be undesirable might be in order as well.