From patchwork Sat Jan 9 04:46:22 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: hailong X-Patchwork-Id: 12007923 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=-13.6 required=3.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED,USER_AGENT_GIT 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 42D6DC433E0 for ; Sat, 9 Jan 2021 04:48:04 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id BB40E23A69 for ; Sat, 9 Jan 2021 04:48:03 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org BB40E23A69 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=yeah.net Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=owner-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix) id B642E8D01B7; Fri, 8 Jan 2021 23:48:02 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id B15306B00C1; Fri, 8 Jan 2021 23:48:02 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id A2A7F8D01B7; Fri, 8 Jan 2021 23:48:02 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0180.hostedemail.com [216.40.44.180]) by kanga.kvack.org (Postfix) with ESMTP id 8A4EC6B0095 for ; Fri, 8 Jan 2021 23:48:02 -0500 (EST) Received: from smtpin13.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay04.hostedemail.com (Postfix) with ESMTP id 5116F4DAB for ; Sat, 9 Jan 2021 04:48:02 +0000 (UTC) X-FDA: 77685004404.13.bread17_540e63b274f8 Received: from filter.hostedemail.com (10.5.16.251.rfc1918.com [10.5.16.251]) by smtpin13.hostedemail.com (Postfix) with ESMTP id 3398618140B60 for ; Sat, 9 Jan 2021 04:48:02 +0000 (UTC) X-HE-Tag: bread17_540e63b274f8 X-Filterd-Recvd-Size: 4003 Received: from mail-177132.yeah.net (mail-177132.yeah.net [123.58.177.132]) by imf40.hostedemail.com (Postfix) with ESMTP for ; Sat, 9 Jan 2021 04:47:57 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=yeah.net; s=s110527; h=From:Subject:Date:Message-Id:MIME-Version; bh=8u5ig eF9P2tWvHHZTcGnBzv/d0gnIJMobD7YOWJEPso=; b=hWfNBooHGQC+drth925D3 7XBj/o8l53BMvOP/bYK2nM5zX6vuApRAfKtSDCgIevh3K7Kcg7INV+30dOFu69yr AU3Vke4fa3ZLMXedcSRzIDLPgLm1+DhMxdN2IJncC3+4Q8X0Cg9L+D/cmUgqy63h 2xrMHydHw71RxeZJQ9sV84= Received: from localhost.localdomain (unknown [117.139.248.191]) by smtp2 (Coremail) with SMTP id C1UQrAAntuEhNflffZAPLw--.57202S2; Sat, 09 Jan 2021 12:46:26 +0800 (CST) From: Hailong liu To: aryabinin@virtuozzo.com Cc: linux@armlinux.org.uk, glider@google.com, dvyukov@google.com, akpm@linux-foundation.org, kasan-dev@googlegroups.com, linux-arm-kernel@lists.infradead.org, linux-mm@kvack.org, linux-kernel@vger.kernel.org, hailongliiu@yeah.net, Hailong Liu , Ziliang Guo Subject: [PATCH] arm/kasan:fix the arry size of kasan_early_shadow_pte Date: Sat, 9 Jan 2021 12:46:22 +0800 Message-Id: <20210109044622.8312-1-hailongliiu@yeah.net> X-Mailer: git-send-email 2.17.1 MIME-Version: 1.0 X-CM-TRANSID: C1UQrAAntuEhNflffZAPLw--.57202S2 X-Coremail-Antispam: 1Uf129KBjvJXoW7KF47GFW8KrW3tF4xuw4fuFg_yoW8tF4Upw 4DAFy8Kry8ZFn0qa43Cr13Cr1UWwnFkr97tFW29FsIqay7G3s2gFWq9r93Gw1xWrWkJa4Y vw48tFW5Gr15Aa7anT9S1TB71UUUUUUqnTZGkaVYY2UrUUUUjbIjqfuFe4nvWSU5nxnvy2 9KBjDUYxBIdaVFxhVjvjDU0xZFpf9x07jpZXrUUUUU= X-Originating-IP: [117.139.248.191] X-CM-SenderInfo: xkdlz05qjoxx3x61vtnkoqv3/1tbiDQIV6FszTMgUAAAAsK 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: From: Hailong Liu The size of kasan_early_shadow_pte[] now is PTRS_PER_PTE which defined to 512 for arm architecture. This means that it only covers the prev Linux pte entries, but not the HWTABLE pte entries for arm. The reason it works well current is that the symbol kasan_early_shadow_page immediately following kasan_early_shadow_pte in memory is page aligned, which makes kasan_early_shadow_pte look like a 4KB size array. But we can't ensure the order always right with different compiler/linker, nor more bss symbols be introduced. We had a test with QEMU + vexpress:put a 512KB-size symbol with attribute __section(".bss..page_aligned") after kasan_early_shadow_pte, and poison it after kasan_early_init(). Then enabled CONFIG_KASAN, it failed to boot up. Signed-off-by: Hailong Liu Signed-off-by: Ziliang Guo Reviewed-by: Linus Walleij --- include/linux/kasan.h | 6 +++++- mm/kasan/init.c | 3 ++- 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/include/linux/kasan.h b/include/linux/kasan.h index 5e0655fb2a6f..fe1ae73ff8b5 100644 --- a/include/linux/kasan.h +++ b/include/linux/kasan.h @@ -35,8 +35,12 @@ struct kunit_kasan_expectation { #define KASAN_SHADOW_INIT 0 #endif +#ifndef PTE_HWTABLE_PTRS +#define PTE_HWTABLE_PTRS 0 +#endif + extern unsigned char kasan_early_shadow_page[PAGE_SIZE]; -extern pte_t kasan_early_shadow_pte[PTRS_PER_PTE]; +extern pte_t kasan_early_shadow_pte[PTRS_PER_PTE + PTE_HWTABLE_PTRS]; extern pmd_t kasan_early_shadow_pmd[PTRS_PER_PMD]; extern pud_t kasan_early_shadow_pud[PTRS_PER_PUD]; extern p4d_t kasan_early_shadow_p4d[MAX_PTRS_PER_P4D]; diff --git a/mm/kasan/init.c b/mm/kasan/init.c index bc0ad208b3a7..7ca0b92d5886 100644 --- a/mm/kasan/init.c +++ b/mm/kasan/init.c @@ -64,7 +64,8 @@ static inline bool kasan_pmd_table(pud_t pud) return false; } #endif -pte_t kasan_early_shadow_pte[PTRS_PER_PTE] __page_aligned_bss; +pte_t kasan_early_shadow_pte[PTRS_PER_PTE + PTE_HWTABLE_PTRS] + __page_aligned_bss; static inline bool kasan_pte_table(pmd_t pmd) {