From patchwork Mon May 28 10:02:40 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Greg KH X-Patchwork-Id: 10431027 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 E650A60249 for ; Mon, 28 May 2018 10:36:37 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id D7982289C6 for ; Mon, 28 May 2018 10:36:37 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id CBF0328C8E; Mon, 28 May 2018 10:36:37 +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 27FA3289C6 for ; Mon, 28 May 2018 10:36:37 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id AD6B06B0007; Mon, 28 May 2018 06:36:35 -0400 (EDT) Delivered-To: linux-mm-outgoing@kvack.org Received: by kanga.kvack.org (Postfix, from userid 40) id A82786B0008; Mon, 28 May 2018 06:36:35 -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 971296B000A; Mon, 28 May 2018 06:36:35 -0400 (EDT) X-Original-To: linux-mm@kvack.org X-Delivered-To: linux-mm@kvack.org Received: from mail-pg0-f72.google.com (mail-pg0-f72.google.com [74.125.83.72]) by kanga.kvack.org (Postfix) with ESMTP id 57FFD6B0007 for ; Mon, 28 May 2018 06:36:35 -0400 (EDT) Received: by mail-pg0-f72.google.com with SMTP id q71-v6so2975570pgq.17 for ; Mon, 28 May 2018 03:36:35 -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=3XNjO5ZLg/IIkwuzEABO4/VdKiwgIVj0Ytj0PdrpEoU=; b=WYRFSsj1oETtrEBUKZpLvOnpPdUmhRZb8av2gvxVKO0IJV2WqX+sT7GUTL0XEzcsaI aYW2702CG5uk5k6O8qazjM2A2zD6PueZmGtonndr0tNrkcSqXUs3UIN+eJ47mu4ZuVYv B5VfNBfnFHk5X3MK7hki8wbmXH7OhgO0yqQMrb/UDKL+tBTVrRae9dS7Y0dNbnG0FCJS ep49FeZoAqme9CLLHK9qtY76BkyJkPGG+mHnL3+vYF90CbAQkoiNYhtjXSRRk+Yq9z+E lrIIqUx9O4QUV59Usi8gObLJPeE73g9Wcj4GyQqLXmvfJ34hTuhV7hhBjmezbH5fkdMS 5UWQ== X-Gm-Message-State: ALKqPwesUTvXuaUnJrBg5qFgO75qXxrpItq7TZ0OxW6UcMFelAScriuL N8blt8uNTjB7Sm4kLWe2DMLILW3t5E5rdqve33rJXxLXEOWNQ0r1gNDVJ/M1GyX2jbqlV1fago7 sn6KlwRKL4VB25LDcjGpHsAL/ezApvBj2tcIJEpdjTmYtzgpooOO0MorV0fUtik0= X-Received: by 2002:a17:902:321:: with SMTP id 30-v6mr13018835pld.122.1527503795048; Mon, 28 May 2018 03:36:35 -0700 (PDT) X-Google-Smtp-Source: AB8JxZqa6V3YupNvHh+hhBpCY6RA9WgQVzssTQKDYYnQbxWtuUYeqdKN3dnOcFq6Y4FB0mrUCb26 X-Received: by 2002:a17:902:321:: with SMTP id 30-v6mr13018794pld.122.1527503794371; Mon, 28 May 2018 03:36:34 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1527503794; cv=none; d=google.com; s=arc-20160816; b=pczRdRvqikBOvc7E/SMTv2xBPxcAvjyNfPpM//e3eMsA4jHmCz43AR0MOMIsssQ3Gm guspsUacQKVvfEohDtq56QbsPHCDyvJOnpw4NMhbgluJuQXgmkG3TckCbjNOSQaNHLsM ypmMaIQuvo45g/IEyHjDYtcKQupUsuGAuIjTneaItF3ouHj/WLZnKX7bCiYvnpcIQqWH lnDF0Vp3Bsvnrp7hSWKRZDt2iPLgL6Sq7AXutfOX50RG5WaUCorA1y+C6oUCjSQh9kd0 5E4p2/3PG6tYsnhZrBS2qxgpfglnZrD/wr55KiGrbkrkrBO8wSay1lNmYOUDOmO9VJoq ZAog== 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=3XNjO5ZLg/IIkwuzEABO4/VdKiwgIVj0Ytj0PdrpEoU=; b=bVqa2AWCyQajotrcX/VS3XACpDRKQvDCtzm0wGecJHLiuS5zykcgMn0JPF0G3Dx/cs fRxORT+WbaeS/fAPggQ7D2i5MPtxY8XR1c4LGt8HNcBiJi2X+04R66WsX3UNcaGMs/U3 h/5Iny3WzE9z2otfNeVE5oUCG9knVpZxUhf34tt14N/vr0cJajCfdDv0+ztkU3GTUuiw 68V7ULY5wGCL7y8yclDdlJkVhgbFDbAFjpDX4kyCASiRq09z9S6mXEaV6yAW8/zPWI7r B8AGeV04ttW4jnSktKO6gzAiM/AeV6Xga/GtCsFPbMolCnaqRSM3jQn2nR1IOghXB8RV 6WxQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=gNudSAI8; 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 i26-v6si7885316pgn.433.2018.05.28.03.36.34 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 28 May 2018 03:36:34 -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=gNudSAI8; 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 55BAA208AE; Mon, 28 May 2018 10:36:33 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1527503794; bh=ZL/IUvGzxXWPTJTBinEGDSKlgM8Rs6SNe/qh+pecxAU=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=gNudSAI80A51iqyHYuXrZu9MR+rZ2FgA6aKtIRLS/46zNyfbIig5FhBWNYxzlGOeL l2heNO+26zDfarUtMO6sWNR1QDB/sRk20YNdezeNSgO5N9pv7VtIdJyIrdNsxv/zNp fCSQi7HBXKnu3zqygi+4PyBoIzZ1q3lJbxOXmGpI= 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.9 231/329] x86/mm: Do not forbid _PAGE_RW before init for __ro_after_init Date: Mon, 28 May 2018 12:02:40 +0200 Message-Id: <20180528100301.329900202@linuxfoundation.org> X-Mailer: git-send-email 2.17.0 In-Reply-To: <20180528100241.796630982@linuxfoundation.org> References: <20180528100241.796630982@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.9-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 @@ -279,9 +279,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;