From patchwork Mon May 28 10:01:24 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Greg KH X-Patchwork-Id: 10431603 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 3DCBD60249 for ; Mon, 28 May 2018 11:07:46 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 2CD5128C10 for ; Mon, 28 May 2018 11:07:46 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 1E02A28C82; Mon, 28 May 2018 11:07:46 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-2.9 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID, MAILING_LIST_MULTI, RCVD_IN_DNSWL_NONE autolearn=ham version=3.3.1 Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 4686E28C10 for ; Mon, 28 May 2018 11:07:45 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id C8FCE6B0008; Mon, 28 May 2018 07:07:43 -0400 (EDT) Delivered-To: linux-mm-outgoing@kvack.org Received: by kanga.kvack.org (Postfix, from userid 40) id C16656B000A; Mon, 28 May 2018 07:07:43 -0400 (EDT) X-Original-To: int-list-linux-mm@kvack.org X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id ADFF56B000C; Mon, 28 May 2018 07:07:43 -0400 (EDT) X-Original-To: linux-mm@kvack.org X-Delivered-To: linux-mm@kvack.org Received: from mail-pf0-f200.google.com (mail-pf0-f200.google.com [209.85.192.200]) by kanga.kvack.org (Postfix) with ESMTP id 69CD56B0008 for ; Mon, 28 May 2018 07:07:43 -0400 (EDT) Received: by mail-pf0-f200.google.com with SMTP id p189-v6so7264096pfp.2 for ; Mon, 28 May 2018 04:07:43 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:dkim-signature:from:to:cc:subject:date :message-id:in-reply-to:references:user-agent:mime-version; bh=vv0YUWtWffwyMkIz20EAVCEe6jTKMJtg+/Jy2eiNSSY=; b=OcvTR5LVMd0oatjObEcmRUiX9KZc9jT20BTrrIljOjWLgKBHPQrQF2LtuJ0nKVnge4 V+DvKoqcSMSzsoCkcC44RV6IrQe7r6KdIiIG0+NBMFDom9V7tkjrmqac2NkVD9OXoI6B oBmM+JyCMeRb/Pu4p/NGNuxD43EzroLmdNlwyl0YFgNc5wCwpLk+Y1AbG5DkspLNTEoU T9ML6Q5GNUzHTxOXrAW3l447723POW3Tx/e1lawlBR44/AW2B2aZoxnG93gJcZilTYsr 8ZZ9DknYkdP/O48rJWILhZx7BTnFyS6uM8Ii753MMVyFwCTxJG7mzi+a7X8AUlw38m7i a2AQ== X-Gm-Message-State: ALKqPwfz5GerBYXCUFQ7j1C8g1zkIx2LZoPLWVg+Hz+iUHJPtJ005JIb l6FWa4e3DYw0pZdR1U/LNzdGcUZm02GkvXUbYwOhAu+GxJZWhSOFybZaGNbfocNAZwSD/Gs2Ap7 gcT7Fy1/6EvoNkdz1PPeC/thLxXfuf4LF9TzblA1G2xPH4LBUQM+yLyBEHN8l4QE= X-Received: by 2002:a17:902:6bc7:: with SMTP id m7-v6mr12906768plt.162.1527505663124; Mon, 28 May 2018 04:07:43 -0700 (PDT) X-Google-Smtp-Source: AB8JxZoPAx+zRlhsh0Qcymbh0HFOtckCsYYb39v/zoUfjyieHVLRrCxSOh2s2KnBQICPHs5t3GMZ X-Received: by 2002:a17:902:6bc7:: with SMTP id m7-v6mr12906741plt.162.1527505662527; Mon, 28 May 2018 04:07:42 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1527505662; cv=none; d=google.com; s=arc-20160816; b=xl2JEZId3Qpc0Y+qhO/l4huNtk2dbaRJooRzfIHE7QyUZ4Ua+93fx2st5kHNoXxgxh 6p+92YUWJoe4GWnhIGA8C6xi+bhmeJtUFMq0knvvTPn2MzK5DZ+6GHDnyUIooZc90BEP ndphCf6dv+vkmw/Fhxo+U4+I562Nu7Sugw60wDiG/xXak3V6EwrmEy6OvMAk7M5JnjMh 9MybE8bLOXTfr6DgGEPhwk7Y5uauALITso8KkdwYuqfQkB3DT+i5BTcT+93zEGcqKBPA xcB8AyEEPlMZ1NsCSr4g2IUTcP9O5F+HbE49CuDHk+Vd9uUUy2YlelOb+FD5VNeEi53J mCcg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=mime-version:user-agent:references:in-reply-to:message-id:date :subject:cc:to:from:dkim-signature:arc-authentication-results; bh=vv0YUWtWffwyMkIz20EAVCEe6jTKMJtg+/Jy2eiNSSY=; b=fqIpJ3s97jVWSRP6NMXvFCUrWX8AxMNdD4rIkf8rcIonHh5hh5cNd4vBr0glrmRNQ2 T89woquCaWqcnuTXEgSc/ODy7io00zcb1jaIEad8eONWmg7923/ByqwV4ZXwWK+RN6sn XV+pNfYIwby83/XBlo7IpRuYtRlkAzpbXnn94FwD/9CgAP5HOHA808phn/YOpVSevHjK gRJvxVKzImeKIW5dTQ3HJRaDrc0Sswdf7EhhkmkLnVTAQOgrRvkOZc6v32Cc/Y5xRXjC pmd7+rmzrSV247kyLNYRykL1c9ukj5olQxbjVUvWzwdIsuUOSbN5qw2QoIPf9ri4ITYE QBVw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=sJSfi5k4; spf=pass (google.com: domain of srs0=wbis=ip=linuxfoundation.org=gregkh@kernel.org designates 198.145.29.99 as permitted sender) smtp.mailfrom=SRS0=WbIs=IP=linuxfoundation.org=gregkh@kernel.org Received: from mail.kernel.org (mail.kernel.org. [198.145.29.99]) by mx.google.com with ESMTPS id c10-v6si7322799pla.53.2018.05.28.04.07.42 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 28 May 2018 04:07:42 -0700 (PDT) Received-SPF: pass (google.com: domain of srs0=wbis=ip=linuxfoundation.org=gregkh@kernel.org designates 198.145.29.99 as permitted sender) client-ip=198.145.29.99; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=sJSfi5k4; spf=pass (google.com: domain of srs0=wbis=ip=linuxfoundation.org=gregkh@kernel.org designates 198.145.29.99 as permitted sender) smtp.mailfrom=SRS0=WbIs=IP=linuxfoundation.org=gregkh@kernel.org Received: from localhost (LFbn-1-12247-202.w90-92.abo.wanadoo.fr [90.92.61.202]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id A747B2087E; Mon, 28 May 2018 11:07:41 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1527505662; bh=Jr5qa58DcmtDzy8SjvWzokQGPZDLlzPnSjw8UjGV4cY=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=sJSfi5k4UatqUPkfsqgRuiipLIGamVgHz66nSbcWPfTlU6ZnpcCG1dsw34Mqbc8+r 4zbVMHS4oVjHmeL9RuzpmTe9XHlyQq+za5CBEtlVoabW7pAfhD0hIoRNDzVovvERIi a7mspZAJ7ZDrPEikTxWizhuIPge7bAa8LDXtd0Qg= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Dave Hansen , Kees Cook , Andrea Arcangeli , Andy Lutomirski , Arjan van de Ven , Borislav Petkov , Dan Williams , David Woodhouse , Hugh Dickins , Josh Poimboeuf , Juergen Gross , Linus Torvalds , Nadav Amit , Peter Zijlstra , Thomas Gleixner , linux-mm@kvack.org, Ingo Molnar , Sasha Levin Subject: [PATCH 4.16 051/272] x86/mm: Do not forbid _PAGE_RW before init for __ro_after_init Date: Mon, 28 May 2018 12:01:24 +0200 Message-Id: <20180528100245.157344308@linuxfoundation.org> X-Mailer: git-send-email 2.17.0 In-Reply-To: <20180528100240.256525891@linuxfoundation.org> References: <20180528100240.256525891@linuxfoundation.org> User-Agent: quilt/0.65 X-stable: review MIME-Version: 1.0 X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: X-Virus-Scanned: ClamAV using ClamSMTP 4.16-stable review patch. If anyone has any objections, please let me know. ------------------ From: Dave Hansen [ Upstream commit 639d6aafe437a7464399d2a77d006049053df06f ] __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 Signed-off-by: Sasha Levin Signed-off-by: Greg Kroah-Hartman --- arch/x86/mm/pageattr.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) --- a/arch/x86/mm/pageattr.c +++ b/arch/x86/mm/pageattr.c @@ -298,9 +298,11 @@ static inline pgprot_t static_protection /* * 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;