Received: by 2002:a25:ad19:0:0:0:0:0 with SMTP id y25csp10653529ybi; Thu, 11 Jul 2019 08:48:36 -0700 (PDT) X-Google-Smtp-Source: APXvYqxV6OHQXD/Vy2QV8/AO2EoQApxKU/q8XrijpLRCGJblAlLwP8ludsQu/mQmQyeGybYvLG23 X-Received: by 2002:a63:ff20:: with SMTP id k32mr5103317pgi.445.1562860116106; Thu, 11 Jul 2019 08:48:36 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1562860116; cv=none; d=google.com; s=arc-20160816; b=IdgGYSnvgp2ihz0V842suoNx4x5qq367SWHF4jzcq5waTLaobAhyjhy8MGW/48nCwq AjkNf2vvEVk+da1Im8Myjuc+vO/s5VUPEl4SUpo4+t30GZkopKjzWFZP/pqfqr8JB12x oAjjfXpHbfmQUJwyyxn0J3qOC4vklibKGrz8J1htyzqqB8yP/S3OUOXjcUPFWFWVzj+9 TwUFipsTW71cAGrEGALisfxD4ZhTvxSVfhrs4SnYBwRLVEfN/7i/zCz4jNzHnCVIm+gn LRkzqGOcRhlmJQko4BFBleVwNKlSd4ATT/rvAAjBevyDVKS+TisX93jdIhJwWysRGuO/ njyA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:in-reply-to:content-disposition :mime-version:references:message-id:subject:cc:to:from:date :dkim-signature; bh=6Y7/EmhYa6i3GEsi4Y7y5f9hDRN5qiF/ifdOoyJesEU=; b=TsfAkkQgtFvEJXpw0Jh1AV7GhYj5joce0oEHqNMTnVSDSqS16jtv30wdL6ng3nx8Fx PYzf62vBHwRy5y8mVUN8WKoAkmUP2j9UxLYpwkEw2TjDYlFS7LMYADEcth536c4VZusM SDQUt8sYhKKXcpH0Bd1YpRtY2IZYCIlPFuB/09Z6woQQalXklqvl+SoOutuzI4SmpiYD PeclCq0Vlv4p8DqDqnCwHkJ/zdhXIwNcpoSUGzBEI8modWmlwCK9ZiOJEHQVC/uMZGd+ vgv0WJpKVIBP3zOEE6aU5LyXnhp9JbSXxx/XQQ47jJJ1jrBBy0uBsGfoo90s6nQ/ZZ9m 9JFw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@chromium.org header.s=google header.b=LQSni2QX; 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 a15si5968702pfg.87.2019.07.11.08.48.15; Thu, 11 Jul 2019 08:48:36 -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=LQSni2QX; 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 S1728882AbfGKPJA (ORCPT + 99 others); Thu, 11 Jul 2019 11:09:00 -0400 Received: from mail-pl1-f195.google.com ([209.85.214.195]:41053 "EHLO mail-pl1-f195.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728474AbfGKPJA (ORCPT ); Thu, 11 Jul 2019 11:09:00 -0400 Received: by mail-pl1-f195.google.com with SMTP id m9so3167862pls.8 for ; Thu, 11 Jul 2019 08:09:00 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; h=date:from:to:cc:subject:message-id:references:mime-version :content-disposition:in-reply-to; bh=6Y7/EmhYa6i3GEsi4Y7y5f9hDRN5qiF/ifdOoyJesEU=; b=LQSni2QXLXswE/M1jbF0EOI21lueLWhC/pRwpcUKf3JlktEQ9xnYvfv0m884j88kDu xsqHchYyVuLK+mORVh1Y1kXPJC+w90SkovvGnf85vvxKir6kk8OO1QPCOuQDmJXyi6d2 OiUhDpscvaAWfWIUAIiYNc3bOwd6vjZ5oV23k= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:in-reply-to; bh=6Y7/EmhYa6i3GEsi4Y7y5f9hDRN5qiF/ifdOoyJesEU=; b=LTob9BC24Cb+L1M6Q//JlEKskAS4/JQE8xSPGFazE7L7svFrwGTKBzBnqXYs92hO83 q69JLn/qCUsEXW95mYDCOHVZcmRmZCU6FzuSqQjFy3UlGeunPMRKdObziXA7HhBhkE7s Im+4t4P34iU5uRKfHY9jAdwGtEqPNVuXU/z5RsmHnlxM6gRMGmQbqB5nQeduLHjJjF8Z A/UuWm95wpqUBsUQzWCghecnRPKIdHZsRFi9ysmnEKbc4I2iOrNebYbxZnf+TxpFgw6e MnDDgZrWgs6xFT6aGHRHuLRI+te/gAeKCbjpBvXH7Cq3xFv5qhBQ5MJlPdxM3p3fBl/X F/Zg== X-Gm-Message-State: APjAAAVoQ8sdAoWQWi1cp+peSHxtgeyMEf7qRwn0C5twJU87yZrtxKvt hLqBDdKDJP3UUiadIf9GI4b6uQ== X-Received: by 2002:a17:902:da4:: with SMTP id 33mr4748129plv.209.1562857739978; Thu, 11 Jul 2019 08:08:59 -0700 (PDT) Received: from www.outflux.net (smtp.outflux.net. [198.145.64.163]) by smtp.gmail.com with ESMTPSA id p1sm6929343pff.74.2019.07.11.08.08.58 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Thu, 11 Jul 2019 08:08:59 -0700 (PDT) Date: Thu, 11 Jul 2019 08:08:57 -0700 From: Kees Cook To: Peter Zijlstra Cc: Nadav Amit , Jiri Kosina , Xi Ruoyao , Thomas Gleixner , Linus Torvalds , Ingo Molnar , Linux List Kernel Mailing , Borislav Petkov , Len Brown , Andrew Morton , "Rafael J. Wysocki" , Tony Luck , Bob Moore , Erik Schmauss , Josh Poimboeuf , Daniel Bristot de Oliveira Subject: Re: [GIT PULL] x86/topology changes for v5.3 Message-ID: <201907110806.9C79329@keescook> References: <201907091727.91CC6C72D8@keescook> <1ad2de95e694a29909801d022fe2d556df9a4bd5.camel@mengyan1223.wang> <768463eb26a2feb0fcc374fd7f9cc28b96976917.camel@mengyan1223.wang> <20190710134433.GN3402@hirez.programming.kicks-ass.net> <89EBC357-BEAC-4252-915F-E183C2D350C4@vmware.com> <20190711080134.GT3402@hirez.programming.kicks-ass.net> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20190711080134.GT3402@hirez.programming.kicks-ass.net> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Thu, Jul 11, 2019 at 10:01:34AM +0200, Peter Zijlstra wrote: > On Thu, Jul 11, 2019 at 07:11:19AM +0000, Nadav Amit wrote: > > > On Jul 10, 2019, at 7:22 AM, Jiri Kosina wrote: > > > > > > On Wed, 10 Jul 2019, Peter Zijlstra wrote: > > > > > >> If we mark the key as RO after init, and then try and modify the key to > > >> link module usage sites, things might go bang as described. > > >> > > >> Thanks! > > >> > > >> > > >> diff --git a/arch/x86/kernel/cpu/common.c b/arch/x86/kernel/cpu/common.c > > >> index 27d7864e7252..5bf7a8354da2 100644 > > >> --- a/arch/x86/kernel/cpu/common.c > > >> +++ b/arch/x86/kernel/cpu/common.c > > >> @@ -366,7 +366,7 @@ static __always_inline void setup_umip(struct cpuinfo_x86 *c) > > >> cr4_clear_bits(X86_CR4_UMIP); > > >> } > > >> > > >> -DEFINE_STATIC_KEY_FALSE_RO(cr_pinning); > > >> +DEFINE_STATIC_KEY_FALSE(cr_pinning); > > > > > > Good catch, I guess that is going to fix it. > > > > > > At the same time though, it sort of destroys the original intent of Kees' > > > patch, right? The exploits will just have to call static_key_disable() > > > prior to calling native_write_cr4() again, and the protection is gone. > > > > Even with DEFINE_STATIC_KEY_FALSE_RO(), I presume you can just call > > set_memory_rw(), make the page that holds the key writable, and then call > > static_key_disable(), followed by a call to native_write_cr4(). > > Or call text_poke_bp() with the right set of arguments. Right -- the point is to make it defended against an arbitrary write, not arbitrary execution. Nothing is safe from arbitrary exec, but we can do our due diligence on making things read-only. -- Kees Cook