Received: by 2002:ac0:a5a6:0:0:0:0:0 with SMTP id m35-v6csp4613206imm; Sat, 25 Aug 2018 22:57:41 -0700 (PDT) X-Google-Smtp-Source: ANB0VdYG7PUKGpQ/02+QfBXdj0Xu6dI5WifR2tLQ2A2rAipYOJY9frdBPtSsGhlll38gZrlFAHFS X-Received: by 2002:a17:902:1101:: with SMTP id d1-v6mr8126750pla.131.1535263060981; Sat, 25 Aug 2018 22:57:40 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1535263060; cv=none; d=google.com; s=arc-20160816; b=Bw2EDQKHY3xB9m1T4yXdz8sDfxmMmqwbkx/oBYqTVYU2A42V6PIfHntjW42p7V/xDJ +XVFYgAn6s1vopEjCVjOMz54FPF/K6Ev0E2Qyki11tuKawjDw8Ilypt3lg2RplU9k5Nj hB3k2hxAHaIv7mTBaA8+pwX4KCgMuRShZR5BK4LT/5g3KGTkxzsLL4p75ocX36son3rN 4mWskQqhJ4CIFzdwqwhPn9YGREXR8V3G8dEwEqqy0AJckhRFkJ7UOjX6Veyg3NUpUqeS JRVpVdZKS9zkf4ytYsgnxTjdT8Q3nOjMoULU+8OWqbnHFsT5m2hfz/iPpWnRjwQsFD4h I6xg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:to:references:message-id :content-transfer-encoding:cc:date:in-reply-to:from:subject :mime-version:dkim-signature:arc-authentication-results; bh=FCFtb8j9XOxXsAeacrgs4e41ka3CLAoSbaGqUsmExt8=; b=fQFepfOoKjTFZUB036wcnOHL0pqBqsz36xtxJ2TPCgBYBowbOJ1SmcuI2Tq5UhldCx aSvUKiYZU1dPz/rT9Iazk2eMn62zl1vG2N55n4Gvu2JBTtyz34iVCZA9oEZLA4/fnxCN kUtidCrTtMK+WR7tpSPKRIZo8bR7TtnC5tTPojs0h40Qt6qpaK5AilmTX3olwRNbugFz bslNJNgXuP/hivTL0EIRr3KlgXpe4CWK4xFsMGbS6ym18PgbGUywKi/0nJrwZQ3nem1X vYqilZf23PkHmK09gsVikAl/PFbuWEdiKDOHnFVzsJlnYjFtkZIK/zGNbyL7GOm1eGLa T6sQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=s2owTXQe; 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=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id d9-v6si11661496pfk.166.2018.08.25.22.56.59; Sat, 25 Aug 2018 22:57:40 -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=@gmail.com header.s=20161025 header.b=s2owTXQe; 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=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726433AbeHZJfi (ORCPT + 99 others); Sun, 26 Aug 2018 05:35:38 -0400 Received: from mail-pf1-f196.google.com ([209.85.210.196]:42254 "EHLO mail-pf1-f196.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726245AbeHZJfi (ORCPT ); Sun, 26 Aug 2018 05:35:38 -0400 Received: by mail-pf1-f196.google.com with SMTP id l9-v6so6282371pff.9 for ; Sat, 25 Aug 2018 22:54:11 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=mime-version:subject:from:in-reply-to:date:cc :content-transfer-encoding:message-id:references:to; bh=FCFtb8j9XOxXsAeacrgs4e41ka3CLAoSbaGqUsmExt8=; b=s2owTXQePiW1/A6R1wVoNuSmIus4SHmadKi/AaAtNb6NmR+y3no24jf95RpUWEGpQ6 lbpBRocwkHUTe+ueXtzhwyPQ6XmrkVTA3jESQmrBPLsCXGvfIT1eEU9WfINR29nW0FMF Uj9SXJO5RC7SEzH7tVuVZAKJYFonA7N7+U9kKhhJ2ThMgwtdft5cx57C7rP6W/Eifciu WwVSgv1ngm6CDlotIXSdlwi9p0SQdfWhc2egpFFD69i0zwvSMhL196XslwYeX5oH7oTC tE0+ONxqcgHGZJH4V3BjGFB2llKB19DpaKu94K6PcOYEToPYLMSlP2QTHDeW62Ib21YY of+Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:subject:from:in-reply-to:date:cc :content-transfer-encoding:message-id:references:to; bh=FCFtb8j9XOxXsAeacrgs4e41ka3CLAoSbaGqUsmExt8=; b=RxTSpRwU3/G4PQvpuUXX6zd4QlWfRiRJa55ERKIqFihG+p0IeYQxfYoFspJg5Ys0Y8 c9JG7AtXsQ82X8KSLt4op5Cy8nv/BFVhm5AvifetGPB9EYB5/MFFUxuAST4zOmrZYhs3 vrIhYH0BapSEJs04kfhKVTy2EOMnrzeRwOVwa6EI7CqGYgvPOk9/2dgimSh++iApLnDG QSMt/CwjLePIvp9t84gmxxADIqsWhVL6lbaUj3WBffKWMCzjY0lcwJLqO6JjnTjRPxDc c+/zHfA4U8ES8OuNMuwyTN/0/9LLO83aBpqI5zgUgWf+R3EveXl7AH0/TeIJWgLeYJC6 sblg== X-Gm-Message-State: APzg51D6dUKvS+MMBFB3qKBHIoC7YFQMjE8SHhe/LV+M/WHIWV8BDojg IWXHpoaWTTAvs2Pc1c+GJwA= X-Received: by 2002:a62:8c8c:: with SMTP id m134-v6mr8743657pfd.130.1535262851123; Sat, 25 Aug 2018 22:54:11 -0700 (PDT) Received: from ?IPv6:2601:647:4580:b719:b5ce:2cca:790b:b1c4? ([2601:647:4580:b719:b5ce:2cca:790b:b1c4]) by smtp.gmail.com with ESMTPSA id h4-v6sm12985784pgp.13.2018.08.25.22.54.09 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Sat, 25 Aug 2018 22:54:10 -0700 (PDT) Content-Type: text/plain; charset=us-ascii Mime-Version: 1.0 (Mac OS X Mail 11.5 \(3445.9.1\)) Subject: Re: TLB flushes on fixmap changes From: Nadav Amit In-Reply-To: Date: Sat, 25 Aug 2018 22:53:47 -0700 Cc: Masami Hiramatsu , 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-Transfer-Encoding: quoted-printable Message-Id: 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> To: Kees Cook , Andy Lutomirski X-Mailer: Apple Mail (2.3445.9.1) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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? >>>=20 >>> 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? >>=20 >> 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();. >>=20 >> 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. >=20 > 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=3D= kspp/write-rarely&id=3D9ab0cb2618ebbc51f830ceaa06b7d2182fe1a52d >=20 > With that, text_poke() mostly becomes: >=20 > rare_write_begin() > memcpy(addr, opcode, len); > rare_write_end() >=20 > As for juiciness, if an attacker already has execution control, they > can do more interesting things than text_poke(). But regardless, yes, > it's always made me uncomfortable. :) I think that the key to harden the security of text_poke() against its = use as a gadget in a ROP/JOP attack is to add a check/assertion for the old (expected) value, such as: rare_write_begin() if (*addr =3D=3D prev_opcode) memcpy(addr, opcode, len); rare_write_end()