From patchwork Tue May 29 04:37:54 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jun Yao X-Patchwork-Id: 10434719 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 32541602BF for ; Tue, 29 May 2018 09:59:43 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 24B4D286B9 for ; Tue, 29 May 2018 09:59:43 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 17D1C286BE; Tue, 29 May 2018 09:59:43 +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=-5.3 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, FREEMAIL_FROM, MAILING_LIST_MULTI, RCVD_IN_DNSWL_MED autolearn=ham version=3.3.1 Received: from mother.openwall.net (mother.openwall.net [195.42.179.200]) by mail.wl.linuxfoundation.org (Postfix) with SMTP id 44BDD286B9 for ; Tue, 29 May 2018 09:59:42 +0000 (UTC) Received: (qmail 31816 invoked by uid 550); 29 May 2018 09:59:29 -0000 Mailing-List: contact kernel-hardening-help@lists.openwall.com; run by ezmlm Precedence: bulk List-Post: List-Help: List-Unsubscribe: List-Subscribe: List-ID: Delivered-To: mailing list kernel-hardening@lists.openwall.com Delivered-To: moderator for kernel-hardening@lists.openwall.com Received: (qmail 19541 invoked from network); 29 May 2018 04:38:12 -0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id; bh=cCu8iud5l5CG5FG06jT517gkB7592tYzg+NC/f1m0rM=; b=Fo1pQZTX57uI7/IyGBFUzefDisY4b4clyzgkJTsu3ArbTShWJRl4K7Cy+Q3VO6iag9 Q/AtT1WjF0lLrumc9wzpVrvJcsGmrafDXpgNGavGuaKQVVa55SNGYgY2FVApXq3iPdby qBguo4OwJI3HKkMf+n5UBclTF+bBcYgBC+npjdXjSYzoWGWeq8NMM+HNxEpD2an52E5S lqh+qPQORDy7KOH/dOnfV2MuELA9eWuua+iRQsNYNMbtoYupxJm4ywkzT1DzvReR1mrm IUFJ1tuG5C2jXZGLVrS9UmFKxG3SSDA0CRs94m9sSeWilEnNqYmIOG2CcyGRBMrvssYy 9+Mg== 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=cCu8iud5l5CG5FG06jT517gkB7592tYzg+NC/f1m0rM=; b=HlrxzFQI8fEjcAdi5lLTNlqBdaOqfpVTA6avq9tM47MQcx8y+mwXsdEEub2mHiG/zh MYAXA6acKug9FjYecmAevgev0OzjN4vTtkNlYM/HU/5GwLhmWt3vvoSRE0JiigPISRfg yAarulBfLxqC/e8DPLYvj3FiA86I5Dsd3Vlrrfe0jxhbqzunp3nVtO5Njw95y/FC/CEJ fXP9iEWw17g56KbKNTWIrOz+tg0THupziX0z9helU9w7IeAd3FRz17SnR+7xaQmYb2eh 8OctvFaxpJeGuezKXU2Fhz/yM9Ea6ZKE36rzakQr73w3k4VlNvPioE2l1FqnJf2jdhZN EaEQ== X-Gm-Message-State: ALKqPwf5ghixNhwOvvYVvRVJyT138SwhnPLmmf1P8p57lGHbs7GbC5Ma F7ARRYffAvCPgPzoxIhWwu7QzA== X-Google-Smtp-Source: ADUXVKKfcKuikrhJ/PjJLTBgbVjrov9LmJalFk2zAsaeb/WUdtjv0CHyvaqSgOd385nUoBpkdb+N6A== X-Received: by 2002:a17:902:d716:: with SMTP id w22-v6mr288853ply.98.1527568680793; Mon, 28 May 2018 21:38:00 -0700 (PDT) From: YaoJun To: kernel-hardening@lists.openwall.com Cc: linux-kernel@vger.kernel.org, linux-security-module@vger.kernel.org, jmorris@namei.org Subject: [PATCH 2/4] migrate swapper_pg_dir Date: Tue, 29 May 2018 12:37:54 +0800 Message-Id: <20180529043754.27843-1-yaojun8558363@gmail.com> X-Mailer: git-send-email 2.17.0 X-Virus-Scanned: ClamAV using ClamSMTP Introduce a variable to record new virtual address of swapper_pg_dir. --- arch/arm64/include/asm/mmu_context.h | 2 +- arch/arm64/include/asm/pgtable.h | 1 + arch/arm64/mm/kasan_init.c | 2 +- arch/arm64/mm/mmu.c | 1 + 4 files changed, 4 insertions(+), 2 deletions(-) diff --git a/arch/arm64/include/asm/mmu_context.h b/arch/arm64/include/asm/mmu_context.h index 3eddb871f251..481c2d16adeb 100644 --- a/arch/arm64/include/asm/mmu_context.h +++ b/arch/arm64/include/asm/mmu_context.h @@ -57,7 +57,7 @@ static inline void cpu_set_reserved_ttbr0(void) static inline void cpu_switch_mm(pgd_t *pgd, struct mm_struct *mm) { - BUG_ON(pgd == swapper_pg_dir); + BUG_ON(pgd == new_swapper_pg_dir); cpu_set_reserved_ttbr0(); cpu_do_switch_mm(virt_to_phys(pgd),mm); } diff --git a/arch/arm64/include/asm/pgtable.h b/arch/arm64/include/asm/pgtable.h index 14ba344b1af7..7abec25cedd2 100644 --- a/arch/arm64/include/asm/pgtable.h +++ b/arch/arm64/include/asm/pgtable.h @@ -723,6 +723,7 @@ extern pgd_t swapper_pg_end[]; extern pgd_t idmap_pg_dir[PTRS_PER_PGD]; extern pgd_t tramp_pg_dir[PTRS_PER_PGD]; extern phys_addr_t __pa_swapper_pg_dir; +extern pgd_t *new_swapper_pg_dir; /* * Encode and decode a swap entry: diff --git a/arch/arm64/mm/kasan_init.c b/arch/arm64/mm/kasan_init.c index dd4f28c19165..08bcaae4725e 100644 --- a/arch/arm64/mm/kasan_init.c +++ b/arch/arm64/mm/kasan_init.c @@ -197,7 +197,7 @@ void __init kasan_init(void) * tmp_pg_dir used to keep early shadow mapped until full shadow * setup will be finished. */ - memcpy(tmp_pg_dir, swapper_pg_dir, sizeof(tmp_pg_dir)); + memcpy(tmp_pg_dir, new_swapper_pg_dir, sizeof(tmp_pg_dir)); dsb(ishst); cpu_replace_ttbr1(__pa_symbol(tmp_pg_dir)); diff --git a/arch/arm64/mm/mmu.c b/arch/arm64/mm/mmu.c index 41eee333f91a..26ba3e70a91c 100644 --- a/arch/arm64/mm/mmu.c +++ b/arch/arm64/mm/mmu.c @@ -56,6 +56,7 @@ u64 kimage_voffset __ro_after_init; EXPORT_SYMBOL(kimage_voffset); phys_addr_t __pa_swapper_pg_dir; +pgd_t *new_swapper_pg_dir = swapper_pg_dir; /* * Empty_zero_page is a special page that is used for zero-initialized data