From patchwork Sat Feb 6 08:35:47 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Lecopzer Chen X-Patchwork-Id: 12072013 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=-17.0 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER, INCLUDES_PATCH,MAILING_LIST_MULTI,MIME_BASE64_TEXT,SPF_HELO_NONE,SPF_PASS, UNPARSEABLE_RELAY,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 6581DC433E0 for ; Sat, 6 Feb 2021 08:46:33 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id 02ADB64F06 for ; Sat, 6 Feb 2021 08:46:32 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 02ADB64F06 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=mediatek.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=owner-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix) id 175136B0070; Sat, 6 Feb 2021 03:46:30 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 0B00E6B0071; Sat, 6 Feb 2021 03:46:30 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id EDD706B0072; Sat, 6 Feb 2021 03:46:29 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0041.hostedemail.com [216.40.44.41]) by kanga.kvack.org (Postfix) with ESMTP id D9C456B0070 for ; Sat, 6 Feb 2021 03:46:29 -0500 (EST) Received: from smtpin26.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay05.hostedemail.com (Postfix) with ESMTP id 9BA17181AEF10 for ; Sat, 6 Feb 2021 08:46:29 +0000 (UTC) X-FDA: 77787211698.26.snail22_59070fc275ec Received: from filter.hostedemail.com (10.5.16.251.rfc1918.com [10.5.16.251]) by smtpin26.hostedemail.com (Postfix) with ESMTP id 71C9C1804B66A for ; Sat, 6 Feb 2021 08:46:29 +0000 (UTC) X-HE-Tag: snail22_59070fc275ec X-Filterd-Recvd-Size: 6180 Received: from mailgw01.mediatek.com (mailgw01.mediatek.com [216.200.240.184]) by imf37.hostedemail.com (Postfix) with ESMTP for ; Sat, 6 Feb 2021 08:46:28 +0000 (UTC) X-UUID: c2688788d9f240f99586bf8a714d24e1-20210206 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=mediatek.com; s=dk; h=Content-Transfer-Encoding:Content-Type:MIME-Version:Message-ID:Date:Subject:CC:To:From; bh=GNL5TnXZWao9h2DFDrcMnQF6C7i6wQ7dc36keENPRnY=; b=nNqpwDIwpnh2fRLXJhhW8KaVxFhNZxk3qtq4g86tqgvgkoTOmAL2EU7Be2rRXUAzot6QQ2d10Ui4ROFoLo1XFi0zlf7VpRFhThLb0CzUldDMpCu2UHl/SrxkMDtsLTduJJfzGAZLEVBXeVfYXX6/9yxrf9fheVU/+MFAciL+ei8=; X-UUID: c2688788d9f240f99586bf8a714d24e1-20210206 Received: from mtkcas66.mediatek.inc [(172.29.193.44)] by mailgw01.mediatek.com (envelope-from ) (musrelay.mediatek.com ESMTP with TLSv1.2 ECDHE-RSA-AES256-SHA384 256/256) with ESMTP id 337313232; Sat, 06 Feb 2021 00:46:21 -0800 Received: from mtkmbs08n2.mediatek.inc (172.21.101.56) by MTKMBS62N2.mediatek.inc (172.29.193.42) with Microsoft SMTP Server (TLS) id 15.0.1497.2; Sat, 6 Feb 2021 00:36:18 -0800 Received: from mtkcas11.mediatek.inc (172.21.101.40) by mtkmbs08n2.mediatek.inc (172.21.101.56) with Microsoft SMTP Server (TLS) id 15.0.1497.2; Sat, 6 Feb 2021 16:36:04 +0800 Received: from mtksdccf07.mediatek.inc (172.21.84.99) by mtkcas11.mediatek.inc (172.21.101.73) with Microsoft SMTP Server id 15.0.1497.2 via Frontend Transport; Sat, 6 Feb 2021 16:36:04 +0800 From: Lecopzer Chen To: , , , , CC: , , , , , , , , , , , , , , , , , , Lecopzer Chen Subject: [PATCH v3 0/5] arm64: kasan: support CONFIG_KASAN_VMALLOC Date: Sat, 6 Feb 2021 16:35:47 +0800 Message-ID: <20210206083552.24394-1-lecopzer.chen@mediatek.com> X-Mailer: git-send-email 2.18.0 MIME-Version: 1.0 X-TM-SNTS-SMTP: 48ED01F9EB92388DB50C25F6565B6744F8836A662E8B2C774BE4F94EFBD8AA522000:8 X-MTK: N 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: Linux supports KAsan for VMALLOC since commit 3c5c3cfb9ef4da9 ("kasan: support backing vmalloc space with real shadow memory") Acroding to how x86 ported it [1], they early allocated p4d and pgd, but in arm64 I just simulate how KAsan supports MODULES_VADDR in arm64 by not to populate the vmalloc area except for kimg address. ----------- vmalloc_shadow_start | | | | | | <= non-mapping | | | | |-----------| |///////////|<- kimage shadow with page table mapping. |-----------| | | | | <= non-mapping | | ------------- vmalloc_shadow_end |00000000000| |00000000000| <= Zero shadow |00000000000| ------------- KASAN_SHADOW_END Test environment: 4G and 8G Qemu virt, 39-bit VA + 4k PAGE_SIZE with 3-level page table, test by lib/test_kasan.ko and lib/test_kasan_module.ko It works in Kaslr with CONFIG_RANDOMIZE_MODULE_REGION_FULL and randomize module region inside vmalloc area. Also work with VMAP_STACK, thanks Ard for testing it. [1]: commit 0609ae011deb41c ("x86/kasan: support KASAN_VMALLOC") Signed-off-by: Lecopzer Chen Acked-by: Andrey Konovalov Tested-by: Andrey Konovalov Tested-by: Ard Biesheuvel --- Thanks Will Deacon, Ard Biesheuvel and Andrey Konovalov for reviewing and suggestion. v3 -> v2 rebase on 5.11-rc6 1. remove always true condition in kasan_init() and remove unsed vmalloc_shadow_start. 2. select KASAN_VMALLOC if KANSAN_GENERIC is enabled for VMAP_STACK. 3. tweak commit message v2 -> v1 1. kasan_init.c tweak indent 2. change Kconfig depends only on HAVE_ARCH_KASAN 3. support randomized module region. v2: https://lkml.org/lkml/2021/1/9/49 v1: https://lore.kernel.org/lkml/20210103171137.153834-1-lecopzer@gmail.com/ --- Lecopzer Chen (5): arm64: kasan: don't populate vmalloc area for CONFIG_KASAN_VMALLOC arm64: kasan: abstract _text and _end to KERNEL_START/END arm64: Kconfig: support CONFIG_KASAN_VMALLOC arm64: kaslr: support randomized module area with KASAN_VMALLOC arm64: Kconfig: select KASAN_VMALLOC if KANSAN_GENERIC is enabled arch/arm64/Kconfig | 2 ++ arch/arm64/kernel/kaslr.c | 18 ++++++++++-------- arch/arm64/kernel/module.c | 16 +++++++++------- arch/arm64/mm/kasan_init.c | 24 ++++++++++++++++-------- 4 files changed, 37 insertions(+), 23 deletions(-)