Received: by 2002:a25:1506:0:0:0:0:0 with SMTP id 6csp698236ybv; Wed, 19 Feb 2020 07:27:45 -0800 (PST) X-Google-Smtp-Source: APXvYqzMenR1AS12VLNH52s3l+SE4gMc077Ae+dxNXre+GQe2S9XG1hdnBGxJuCDZxtZqvlv3E5N X-Received: by 2002:aca:b187:: with SMTP id a129mr5009234oif.175.1582126065470; Wed, 19 Feb 2020 07:27:45 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1582126065; cv=none; d=google.com; s=arc-20160816; b=wtmYXhOSZWCjIOBmJ55ma/Ww4taAr2v4QcVeLWxwBK51a2wF30iwbJGT40kOcAMWc7 3Ypuv6mLldM3obzOoQOc7+HZ7vuMfD9dyvVvFJrjJ9a+zh7vXY2ujLpb3Y7CRb6p2xSH ZMAjVQgLZ34TDENH7Ugqp6NA5oqqaoX774xY+8tdSe0YEiS7Hcpj0S6BKtW6PxhBT82A uxTqyJfN/JhxURxwjJXJFlA3nyWoU5XFpJ7AeBg+60qv3Qz+gnMkLm/cuNsHiq2+KmZl zhqJqCZ08hQxnOPC/dMsS1VbJWc5FPiow6+3zRLqNoL0xK6ai8yvmTF7Vz4luxLRztDk M4kQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:date:cc:to:subject:from:message-id :dkim-signature; bh=ANsJXuSKlChP4U6TweIOeXKVKq1C+AyTaodXPsf6gjo=; b=dvL8n7DjLAgTiZnHR9BfPojr423LjjTPk8VDkBV4VVO9W6xim6KTTF09n/VSwfJafr ifjptyD1yWdMkJB0MABz0VI7sbs2LSknIto+pbH5KfoyCqVFBVjxVEAY5NfQH9EWI03a M/DsFN49kKrV43ZfK3URP9gnNB4SyBoFeyPCr6Zkjf8vNz5dw6v0Hk/PvJMRyhskJb3o Wg9Vk39Bn1z9ooyMaBQVcrvyqOmICOOeVwweiQDlsWNuiHUgX1ewsWq/qdjz36gdBbZg 5Y2XNz+vBzQmi6AZ9vBC37/T45PoXHb+9/gTtMsiQEQTPtIAAY/ZX9qTVE8iI1fErPEN MRSg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@c-s.fr header.s=mail header.b=fdHtc56h; 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 x12si21546oto.194.2020.02.19.07.27.32; Wed, 19 Feb 2020 07:27:45 -0800 (PST) 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; dkim=pass header.i=@c-s.fr header.s=mail header.b=fdHtc56h; 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 S1727322AbgBSP0i (ORCPT + 99 others); Wed, 19 Feb 2020 10:26:38 -0500 Received: from pegase1.c-s.fr ([93.17.236.30]:51206 "EHLO pegase1.c-s.fr" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726613AbgBSP0i (ORCPT ); Wed, 19 Feb 2020 10:26:38 -0500 Received: from localhost (mailhub1-int [192.168.12.234]) by localhost (Postfix) with ESMTP id 48N1lv0SrCz9tyQn; Wed, 19 Feb 2020 16:26:35 +0100 (CET) Authentication-Results: localhost; dkim=pass reason="1024-bit key; insecure key" header.d=c-s.fr header.i=@c-s.fr header.b=fdHtc56h; dkim-adsp=pass; dkim-atps=neutral X-Virus-Scanned: Debian amavisd-new at c-s.fr Received: from pegase1.c-s.fr ([192.168.12.234]) by localhost (pegase1.c-s.fr [192.168.12.234]) (amavisd-new, port 10024) with ESMTP id jLL-SHKze0rm; Wed, 19 Feb 2020 16:26:34 +0100 (CET) Received: from messagerie.si.c-s.fr (messagerie.si.c-s.fr [192.168.25.192]) by pegase1.c-s.fr (Postfix) with ESMTP id 48N1lt58cNz9tyQm; Wed, 19 Feb 2020 16:26:34 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=c-s.fr; s=mail; t=1582125994; bh=ANsJXuSKlChP4U6TweIOeXKVKq1C+AyTaodXPsf6gjo=; h=From:Subject:To:Cc:Date:From; b=fdHtc56hE7xsF0Gd2iEvJerODfV8CbFDWZQInllNwz+HtGQH1drVpJgPaYC4wc9Ac oW0reD3L1o04zCu/1Q8TMy4gu1U9ezPTb6i/ugIWT8zdATcUKfipZdcyGoXAANoK2O +5WpvIi9VHX23EFvaOEoMv3ClEa1sySld7fFhvmg= Received: from localhost (localhost [127.0.0.1]) by messagerie.si.c-s.fr (Postfix) with ESMTP id 3E4CF8B858; Wed, 19 Feb 2020 16:26:36 +0100 (CET) X-Virus-Scanned: amavisd-new at c-s.fr Received: from messagerie.si.c-s.fr ([127.0.0.1]) by localhost (messagerie.si.c-s.fr [127.0.0.1]) (amavisd-new, port 10023) with ESMTP id KHUId65zjbJL; Wed, 19 Feb 2020 16:26:36 +0100 (CET) Received: from pc16570vm.idsi0.si.c-s.fr (po15451.idsi0.si.c-s.fr [172.25.230.102]) by messagerie.si.c-s.fr (Postfix) with ESMTP id 14B578B856; Wed, 19 Feb 2020 16:26:36 +0100 (CET) Received: by pc16570vm.idsi0.si.c-s.fr (Postfix, from userid 0) id A6EF765326; Wed, 19 Feb 2020 15:26:35 +0000 (UTC) Message-Id: From: Christophe Leroy Subject: [PATCH] powerpc/kasan: Fix shadow memory protection with CONFIG_KASAN_VMALLOC To: Benjamin Herrenschmidt , Paul Mackerras , Michael Ellerman Cc: linux-kernel@vger.kernel.org, linuxppc-dev@lists.ozlabs.org Date: Wed, 19 Feb 2020 15:26:35 +0000 (UTC) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org With CONFIG_KASAN_VMALLOC, new page tables are created at the time shadow memory for vmalloc area in unmapped. If some parts of the page table still has entries to the zero page shadow memory, the entries are wrongly marked RW. Make sure new page tables are populated with RO entries once kasan_remap_early_shadow_ro() has run. Fixes: 3d4247fcc938 ("powerpc/32: Add support of KASAN_VMALLOC") Signed-off-by: Christophe Leroy --- arch/powerpc/mm/kasan/kasan_init_32.c | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/arch/powerpc/mm/kasan/kasan_init_32.c b/arch/powerpc/mm/kasan/kasan_init_32.c index 16dd95bd0749..b533e7a8319d 100644 --- a/arch/powerpc/mm/kasan/kasan_init_32.c +++ b/arch/powerpc/mm/kasan/kasan_init_32.c @@ -30,11 +30,13 @@ static void __init kasan_populate_pte(pte_t *ptep, pgprot_t prot) __set_pte_at(&init_mm, va, ptep, pfn_pte(PHYS_PFN(pa), prot), 0); } -static int __init kasan_init_shadow_page_tables(unsigned long k_start, unsigned long k_end) +static int __init +kasan_init_shadow_page_tables(unsigned long k_start, unsigned long k_end, bool is_late) { pmd_t *pmd; unsigned long k_cur, k_next; pte_t *new = NULL; + pgprot_t prot = is_late ? kasan_prot_ro() : PAGE_KERNEL; pmd = pmd_offset(pud_offset(pgd_offset_k(k_start), k_start), k_start); @@ -48,7 +50,7 @@ static int __init kasan_init_shadow_page_tables(unsigned long k_start, unsigned if (!new) return -ENOMEM; - kasan_populate_pte(new, PAGE_KERNEL); + kasan_populate_pte(new, prot); smp_wmb(); /* See comment in __pte_alloc */ @@ -71,7 +73,7 @@ static int __init kasan_init_region(void *start, size_t size) int ret; void *block; - ret = kasan_init_shadow_page_tables(k_start, k_end); + ret = kasan_init_shadow_page_tables(k_start, k_end, false); if (ret) return ret; @@ -121,7 +123,7 @@ static void __init kasan_unmap_early_shadow_vmalloc(void) phys_addr_t pa = __pa(kasan_early_shadow_page); if (!early_mmu_has_feature(MMU_FTR_HPTE_TABLE)) { - int ret = kasan_init_shadow_page_tables(k_start, k_end); + int ret = kasan_init_shadow_page_tables(k_start, k_end, true); if (ret) panic("kasan: kasan_init_shadow_page_tables() failed"); @@ -144,7 +146,8 @@ void __init kasan_mmu_init(void) struct memblock_region *reg; if (early_mmu_has_feature(MMU_FTR_HPTE_TABLE)) { - ret = kasan_init_shadow_page_tables(KASAN_SHADOW_START, KASAN_SHADOW_END); + ret = kasan_init_shadow_page_tables(KASAN_SHADOW_START, KASAN_SHADOW_END, + false); if (ret) panic("kasan: kasan_init_shadow_page_tables() failed"); -- 2.25.0