From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-0.8 required=3.0 tests=HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,SPF_PASS autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id D9E8AC5CFC1 for ; Tue, 19 Jun 2018 15:54:40 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 9460620661 for ; Tue, 19 Jun 2018 15:54:40 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 9460620661 Authentication-Results: mail.kernel.org; dmarc=none (p=none dis=none) header.from=arm.com Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S966741AbeFSPyi (ORCPT ); Tue, 19 Jun 2018 11:54:38 -0400 Received: from usa-sjc-mx-foss1.foss.arm.com ([217.140.101.70]:53104 "EHLO foss.arm.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S966257AbeFSPyh (ORCPT ); Tue, 19 Jun 2018 11:54:37 -0400 Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.72.51.249]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id A1F041596; Tue, 19 Jun 2018 08:54:37 -0700 (PDT) Received: from edgewater-inn.cambridge.arm.com (usa-sjc-imap-foss1.foss.arm.com [10.72.51.249]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPA id 7361B3F557; Tue, 19 Jun 2018 08:54:37 -0700 (PDT) Received: by edgewater-inn.cambridge.arm.com (Postfix, from userid 1000) id 23F5A1AE3797; Tue, 19 Jun 2018 16:55:13 +0100 (BST) Date: Tue, 19 Jun 2018 16:55:13 +0100 From: Will Deacon To: Ard Biesheuvel Cc: YaoJun , Kernel Hardening , Catalin Marinas , linux-arm-kernel , Linux Kernel Mailing List Subject: Re: [PATCH] arm64: mm: mark tramp_pg_dir read-only Message-ID: <20180619155512.GQ13984@arm.com> References: <20180530091457.GB2452@arm.com> <20180619152035.GM13984@arm.com> <20180619152805.GN13984@arm.com> <20180619153754.GO13984@arm.com> <20180619155001.GP13984@arm.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: User-Agent: Mutt/1.5.23 (2014-03-12) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Tue, Jun 19, 2018 at 05:51:46PM +0200, Ard Biesheuvel wrote: > On 19 June 2018 at 17:50, Will Deacon wrote: > > On Tue, Jun 19, 2018 at 05:40:26PM +0200, Ard Biesheuvel wrote: > >> On 19 June 2018 at 17:37, Will Deacon wrote: > >> > On Tue, Jun 19, 2018 at 05:29:03PM +0200, Ard Biesheuvel wrote: > >> >> On 19 June 2018 at 17:28, Will Deacon wrote: > >> >> > On Tue, Jun 19, 2018 at 05:23:41PM +0200, Ard Biesheuvel wrote: > >> >> >> On 19 June 2018 at 17:20, Will Deacon wrote: > >> >> >> > On Wed, May 30, 2018 at 11:53:20AM +0200, Ard Biesheuvel wrote: > >> >> >> >> On 30 May 2018 at 11:14, Will Deacon wrote: > >> >> >> >> > On Wed, May 30, 2018 at 12:48:06PM +0800, YaoJun wrote: > >> >> >> >> >> diff --git a/arch/arm64/mm/mmu.c b/arch/arm64/mm/mmu.c > >> >> >> >> >> index 2dbb2c9f1ec1..ac4b22c7e435 100644 > >> >> >> >> >> --- a/arch/arm64/mm/mmu.c > >> >> >> >> >> +++ b/arch/arm64/mm/mmu.c > >> >> >> >> >> @@ -551,6 +551,10 @@ static int __init map_entry_trampoline(void) > >> >> >> >> >> __create_pgd_mapping(tramp_pg_dir, pa_start, TRAMP_VALIAS, PAGE_SIZE, > >> >> >> >> >> prot, pgd_pgtable_alloc, 0); > >> >> >> >> >> > >> >> >> >> >> + update_mapping_prot(__pa_symbol(tramp_pg_dir), > >> >> >> >> >> + (unsigned long)tramp_pg_dir, > >> >> >> >> >> + PGD_SIZE, PAGE_KERNEL_RO); > >> >> >> >> > > >> >> >> >> > Hmm, I like the idea but is there a risk that the page table has been mapped > >> >> >> >> > as part of a block entry, which we can't safely split at this point (i.e. > >> >> >> >> > we'll run into one of the BUG_ONs in the mapping code)? > >> >> >> >> > > >> >> >> >> > >> >> >> >> We'd need to create a separate segment for it initially so the mapping > >> >> >> >> is already at the right granularity. > >> >> >> > > >> >> >> > Why do you think that's the case? I can't see anything that guarantees this > >> >> >> > for the page table itself. > >> >> >> > > >> >> >> > >> >> >> We'd need to pass NO_BLOCK_MAPPINGS to map_kernel_segment(), > >> >> >> obviously, but that shouldn't hurt since that segment is relatively > >> >> >> tiny anyway. > >> >> > > >> >> > Ah right, with NO_BLOCK_MAPPINGS | NO_CONT_MAPPINGS, I agree that we're good. > >> >> > Ideally, we'd move {idmap,swapper,tramp}_pg_dir into .rodata... > >> >> > > >> >> > >> >> idmap and tramp yes, but swapper needs to be modifiable at runtime, no? > >> > > >> > Right, but couldn't we swizzle the permissions in e.g. set_pmd? We could > >> > even predicate that on a sanity check of the prot. > >> > > >> > >> Swizzle the permissions of the entire .rodata segment? That sounds > >> doable, but there is a whole class of data that belongs in this > >> category, and I think PaX/grsecurity had an API for that (but I don't > >> think anyone is upstreaming that yet). So let's not reinvent that > >> wheel for swapper_pg_dir only. > > > > I wasn't thinking of the whole .rodata segment -- just the page containing > > the entry being modified, but ok. > > That means we will need to map .rodata down to pages as well, or at > least avoid contiguous mappings. Doesn't it already avoid those? Will