Received: by 10.192.165.148 with SMTP id m20csp452058imm; Wed, 25 Apr 2018 02:11:51 -0700 (PDT) X-Google-Smtp-Source: AIpwx49oC5zAQTSqSMoMUWxjDkMjr/tZv6c7XL5VUMcX7/mje99JwpD1EBGMY5uvMcMuGND1dubr X-Received: by 10.98.83.199 with SMTP id h190mr27186878pfb.146.1524647511612; Wed, 25 Apr 2018 02:11:51 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1524647511; cv=none; d=google.com; s=arc-20160816; b=CyLaT3HuLX5WiFFes2NkkQcSr9gvmCk0ED/YSYIdzTMzwfM+WatorCGaCFl8knQCQw w94Cf8J4nHs9GKfMkb/WKOGZ2z9gkFCZJkp3LW5FhAeumJOR+9cjOcuMDrdP4jBB1BW+ RxBcrC/CpZEQbyvu/OHBalbxiHVY6G4frgyYMtF0NhbqQoxE57cdN3X9h7RkFndk7aFV jDsTBnOsMbOLV9ejaXFRk50Fpg8v6htkjfDdbWsIFDhzTVi9x3+JqH6bghfSW4+OFSmN HwX7cEps0JUJQp4bkPx05eIHcNB3T6lPoCOOVtPFBO6jJUhamkjGabaxv3iO27Misg0V Ky9Q== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-disposition :content-transfer-encoding:mime-version:robot-unsubscribe:robot-id :git-commit-id:subject:to:references:in-reply-to:reply-to:cc :message-id:from:date:arc-authentication-results; bh=AVSV9IZ4lDz9L3tclmyzWB1GeE82qoSdE3YNjjDWz8I=; b=zohjMR1B0ZXgixqMfD1JHwXm2kaNpkVRnkMOGYvO+sKaWWAB/W3IsMgGIkNJzgHGkI /D3MQsmARgKv5RFQtfLjNRu8yY44r01mFwMvHD995iL5mMjdj53Af8dvw8MFDyovAT7L dv9kMCDeQfQYwnFKoWrgiMJiFE5DYL6l6keqdJkpS6I5OmK/SOukubpgl31C0h8vVnPg h2adL71Ouu3Vv9OhgfOgQD12jXJfVhDrRnbX1Jb/BCqrypuEMtiVN5dhWlsrDqpx7qmm 7oNJpC1VVnaImXn0QLMbWHQDNp9mm1QyLrl5cS1LJj9+oxt4bPg5NHaZLtiISaCogJpp V5kQ== ARC-Authentication-Results: i=1; mx.google.com; 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 Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id g185si13190257pgc.155.2018.04.25.02.11.37; Wed, 25 Apr 2018 02:11:51 -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; 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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751544AbeDYJI6 (ORCPT + 99 others); Wed, 25 Apr 2018 05:08:58 -0400 Received: from terminus.zytor.com ([198.137.202.136]:55347 "EHLO terminus.zytor.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1750969AbeDYJI4 (ORCPT ); Wed, 25 Apr 2018 05:08:56 -0400 Received: from terminus.zytor.com (localhost [127.0.0.1]) by terminus.zytor.com (8.15.2/8.15.2) with ESMTP id w3P982p71423833; Wed, 25 Apr 2018 02:08:02 -0700 Received: (from tipbot@localhost) by terminus.zytor.com (8.15.2/8.15.2/Submit) id w3P982Td1423830; Wed, 25 Apr 2018 02:08:02 -0700 Date: Wed, 25 Apr 2018 02:08:02 -0700 X-Authentication-Warning: terminus.zytor.com: tipbot set sender to tipbot@zytor.com using -f From: tip-bot for Dave Hansen Message-ID: Cc: jpoimboe@redhat.com, gregkh@linuxfoundation.org, torvalds@linux-foundation.org, hughd@google.com, bp@alien8.de, arjan@linux.intel.com, luto@kernel.org, aarcange@redhat.com, tglx@linutronix.de, jgross@suse.com, keescook@google.com, dave.hansen@linux.intel.com, hpa@zytor.com, linux-kernel@vger.kernel.org, dwmw2@infradead.org, namit@vmware.com, peterz@infradead.org, dan.j.williams@intel.com, mingo@kernel.org Reply-To: aarcange@redhat.com, luto@kernel.org, arjan@linux.intel.com, bp@alien8.de, hughd@google.com, torvalds@linux-foundation.org, gregkh@linuxfoundation.org, jpoimboe@redhat.com, mingo@kernel.org, peterz@infradead.org, dan.j.williams@intel.com, dwmw2@infradead.org, namit@vmware.com, hpa@zytor.com, linux-kernel@vger.kernel.org, keescook@google.com, dave.hansen@linux.intel.com, jgross@suse.com, tglx@linutronix.de In-Reply-To: <20180420222023.1C8B2B20@viggo.jf.intel.com> References: <20180420222023.1C8B2B20@viggo.jf.intel.com> To: linux-tip-commits@vger.kernel.org Subject: [tip:x86/pti] x86/pti: Reduce amount of kernel text allowed to be Global Git-Commit-ID: a44ca8f5a30c008b54d07b00eed4eae7f169fcd0 X-Mailer: tip-git-log-daemon Robot-ID: Robot-Unsubscribe: Contact to get blacklisted from these emails MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Content-Type: text/plain; charset=UTF-8 Content-Disposition: inline X-Spam-Status: No, score=-2.9 required=5.0 tests=ALL_TRUSTED,BAYES_00 autolearn=ham autolearn_force=no version=3.4.1 X-Spam-Checker-Version: SpamAssassin 3.4.1 (2015-04-28) on terminus.zytor.com Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Commit-ID: a44ca8f5a30c008b54d07b00eed4eae7f169fcd0 Gitweb: https://git.kernel.org/tip/a44ca8f5a30c008b54d07b00eed4eae7f169fcd0 Author: Dave Hansen AuthorDate: Fri, 20 Apr 2018 15:20:23 -0700 Committer: Thomas Gleixner CommitDate: Wed, 25 Apr 2018 11:02:50 +0200 x86/pti: Reduce amount of kernel text allowed to be Global commit abb67605203687c8b7943d760638d0301787f8d9 Kees reported to me that I made too much of the kernel image global. It was far more than just text: I think this is too much set global: _end is after data, bss, and brk, and all kinds of other stuff that could hold secrets. I think this should match what mark_rodata_ro() is doing. This does exactly that. We use __end_rodata_hpage_align as our marker both because it is huge-page-aligned and it does not contain any sections we expect to hold secrets. Kees's logic was that r/o data is in the kernel image anyway and, in the case of traditional distributions, can be freely downloaded from the web, so there's no reason to hide it. Fixes: 8c06c7740 (x86/pti: Leave kernel text global for !PCID) Reported-by: Kees Cook Signed-off-by: Dave Hansen Signed-off-by: Thomas Gleixner Acked-by: Ingo Molnar Cc: Andrea Arcangeli Cc: Juergen Gross Cc: Josh Poimboeuf Cc: Greg Kroah-Hartman Cc: Peter Zijlstra Cc: David Woodhouse Cc: Hugh Dickins Cc: linux-mm@kvack.org Cc: Linus Torvalds Cc: Borislav Petkov Cc: Andy Lutomirski Cc: Nadav Amit Cc: Dan Williams Cc: Arjan van de Ven Link: https://lkml.kernel.org/r/20180420222023.1C8B2B20@viggo.jf.intel.com --- arch/x86/mm/pti.c | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/arch/x86/mm/pti.c b/arch/x86/mm/pti.c index f1fd52f449e0..ae3eb4f5d53b 100644 --- a/arch/x86/mm/pti.c +++ b/arch/x86/mm/pti.c @@ -430,12 +430,24 @@ static inline bool pti_kernel_image_global_ok(void) */ void pti_clone_kernel_text(void) { + /* + * rodata is part of the kernel image and is normally + * readable on the filesystem or on the web. But, do not + * clone the areas past rodata, they might contain secrets. + */ unsigned long start = PFN_ALIGN(_text); - unsigned long end = ALIGN((unsigned long)_end, PMD_PAGE_SIZE); + unsigned long end = (unsigned long)__end_rodata_hpage_align; if (!pti_kernel_image_global_ok()) return; + pr_debug("mapping partial kernel image into user address space\n"); + + /* + * Note that this will undo _some_ of the work that + * pti_set_kernel_image_nonglobal() did to clear the + * global bit. + */ pti_clone_pmds(start, end, _PAGE_RW); } @@ -458,8 +470,6 @@ void pti_set_kernel_image_nonglobal(void) if (pti_kernel_image_global_ok()) return; - pr_debug("set kernel image non-global\n"); - set_memory_nonglobal(start, (end - start) >> PAGE_SHIFT); }