From patchwork Sat Jan 9 10:32:49 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Lecopzer Chen X-Patchwork-Id: 12008077 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.5 required=3.0 tests=BAYES_00, DKIM_ADSP_CUSTOM_MED,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,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 2A0A3C433E0 for ; Sat, 9 Jan 2021 10:33:22 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id B5F5420897 for ; Sat, 9 Jan 2021 10:33:21 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org B5F5420897 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=gmail.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=owner-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix) id 4E29D6B0181; Sat, 9 Jan 2021 05:33:21 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 493616B0183; Sat, 9 Jan 2021 05:33:21 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 3839C8D0002; Sat, 9 Jan 2021 05:33:21 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0016.hostedemail.com [216.40.44.16]) by kanga.kvack.org (Postfix) with ESMTP id 1F84F6B0181 for ; Sat, 9 Jan 2021 05:33:21 -0500 (EST) Received: from smtpin02.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay01.hostedemail.com (Postfix) with ESMTP id D4F17180AD811 for ; Sat, 9 Jan 2021 10:33:20 +0000 (UTC) X-FDA: 77685874560.02.roll81_5f1524d274fa Received: from filter.hostedemail.com (10.5.16.251.rfc1918.com [10.5.16.251]) by smtpin02.hostedemail.com (Postfix) with ESMTP id BD1C610097AA0 for ; Sat, 9 Jan 2021 10:33:20 +0000 (UTC) X-HE-Tag: roll81_5f1524d274fa X-Filterd-Recvd-Size: 6038 Received: from mail-pl1-f179.google.com (mail-pl1-f179.google.com [209.85.214.179]) by imf33.hostedemail.com (Postfix) with ESMTP for ; Sat, 9 Jan 2021 10:33:20 +0000 (UTC) Received: by mail-pl1-f179.google.com with SMTP id 4so7018716plk.5 for ; Sat, 09 Jan 2021 02:33:20 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=0xLmuarIgQdWn84D3wx5rQsfGRtDVE6UQliEht6Oq48=; b=tznSyNRiMyzItLUMQF6oR/88pqEwX9kk7kTQfKdCANR4RIg/jSGWow+vKdXCem/hFb 3hSA000zXc3fyKUBdl/ZjSgR2sEYKmFdqPf4S63Pq3QJjj+bNy413T645P3RQ23jgmVt 3J3FN8KfuLI2UcJsPN3IuNUC+xuBK2yRVHcTCAS5lB5ZR5KUApOT3cZsVhs984Mmsz+/ V4Z6OZsDrFjz+MRDH1hiEauKdGXjagzEXCWcgckQrokmREpHGU7Y6/Z2qKMRYnBqpqtE iEY5t/mq3PAmOu1pAJ8pySebW15PR/thBHPuWzHkZqim021luT+y9tkl8tBRN4AkugJS Vpqw== 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:in-reply-to :references:mime-version:content-transfer-encoding; bh=0xLmuarIgQdWn84D3wx5rQsfGRtDVE6UQliEht6Oq48=; b=AQPVUjLV6NrSD8W5RyLkQ5vzqNTdg6oPqBHZ+d+P3VJr9snHHQrwCaf57cqQz6I55K JIhRpXZbkEJ1IP/Lz8ZBIuf5VHj7l4tPKwDitgW7eVDzh5GxQ6NMqMSsSsZSl2BzilaR +0Jc7hLfbS7ZxAObuoIHPFJeC7kV2uZ2IHFjGN6phGHvXGMDIg08ppnYnE7WVpyz6IlL pnjEM4vYRVSeeqypHgutw3LB4DE3+PIYKNHhFriBw1XRqNNU4loHioJEYQTjtdKZe3i6 TVXMaU0z0nG2WILuWqA2yC9NGfVvQ2rx1Fpb0EK2DW+FJCij4dVTLWPs6fVFNrqbbU4k O3sw== X-Gm-Message-State: AOAM533isHKtxj4lpUm8/lh0Zb9jVyDVr0vQcyHILAIl6vtt4/rUG6qG BZkzC+D85kiu8IzvoekeB9c= X-Google-Smtp-Source: ABdhPJwBW139zzmCSB7i8s5twWc31e2pZPSPq4BBWMA49N6/L9k08yfNKeLBW6qnhsn2aMKeT1auFA== X-Received: by 2002:a17:902:b189:b029:dc:4102:4edf with SMTP id s9-20020a170902b189b02900dc41024edfmr8031040plr.80.1610188399222; Sat, 09 Jan 2021 02:33:19 -0800 (PST) Received: from localhost.localdomain (61-230-13-78.dynamic-ip.hinet.net. [61.230.13.78]) by smtp.gmail.com with ESMTPSA id w200sm11691572pfc.14.2021.01.09.02.33.13 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 09 Jan 2021 02:33:18 -0800 (PST) From: Lecopzer Chen To: linux-kernel@vger.kernel.org, linux-mm@kvack.org, kasan-dev@googlegroups.com, linux-arm-kernel@lists.infradead.org Cc: dan.j.williams@intel.com, aryabinin@virtuozzo.com, glider@google.com, dvyukov@google.com, akpm@linux-foundation.org, linux-mediatek@lists.infradead.org, yj.chiang@mediatek.com, will@kernel.org, catalin.marinas@arm.com, ardb@kernel.org, andreyknvl@google.com, broonie@kernel.org, linux@roeck-us.net, rppt@kernel.org, tyhicks@linux.microsoft.com, robin.murphy@arm.com, vincenzo.frascino@arm.com, gustavoars@kernel.org, Lecopzer Chen , Lecopzer Chen Subject: [PATCH v2 1/4] arm64: kasan: don't populate vmalloc area for CONFIG_KASAN_VMALLOC Date: Sat, 9 Jan 2021 18:32:49 +0800 Message-Id: <20210109103252.812517-2-lecopzer@gmail.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20210109103252.812517-1-lecopzer@gmail.com> References: <20210109103252.812517-1-lecopzer@gmail.com> MIME-Version: 1.0 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 support KAsan for VMALLOC since commit 3c5c3cfb9ef4da9 ("kasan: support backing vmalloc space with real shadow memory") Like how the MODULES_VADDR does now, just not to early populate the VMALLOC_START between VMALLOC_END. similarly, the kernel code mapping is now in the VMALLOC area and should keep these area populated. Signed-off-by: Lecopzer Chen --- arch/arm64/mm/kasan_init.c | 23 ++++++++++++++++++----- 1 file changed, 18 insertions(+), 5 deletions(-) diff --git a/arch/arm64/mm/kasan_init.c b/arch/arm64/mm/kasan_init.c index d8e66c78440e..39b218a64279 100644 --- a/arch/arm64/mm/kasan_init.c +++ b/arch/arm64/mm/kasan_init.c @@ -214,6 +214,7 @@ static void __init kasan_init_shadow(void) { u64 kimg_shadow_start, kimg_shadow_end; u64 mod_shadow_start, mod_shadow_end; + u64 vmalloc_shadow_start, vmalloc_shadow_end; phys_addr_t pa_start, pa_end; u64 i; @@ -223,6 +224,9 @@ static void __init kasan_init_shadow(void) mod_shadow_start = (u64)kasan_mem_to_shadow((void *)MODULES_VADDR); mod_shadow_end = (u64)kasan_mem_to_shadow((void *)MODULES_END); + vmalloc_shadow_start = (u64)kasan_mem_to_shadow((void *)VMALLOC_START); + vmalloc_shadow_end = (u64)kasan_mem_to_shadow((void *)VMALLOC_END); + /* * We are going to perform proper setup of shadow memory. * At first we should unmap early shadow (clear_pgds() call below). @@ -241,12 +245,21 @@ static void __init kasan_init_shadow(void) kasan_populate_early_shadow(kasan_mem_to_shadow((void *)PAGE_END), (void *)mod_shadow_start); - kasan_populate_early_shadow((void *)kimg_shadow_end, - (void *)KASAN_SHADOW_END); + if (IS_ENABLED(CONFIG_KASAN_VMALLOC)) { + kasan_populate_early_shadow((void *)vmalloc_shadow_end, + (void *)KASAN_SHADOW_END); + if (vmalloc_shadow_start > mod_shadow_end) + kasan_populate_early_shadow((void *)mod_shadow_end, + (void *)vmalloc_shadow_start); + + } else { + kasan_populate_early_shadow((void *)kimg_shadow_end, + (void *)KASAN_SHADOW_END); + if (kimg_shadow_start > mod_shadow_end) + kasan_populate_early_shadow((void *)mod_shadow_end, + (void *)kimg_shadow_start); + } - if (kimg_shadow_start > mod_shadow_end) - kasan_populate_early_shadow((void *)mod_shadow_end, - (void *)kimg_shadow_start); for_each_mem_range(i, &pa_start, &pa_end) { void *start = (void *)__phys_to_virt(pa_start);