Received: by 2002:ac0:a5a6:0:0:0:0:0 with SMTP id m35-v6csp5062699imm; Sun, 26 Aug 2018 09:50:48 -0700 (PDT) X-Google-Smtp-Source: ANB0VdY7+4U0q2/IW23Mz7uLryzzwVGDSJOtUmUQi+8qcnJumJcMzvnfH7Z0j+IAbEGZSFNQaTzt X-Received: by 2002:a63:7107:: with SMTP id m7-v6mr9094383pgc.73.1535302248633; Sun, 26 Aug 2018 09:50:48 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1535302248; cv=none; d=google.com; s=arc-20160816; b=V9rteYUMy4dEEzx3Dc41DDzfv9/+7QNugrQDxDY19Y29NXjQrLOdaJffs7aSJZVIoe Sknb45WPPX4DY+eOUAk43NQ4CAnxw25eIVcMf4lsyscDwOisQwSKqwpP8pgdahwUa1/v lHAL0RWTu4KbcOZbs/VtlRaOUW55IVXKhGfrjHmw/VT8eT25Cbf1j9/TvS4waucsJT5t OWDckYH0NJUX61P9AUBAJigQgS8rX/6/u/UBvOH/zxzBGfBvSjwis8rLS7evJSBJ8NP2 /1D3fbZR7TUHyAwEEWRvJi3w78T/6NyTb5NdnQmXdd+1LRvW4zC69HqsOgfR4MdvanJo OZAA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:cc:to:subject:message-id:date:from :references:in-reply-to:mime-version:dkim-signature :arc-authentication-results; bh=cN2QbvzkncMY46b2rS+9Am1lLU2adDQwU4VduoWptY8=; b=XemvaE03AdVOovR/ttL6juqXeAS07DTFUvudp08Z9MUDsPkivaDFVyVd0MwRBtzC/Q 7bunJ8RIo+BwnTInqfdbVrxsa8WLueP4RO+lXGzq6Sn8LZJOBlzeGktzpfNRH4g/1ZFa X9Gp3pxXSiWMPcnhFZR3kIQ8YN5AJd00DTFSaH/sMN3SI2jOm3aSpN3ZLoV3mnp7UWb5 MP9TnT6U5sJV7w+LKyt0IvLAAlmRaNF0E1B2vLCqqY35msfhdGwUSyicAONsv/4SBMVk wLDbrVjU+pugr/WjFMaSF06nFPzB2Q/1yVJesCMKMtPdnyurbMwmmPPcUp2UTJPvakqt KmJw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@chromium.org header.s=google header.b=kuJgV64j; 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=chromium.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id f10-v6si12520535pfn.85.2018.08.26.09.50.12; Sun, 26 Aug 2018 09:50:48 -0700 (PDT) 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=@chromium.org header.s=google header.b=kuJgV64j; 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=chromium.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726785AbeHZUap (ORCPT + 99 others); Sun, 26 Aug 2018 16:30:45 -0400 Received: from mail-yw1-f68.google.com ([209.85.161.68]:43177 "EHLO mail-yw1-f68.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726611AbeHZUap (ORCPT ); Sun, 26 Aug 2018 16:30:45 -0400 Received: by mail-yw1-f68.google.com with SMTP id l189-v6so4760556ywb.10 for ; Sun, 26 Aug 2018 09:47:41 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; h=mime-version:in-reply-to:references:from:date:message-id:subject:to :cc; bh=cN2QbvzkncMY46b2rS+9Am1lLU2adDQwU4VduoWptY8=; b=kuJgV64jJlEKnLx9sVPNDAdvgfGtpE3gwVIQ7AXNDHp0yxV6STub8RRrXWWl1b3wIz JLyGXyZTAR0Y23L2tVsbqDKtpvhr6MYJHGtkEwh4KrkX9sYEK+saakbG6ShxqSPG+w7L UHkKjRuy+dll1e9L3KGt9GLj9q+e2Xh5VkoFg= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:in-reply-to:references:from:date :message-id:subject:to:cc; bh=cN2QbvzkncMY46b2rS+9Am1lLU2adDQwU4VduoWptY8=; b=B1ADH9MIqtXKdvVbMojXJ0FMoJhBwsg1CXGB078zSLSfsBkzE/6PznZujMprNZK4LW H7o5t6sJVR+5H+Ax8LILsy+f2Uvz3r8pANv+WbiBiXtnhQdmpFa7IF8EFvympBpCUrPO Vx9JbuS9CEhER+5kS9aQafj6fngvVqvPM27kgwvm0CzUv30rjqd3WD+6zDBhJsblf9U5 Y9kxvJWFXa7d/Xnm6Py7f8/FjGfyWvDzLV2I0tActZx+Pvg2cUgRk76Ip0RuHGYLpBx3 0rr2gcOS0AXY9Rk3KtIDc6OdqkkbPSoW1F306VS2jQPdN2EemBAVfZOZAnqwaHCESsI4 /3kg== X-Gm-Message-State: APzg51BqdxRtOzBDUYQ8D2lPiNrrgW65IUryPXnVdXBYiFtbUw322HCT RetqKSLLwwPAgKwlxJICtNjtv4CfuS0= X-Received: by 2002:a81:5155:: with SMTP id f82-v6mr5157929ywb.30.1535302061094; Sun, 26 Aug 2018 09:47:41 -0700 (PDT) Received: from mail-yw1-f49.google.com (mail-yw1-f49.google.com. [209.85.161.49]) by smtp.gmail.com with ESMTPSA id a129-v6sm14945703ywh.79.2018.08.26.09.47.37 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Sun, 26 Aug 2018 09:47:38 -0700 (PDT) Received: by mail-yw1-f49.google.com with SMTP id m62-v6so3275747ywd.6 for ; Sun, 26 Aug 2018 09:47:37 -0700 (PDT) X-Received: by 2002:a81:1194:: with SMTP id 142-v6mr5464486ywr.168.1535302057003; Sun, 26 Aug 2018 09:47:37 -0700 (PDT) MIME-Version: 1.0 Received: by 2002:a25:2c11:0:0:0:0:0 with HTTP; Sun, 26 Aug 2018 09:47:36 -0700 (PDT) In-Reply-To: <952A64F0-90B3-4E2F-B410-7E20BE90D617@amacapital.net> References: <20180822153012.173508681@infradead.org> <20180822154046.823850812@infradead.org> <20180822155527.GF24124@hirez.programming.kicks-ass.net> <20180823134525.5f12b0d3@roar.ozlabs.ibm.com> <776104d4c8e4fc680004d69e3a4c2594b638b6d1.camel@au1.ibm.com> <20180823133958.GA1496@brain-police> <20180824084717.GK24124@hirez.programming.kicks-ass.net> <20180824180438.GS24124@hirez.programming.kicks-ass.net> <56A9902F-44BE-4520-A17C-26650FCC3A11@gmail.com> <9A38D3F4-2F75-401D-8B4D-83A844C9061B@gmail.com> <8E0D8C66-6F21-4890-8984-B6B3082D4CC5@gmail.com> <20180826112341.f77a528763e297cbc36058fa@kernel.org> <952A64F0-90B3-4E2F-B410-7E20BE90D617@amacapital.net> From: Kees Cook Date: Sun, 26 Aug 2018 09:47:36 -0700 X-Gmail-Original-Message-ID: Message-ID: Subject: Re: TLB flushes on fixmap changes To: Andy Lutomirski Cc: Andy Lutomirski , Masami Hiramatsu , Nadav Amit , Linus Torvalds , Paolo Bonzini , Jiri Kosina , Peter Zijlstra , Will Deacon , Benjamin Herrenschmidt , Nick Piggin , "the arch/x86 maintainers" , Borislav Petkov , Rik van Riel , Jann Horn , Adin Scannell , Dave Hansen , Linux Kernel Mailing List , linux-mm , David Miller , Martin Schwidefsky , Michael Ellerman Content-Type: text/plain; charset="UTF-8" Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Sun, Aug 26, 2018 at 7:20 AM, Andy Lutomirski wrote: > > >> On Aug 25, 2018, at 9:43 PM, Kees Cook wrote: >> >>> On Sat, Aug 25, 2018 at 9:21 PM, Andy Lutomirski wrote: >>>> On Sat, Aug 25, 2018 at 7:23 PM, Masami Hiramatsu wrote: >>>> On Fri, 24 Aug 2018 21:23:26 -0700 >>>> Andy Lutomirski wrote: >>>>> Couldn't text_poke() use kmap_atomic()? Or, even better, just change CR3? >>>> >>>> No, since kmap_atomic() is only for x86_32 and highmem support kernel. >>>> In x86-64, it seems that returns just a page address. That is not >>>> good for text_poke, since it needs to make a writable alias for RO >>>> code page. Hmm, maybe, can we mimic copy_oldmem_page(), it uses ioremap_cache? >>>> >>> >>> I just re-read text_poke(). It's, um, horrible. Not only is the >>> implementation overcomplicated and probably buggy, but it's SLOOOOOW. >>> It's totally the wrong API -- poking one instruction at a time >>> basically can't be efficient on x86. The API should either poke lots >>> of instructions at once or should be text_poke_begin(); ...; >>> text_poke_end();. >>> >>> Anyway, the attached patch seems to boot. Linus, Kees, etc: is this >>> too scary of an approach? With the patch applied, text_poke() is a >>> fantastic exploit target. On the other hand, even without the patch >>> applied, text_poke() is every bit as juicy. >> >> I tried to convince Ingo to use this method for doing "write rarely" >> and he soundly rejected it. :) I've always liked this because AFAICT, >> it's local to the CPU. I had proposed it in >> https://git.kernel.org/pub/scm/linux/kernel/git/kees/linux.git/commit/?h=kspp/write-rarely&id=9ab0cb2618ebbc51f830ceaa06b7d2182fe1a52d > > Ingo, can you clarify why you hate it? I personally would rather use CR3, but CR0 seems like a fine first step, at least for text_poke. Sorry, it looks like it was tglx, not Ingo: https://lkml.kernel.org/r/alpine.DEB.2.20.1704071048360.1716@nanos This thread is long, and one thing that I think went unanswered was "why do we want this to be fast?" the answer is: for doing page table updates. Page tables are becoming a bigger target for attacks now, and it's be nice if they could stay read-only unless they're getting updated (with something like this). -Kees -- Kees Cook Pixel Security