Received: by 10.192.165.156 with SMTP id m28csp1635820imm; Thu, 12 Apr 2018 00:23:56 -0700 (PDT) X-Google-Smtp-Source: AIpwx4/B/keZ61QNZD2VYfbItjBAcb2wUwvgaTvv8ie8NAG0SQNsy3eGZaM6ObhxqsXzkP/UZI9G X-Received: by 2002:a17:902:8ec5:: with SMTP id x5-v6mr8553042plo.391.1523517836821; Thu, 12 Apr 2018 00:23:56 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1523517836; cv=none; d=google.com; s=arc-20160816; b=MRIcVc4j5Lx26RHg75k1pItTAtfMdMAnW/iWMiB5b9AuvXmfNOQBYg61OA11tt5TXz U/2fcef+89daQuUBQhetj+1vBIYC3O4vhb3xfK0mm92OXJzTUUML6E9TPRSi+Q3qR/Lx CdK6naafjaYjGniZpXTksn24mPXQezIQaa2yicjORtIE1uK0aLhTuoDqMThcC9ZvhT8F JQ4WsyqWKjC7Bro8tu36CVhvL+MKcKhuYD2WfLZbZkl08G+2nv6VSzsyoMUrAN8K1/fg 4cgFfcYYn5LRx+GBiwwp1r2DlwJOwUSb1rJ8ax0gCnUIeF7zGdX7JSC74ZG7Kn/OjYkp 07Dg== 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=TWKnpOgYTh1HgnPbnlS9gN4/w6+oBcYVUe6EO0OLiFM=; b=JKLuOy3mxdwsUtSxDBKz6cVKZCnedaOR6YdLUZ/+9iTvAfk1IsxEjepZE/p/UU+f9d pSTc/WdDI8RUS49Vy/dU1a0TGTo213TqOzDlFM9a4gfnHBBxz9pMcBmQCGfPleb2OhH8 dqc8QFUZJ9SMzLUnGvc58yhl4DrsqYb1kual0q4TL7PQELD8jiSGQnuvIJeTRCcP28Rv SKHaa7Dn7cg14OItIo8F0yxkxiVuMU9Orx07wxIEBz9OsB6W2v3ZE+LreC6NiOdSc5hn TSQXD0H+9rk6FEb+q058gdwNTmZX97FAXeA5IrX55g8yy9xz6TuO6FvtCVYPNSfx3eyz MSUA== 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 x10-v6si2713099plv.563.2018.04.12.00.23.20; Thu, 12 Apr 2018 00:23:56 -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 S1752802AbeDLHQt (ORCPT + 99 others); Thu, 12 Apr 2018 03:16:49 -0400 Received: from terminus.zytor.com ([198.137.202.136]:38919 "EHLO terminus.zytor.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752041AbeDLHQq (ORCPT ); Thu, 12 Apr 2018 03:16:46 -0400 Received: from terminus.zytor.com (localhost [127.0.0.1]) by terminus.zytor.com (8.15.2/8.15.2) with ESMTP id w3C7FT8c2970260; Thu, 12 Apr 2018 00:15:29 -0700 Received: (from tipbot@localhost) by terminus.zytor.com (8.15.2/8.15.2/Submit) id w3C7FSnG2970256; Thu, 12 Apr 2018 00:15:28 -0700 Date: Thu, 12 Apr 2018 00:15:28 -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, tglx@linutronix.de, mingo@kernel.org, bp@alien8.de, jgross@suse.com, hpa@zytor.com, dave.hansen@linux.intel.com, keescook@chromium.org, dwmw2@infradead.org, torvalds@linux-foundation.org, peterz@infradead.org, namit@vmware.com, luto@kernel.org, dan.j.williams@intel.com, hughd@google.com, arjan@linux.intel.com, gregkh@linuxfoundation.org, aarcange@redhat.com, linux-kernel@vger.kernel.org Reply-To: jpoimboe@redhat.com, mingo@kernel.org, tglx@linutronix.de, hpa@zytor.com, bp@alien8.de, jgross@suse.com, namit@vmware.com, dave.hansen@linux.intel.com, dwmw2@infradead.org, keescook@chromium.org, torvalds@linux-foundation.org, peterz@infradead.org, hughd@google.com, arjan@linux.intel.com, gregkh@linuxfoundation.org, luto@kernel.org, dan.j.williams@intel.com, aarcange@redhat.com, linux-kernel@vger.kernel.org In-Reply-To: <20180406205514.8D898241@viggo.jf.intel.com> References: <20180406205514.8D898241@viggo.jf.intel.com> To: linux-tip-commits@vger.kernel.org Subject: [tip:x86/pti] x86/mm: Do not forbid _PAGE_RW before init for __ro_after_init Git-Commit-ID: 639d6aafe437a7464399d2a77d006049053df06f 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: 639d6aafe437a7464399d2a77d006049053df06f Gitweb: https://git.kernel.org/tip/639d6aafe437a7464399d2a77d006049053df06f Author: Dave Hansen AuthorDate: Fri, 6 Apr 2018 13:55:14 -0700 Committer: Ingo Molnar CommitDate: Thu, 12 Apr 2018 09:05:59 +0200 x86/mm: Do not forbid _PAGE_RW before init for __ro_after_init __ro_after_init data gets stuck in the .rodata section. That's normally fine because the kernel itself manages the R/W properties. But, if we run __change_page_attr() on an area which is __ro_after_init, the .rodata checks will trigger and force the area to be immediately read-only, even if it is early-ish in boot. This caused problems when trying to clear the _PAGE_GLOBAL bit for these area in the PTI code: it cleared _PAGE_GLOBAL like I asked, but also took it up on itself to clear _PAGE_RW. The kernel then oopses the next time it wrote to a __ro_after_init data structure. To fix this, add the kernel_set_to_readonly check, just like we have for kernel text, just a few lines below in this function. Signed-off-by: Dave Hansen Acked-by: Kees Cook Cc: Andrea Arcangeli Cc: Andy Lutomirski Cc: Arjan van de Ven Cc: Borislav Petkov Cc: Dan Williams Cc: David Woodhouse Cc: Greg Kroah-Hartman Cc: Hugh Dickins Cc: Josh Poimboeuf Cc: Juergen Gross Cc: Linus Torvalds Cc: Nadav Amit Cc: Peter Zijlstra Cc: Thomas Gleixner Cc: linux-mm@kvack.org Link: http://lkml.kernel.org/r/20180406205514.8D898241@viggo.jf.intel.com Signed-off-by: Ingo Molnar --- arch/x86/mm/pageattr.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/arch/x86/mm/pageattr.c b/arch/x86/mm/pageattr.c index 968f51a2e39b..a7324045d87d 100644 --- a/arch/x86/mm/pageattr.c +++ b/arch/x86/mm/pageattr.c @@ -298,9 +298,11 @@ static inline pgprot_t static_protections(pgprot_t prot, unsigned long address, /* * The .rodata section needs to be read-only. Using the pfn - * catches all aliases. + * catches all aliases. This also includes __ro_after_init, + * so do not enforce until kernel_set_to_readonly is true. */ - if (within(pfn, __pa_symbol(__start_rodata) >> PAGE_SHIFT, + if (kernel_set_to_readonly && + within(pfn, __pa_symbol(__start_rodata) >> PAGE_SHIFT, __pa_symbol(__end_rodata) >> PAGE_SHIFT)) pgprot_val(forbidden) |= _PAGE_RW;