From patchwork Wed May 23 18:43:46 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Laura Abbott X-Patchwork-Id: 10422045 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 2D92160224 for ; Wed, 23 May 2018 18:44:24 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 1BAFA29160 for ; Wed, 23 May 2018 18:44:24 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 10ACB29162; Wed, 23 May 2018 18:44:24 +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 autolearn=unavailable version=3.3.1 Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id AB09529160 for ; Wed, 23 May 2018 18:44:23 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20170209; h=Sender: Content-Transfer-Encoding:Content-Type:MIME-Version:Cc:List-Subscribe: List-Help:List-Post:List-Archive:List-Unsubscribe:List-Id:Message-Id:Date: Subject:To:From:Reply-To:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:In-Reply-To: References:List-Owner; bh=b/FiN6nIuXSC5yWBi/OWyLXfakVVBbsG1euUIWFuUwQ=; b=Yys qTnzX0HLve5CMc0RKl7K8McRXM6zSfwHBGtzThJxgSGU/cD8ctDGMg/la0EV9ZPZkL/4W7RwjmywT yYu2uU1j16C3/JrcBh2usyCx1rwsJTYqottzylxkAsffY1Gl/SWcCggBDXJGLBpfz6tINYCEOwDZy 7xpuoGKtzUUHLUHfry3eJX+E1OjKCSL5+P1iNfoYukGoEfMZyD+nb0QjkmU3td6ZfHieXfsf36+ma fxClvf0AyA0i80oXYAOQ1TqsEPoW0gZAMVYcH537REK39z2N46j6doOu9ReEHFfDFZI29CFfW0VRE gChueBdxRCktmPdk0bkfl7auvcU8gCw==; Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.90_1 #2 (Red Hat Linux)) id 1fLYkE-0006qR-1i; Wed, 23 May 2018 18:44:18 +0000 Received: from mail-oi0-f67.google.com ([209.85.218.67]) by bombadil.infradead.org with esmtps (Exim 4.90_1 #2 (Red Hat Linux)) id 1fLYk9-0006op-B4 for linux-arm-kernel@lists.infradead.org; Wed, 23 May 2018 18:44:16 +0000 Received: by mail-oi0-f67.google.com with SMTP id t27-v6so20430002oij.9 for ; Wed, 23 May 2018 11:44:03 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id; bh=GkiIrWwV/0KoCm21jHfNMBbCi9VyPZeniFAs2SbJmTM=; b=IW87xq3FtbGN89F3YO4pFykADKaPvysu+xJ+xnTNex1rdwYNRG83Cqay2O/381SeKU A+CcGzX6LjPGMnydlkamigBuRNEIDyCkye84PkuG319SK6EkaKggN9uig6sEU+0vkuAe +PLQw/iphx71PcNH70BuYlcDX/FlKVT55viLUDtM5d5t/+US39bKmGiPDTK0r083sis5 b4ER9IS1RmNRP45WqVz81Nk/ebWhW9WzPPLSEZ8OePPLb9HDMZt5Y5Cr8su82jRV3Duv XtDGII9AdYDaELX0XUl7yaMh9lVYgZjGNn6JBiVMU6gz7Nop1wkKYi0fmBNKK+mvpQ2+ oANw== X-Gm-Message-State: ALKqPwexLvj5TFoi5/CCOvDWync5cRV5y+JNSD8mitpmhJVai92g5iVV QuqyGR4V7KeVh4Bq92FRoJRrPg== X-Google-Smtp-Source: AB8JxZpZ+qZrx7wkiMHWabDXp3CPD/qv8u+rzTWKsJOey5rIP0dQr21DMi0A0FefV8i+pGhj5++hcA== X-Received: by 2002:aca:4084:: with SMTP id n126-v6mr2061466oia.205.1527101042403; Wed, 23 May 2018 11:44:02 -0700 (PDT) Received: from labbott-redhat.redhat.com ([2601:602:9802:a8dc::d2dd]) by smtp.gmail.com with ESMTPSA id r37-v6sm11248689ota.10.2018.05.23.11.44.00 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Wed, 23 May 2018 11:44:01 -0700 (PDT) From: Laura Abbott To: Catalin Marinas , Will Deacon , Ard Biesheuvel Subject: [PATCHv2] arm64: Make sure permission updates happen for pmd/pud Date: Wed, 23 May 2018 11:43:46 -0700 Message-Id: <20180523184346.487-1-labbott@redhat.com> X-Mailer: git-send-email 2.17.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20180523_114413_398337_14684956 X-CRM114-Status: GOOD ( 13.89 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Peter Robinson , Laura Abbott , linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.org, Kees Cook MIME-Version: 1.0 Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org X-Virus-Scanned: ClamAV using ClamSMTP Commit 15122ee2c515 ("arm64: Enforce BBM for huge IO/VMAP mappings") disallowed block mappings for ioremap since that code does not honor break-before-make. The same APIs are also used for permission updating though and the extra checks prevent the permission updates from happening, even though this should be permitted. This results in read-only permissions not being fully applied. Visibly, this can occasionaly be seen as a failure on the built in rodata test when the test data ends up in a section or as an odd RW gap on the page table dump. Fix this by using pgattr_change_is_safe instead of p*d_present for determining if the change is permitted. Reported-by: Peter Robinson Fixes: 15122ee2c515 ("arm64: Enforce BBM for huge IO/VMAP mappings") Signed-off-by: Laura Abbott Reviewed-by: Kees Cook Tested-by: Peter Robinson --- v2: Switch to using pgattr_change_is_safe per suggestion of Will --- arch/arm64/mm/mmu.c | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/arch/arm64/mm/mmu.c b/arch/arm64/mm/mmu.c index 2dbb2c9f1ec1..493ff75670ff 100644 --- a/arch/arm64/mm/mmu.c +++ b/arch/arm64/mm/mmu.c @@ -933,13 +933,15 @@ int pud_set_huge(pud_t *pudp, phys_addr_t phys, pgprot_t prot) { pgprot_t sect_prot = __pgprot(PUD_TYPE_SECT | pgprot_val(mk_sect_prot(prot))); + pud_t new_pud = pfn_pud(__phys_to_pfn(phys), sect_prot); - /* ioremap_page_range doesn't honour BBM */ - if (pud_present(READ_ONCE(*pudp))) + /* Only allow permission changes for now */ + if (!pgattr_change_is_safe(READ_ONCE(pud_val(*pudp)), + pud_val(new_pud))) return 0; BUG_ON(phys & ~PUD_MASK); - set_pud(pudp, pfn_pud(__phys_to_pfn(phys), sect_prot)); + set_pud(pudp, new_pud); return 1; } @@ -947,13 +949,15 @@ int pmd_set_huge(pmd_t *pmdp, phys_addr_t phys, pgprot_t prot) { pgprot_t sect_prot = __pgprot(PMD_TYPE_SECT | pgprot_val(mk_sect_prot(prot))); + pmd_t new_pmd = pfn_pmd(__phys_to_pfn(phys), sect_prot); - /* ioremap_page_range doesn't honour BBM */ - if (pmd_present(READ_ONCE(*pmdp))) + /* Only allow permission changes for now */ + if (!pgattr_change_is_safe(READ_ONCE(pmd_val(*pmdp)), + pmd_val(new_pmd))) return 0; BUG_ON(phys & ~PMD_MASK); - set_pmd(pmdp, pfn_pmd(__phys_to_pfn(phys), sect_prot)); + set_pmd(pmdp, new_pmd); return 1; }