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); From patchwork Sat Jan 9 10:32:50 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Lecopzer Chen X-Patchwork-Id: 12008079 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 18EFFC433DB for ; Sat, 9 Jan 2021 10:33:30 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id AC7A820897 for ; Sat, 9 Jan 2021 10:33:29 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org AC7A820897 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 50B176B0184; Sat, 9 Jan 2021 05:33:29 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 4BAB28D0002; Sat, 9 Jan 2021 05:33:29 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 3A8E06B0186; Sat, 9 Jan 2021 05:33:29 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0139.hostedemail.com [216.40.44.139]) by kanga.kvack.org (Postfix) with ESMTP id 233796B0184 for ; Sat, 9 Jan 2021 05:33:29 -0500 (EST) Received: from smtpin27.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay05.hostedemail.com (Postfix) with ESMTP id DD7FB181AC550 for ; Sat, 9 Jan 2021 10:33:28 +0000 (UTC) X-FDA: 77685874896.27.army51_2504d34274fa Received: from filter.hostedemail.com (10.5.16.251.rfc1918.com [10.5.16.251]) by smtpin27.hostedemail.com (Postfix) with ESMTP id C4F163D663 for ; Sat, 9 Jan 2021 10:33:28 +0000 (UTC) X-HE-Tag: army51_2504d34274fa X-Filterd-Recvd-Size: 4964 Received: from mail-pl1-f175.google.com (mail-pl1-f175.google.com [209.85.214.175]) by imf04.hostedemail.com (Postfix) with ESMTP for ; Sat, 9 Jan 2021 10:33:28 +0000 (UTC) Received: by mail-pl1-f175.google.com with SMTP id q4so7019673plr.7 for ; Sat, 09 Jan 2021 02:33:28 -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=3UgUJ81KV4RLYeQfSGzwX3AUr5zkvCkqoF7/Wom4eVQ=; b=tIBodBVvD3dM/tPcoS7jhBbToG4VyWQROjl7yols9+8ORS/CcPAm5b20IC5Jbs9tWr yVOLQtwCCXvMimceRWBUO3zhKGWQjw7EHrfg5RSASgGqK8LLFbezIk2DCr5vc/pfiFnF JV6iQ2JA+Tw6kQMauQ4Z99oHP/u9IuHGhrJnVZaraWhMs00rxoSZ3aZ/hnNT+XYPjx/e UKfTzi1j/93nWOO+MObZpu/CQ5vP357FBpGxyOqQ4YFTPgngWp8raasL/lH/dTgxRD7p PLNtLI5oX9npD+u8BZKHa2tHKv0Fubd+WvDVhI9ejaqOXD0W5NgE6ZHTUmiYwluIMzHv lwYg== 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=3UgUJ81KV4RLYeQfSGzwX3AUr5zkvCkqoF7/Wom4eVQ=; b=jFqCbqc9RimdkkkqwOxkCiqq+o/riyjydk8Gc5Dgbi9RsVfUVOv7+k7h8jtFzD/dNR 5JzT0IucnbjWmuongayzaADgSF87gd1dNOineq4FOYIU6+g+S1kfMC3DvsLhSjW9IZbs xEUozJi4dobCtvPVaiEGQXr+ASYiR6azULKC0db5/39dVGIFKoaLS69C19p9GQkUFnqa lR9ggKlBR2PahpCQLyFqPKQYqj9whcdyFa99yr1VOhdGtOPP2ALYafurw7FP6HNIHOc0 uEmpEbrJwV8zwqc7mtyBLppoXBJxV3z94gjOZCujTbkg9mjjeL3Tu7aS1OD8/SoMrkq9 J3SQ== X-Gm-Message-State: AOAM530lr5MEQFpy8rv44WLuumHgHokkKrJiouTl2Ssfbt3ijNWxQ9Mc 2j4weRndbpydyQKB6fRFxycbJf3znoE3PA== X-Google-Smtp-Source: ABdhPJy4QsiaNLvy4Wi6V3VyP08TTOZIk5pdsPpG8vK4ovPwJSYRAs9Lig3+CqO4Uia7rBMWDffypA== X-Received: by 2002:a17:902:9a02:b029:dc:3481:3ff1 with SMTP id v2-20020a1709029a02b02900dc34813ff1mr11034416plp.28.1610188407451; Sat, 09 Jan 2021 02:33:27 -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.21 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 09 Jan 2021 02:33:26 -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 2/4] arm64: kasan: abstract _text and _end to KERNEL_START/END Date: Sat, 9 Jan 2021 18:32:50 +0800 Message-Id: <20210109103252.812517-3-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.000001, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: Arm64 provide defined macro for KERNEL_START and KERNEL_END, thus replace them by the abstration instead of using _text and _end. Signed-off-by: Lecopzer Chen --- arch/arm64/mm/kasan_init.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/arch/arm64/mm/kasan_init.c b/arch/arm64/mm/kasan_init.c index 39b218a64279..fa8d7ece895d 100644 --- a/arch/arm64/mm/kasan_init.c +++ b/arch/arm64/mm/kasan_init.c @@ -218,8 +218,8 @@ static void __init kasan_init_shadow(void) phys_addr_t pa_start, pa_end; u64 i; - kimg_shadow_start = (u64)kasan_mem_to_shadow(_text) & PAGE_MASK; - kimg_shadow_end = PAGE_ALIGN((u64)kasan_mem_to_shadow(_end)); + kimg_shadow_start = (u64)kasan_mem_to_shadow(KERNEL_START) & PAGE_MASK; + kimg_shadow_end = PAGE_ALIGN((u64)kasan_mem_to_shadow(KERNEL_END)); mod_shadow_start = (u64)kasan_mem_to_shadow((void *)MODULES_VADDR); mod_shadow_end = (u64)kasan_mem_to_shadow((void *)MODULES_END); @@ -241,7 +241,7 @@ static void __init kasan_init_shadow(void) clear_pgds(KASAN_SHADOW_START, KASAN_SHADOW_END); kasan_map_populate(kimg_shadow_start, kimg_shadow_end, - early_pfn_to_nid(virt_to_pfn(lm_alias(_text)))); + early_pfn_to_nid(virt_to_pfn(lm_alias(KERNEL_START)))); kasan_populate_early_shadow(kasan_mem_to_shadow((void *)PAGE_END), (void *)mod_shadow_start); From patchwork Sat Jan 9 10:32:51 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Lecopzer Chen X-Patchwork-Id: 12008081 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 90E01C433DB for ; Sat, 9 Jan 2021 10:33:39 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id 38FC420897 for ; Sat, 9 Jan 2021 10:33:39 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 38FC420897 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 D46316B0186; Sat, 9 Jan 2021 05:33:38 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id CF5F68D0007; Sat, 9 Jan 2021 05:33:38 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id C0DAB8D0002; Sat, 9 Jan 2021 05:33:38 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0196.hostedemail.com [216.40.44.196]) by kanga.kvack.org (Postfix) with ESMTP id AA8516B0186 for ; Sat, 9 Jan 2021 05:33:38 -0500 (EST) Received: from smtpin24.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay03.hostedemail.com (Postfix) with ESMTP id 6C8C2824556B for ; Sat, 9 Jan 2021 10:33:38 +0000 (UTC) X-FDA: 77685875316.24.roll60_2f019b7274fa Received: from filter.hostedemail.com (10.5.16.251.rfc1918.com [10.5.16.251]) by smtpin24.hostedemail.com (Postfix) with ESMTP id 5407E1A4A5 for ; Sat, 9 Jan 2021 10:33:38 +0000 (UTC) X-HE-Tag: roll60_2f019b7274fa X-Filterd-Recvd-Size: 4281 Received: from mail-pl1-f181.google.com (mail-pl1-f181.google.com [209.85.214.181]) by imf04.hostedemail.com (Postfix) with ESMTP for ; Sat, 9 Jan 2021 10:33:37 +0000 (UTC) Received: by mail-pl1-f181.google.com with SMTP id v3so7002378plz.13 for ; Sat, 09 Jan 2021 02:33:37 -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=oLn/SnoBrp3vqZ9sozuXKpJ43I84HTjowTO19xhLeG0=; b=AG/rOYoYRKgzWfqA56Rn+dg5UnJabvU6av5xhDPFM2zF5AyoVz1q4ouIgLU0rUwCf3 GE8L0v5F5suRbnCEyfCMP1LYdLPT803JePm75nQeC45cv+2eRuIQcfrmVMx5rrX+vPmY VT7lek/olVSJGVT0tcb00utrd6oGbaL5pHfK6zrQOtvzLyTdtYKbTpRrbv9AlKg09v8V 0HPUv2qKxgiSlO55/8VstzjDuZ/VK/nPdFqQyg4lXo/KwkkrKd+FfsCQ4tcvXso/m+9A IOk1rWNImSptf2gNWjE//OXdLb34y0erVoZB4eVGCeMN2E52fpzqD9DIII2Fd+vuN3ZQ 3eaw== 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=oLn/SnoBrp3vqZ9sozuXKpJ43I84HTjowTO19xhLeG0=; b=CniGPwkXFYyz7OXB+d7i0McT2x9wajG7zHJCqgTjmgypYtsFky7j+ipfeI9M2/XbAG hzprhn9qW/AGIZVkqWWK6DLI2/wF0rKFMNslABqc8PJNAcuhJq5vUSPMaOEnPSlUANoz 9z6dXgwDt1YjSk/jYm8ZAPqY/Gg/hXTMb9KA6DNf7q7Vlb7basBaq2JkY6O3/EMaW6kZ EU1Uax99/YhiKllhIN52IdTiMRXramlYTRt8+v2uqLrOvuC56p4Q2jz9vK16N6UCMTpR J6+7szq2fJgD/o5Vbxw3pfLF/kZNZf9ioFzmobTdbgOCrhJe48lHk96eZGil8EZ+BFXk aQ4g== X-Gm-Message-State: AOAM531qr6s686KRDEiejJSbMIScEdIOtYiTdEeZhO7aiddpu9ue08h+ +uvkMgWi7vjzBaVmv9BP2W8= X-Google-Smtp-Source: ABdhPJxIH5S3lPWz6xhxfymgG03a6AwgPQzKq4F2KcokdfmaTtrNpjtkVrmnEo0bgoXAa0A0Gz4I5Q== X-Received: by 2002:a17:902:bb95:b029:dc:e7b:fd6e with SMTP id m21-20020a170902bb95b02900dc0e7bfd6emr11108147pls.12.1610188416663; Sat, 09 Jan 2021 02:33:36 -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.30 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 09 Jan 2021 02:33:36 -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 3/4] arm64: Kconfig: support CONFIG_KASAN_VMALLOC Date: Sat, 9 Jan 2021 18:32:51 +0800 Message-Id: <20210109103252.812517-4-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: now we can backed shadow memory in vmalloc area, thus support KASAN_VMALLOC in KASAN_GENERIC mode. Signed-off-by: Lecopzer Chen --- arch/arm64/Kconfig | 1 + 1 file changed, 1 insertion(+) diff --git a/arch/arm64/Kconfig b/arch/arm64/Kconfig index 05e17351e4f3..ba03820402ee 100644 --- a/arch/arm64/Kconfig +++ b/arch/arm64/Kconfig @@ -136,6 +136,7 @@ config ARM64 select HAVE_ARCH_JUMP_LABEL select HAVE_ARCH_JUMP_LABEL_RELATIVE select HAVE_ARCH_KASAN if !(ARM64_16K_PAGES && ARM64_VA_BITS_48) + select HAVE_ARCH_KASAN_VMALLOC if HAVE_ARCH_KASAN select HAVE_ARCH_KASAN_SW_TAGS if HAVE_ARCH_KASAN select HAVE_ARCH_KASAN_HW_TAGS if (HAVE_ARCH_KASAN && ARM64_MTE) select HAVE_ARCH_KGDB From patchwork Sat Jan 9 10:32:52 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Lecopzer Chen X-Patchwork-Id: 12008083 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 A22A9C433DB for ; Sat, 9 Jan 2021 10:33:47 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id 4EC3F20897 for ; Sat, 9 Jan 2021 10:33:47 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 4EC3F20897 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 DBCE06B0188; Sat, 9 Jan 2021 05:33:46 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id D922C8D0002; Sat, 9 Jan 2021 05:33:46 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id CA8BB6B018A; Sat, 9 Jan 2021 05:33:46 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0013.hostedemail.com [216.40.44.13]) by kanga.kvack.org (Postfix) with ESMTP id B600F6B0188 for ; Sat, 9 Jan 2021 05:33:46 -0500 (EST) Received: from smtpin12.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay05.hostedemail.com (Postfix) with ESMTP id 80D73181AC550 for ; Sat, 9 Jan 2021 10:33:46 +0000 (UTC) X-FDA: 77685875652.12.cars14_4c019b6274fa Received: from filter.hostedemail.com (10.5.16.251.rfc1918.com [10.5.16.251]) by smtpin12.hostedemail.com (Postfix) with ESMTP id 5E4BC1800227D for ; Sat, 9 Jan 2021 10:33:46 +0000 (UTC) X-HE-Tag: cars14_4c019b6274fa X-Filterd-Recvd-Size: 6959 Received: from mail-pg1-f177.google.com (mail-pg1-f177.google.com [209.85.215.177]) by imf06.hostedemail.com (Postfix) with ESMTP for ; Sat, 9 Jan 2021 10:33:45 +0000 (UTC) Received: by mail-pg1-f177.google.com with SMTP id n10so9290624pgl.10 for ; Sat, 09 Jan 2021 02:33:45 -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=xjESqlUb86RQ6iRPUx+QrIUmLWqLivYfrQTN5THOZlI=; b=BPZllgi5j123yuQfqVOrYEdSznE7JM0iGEn20PN86SJp5LuMZ02GpJIdXxKU5f06lo v0sdJbXah37egbezScUS75h3gFsVDu2TvXVT4wFU6e07EoexWe5Bfxd5/0DXNT9OF4Ak 0BfyFOyQpbC+ZIru/6UpoqCsDY1grAObtZGP4e+3+b78hIzVb7r8kKLhNZM+whZ+dUr5 8rwbKK0V3+7uN+aKrVU+tVUCiBK/hwZjD/3DnB0SKZVrL8zaqHjoCai9Dw9i0EwI4+pF J7hzl7aC7QzoLIXtNAXCicyX085vdBopmyvdwudeQrwfrw2GsvrRfZ4MxlvBZnY5DQ8f DKNQ== 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=xjESqlUb86RQ6iRPUx+QrIUmLWqLivYfrQTN5THOZlI=; b=WCb8wIxqOEgalINecYza1vMDgDQWKcDBab/0/3XshiD+mramGyepc3c3smKO+3U7XD zPGn5y01bFRG8XvgLz2bsFGzyavpKPE/agjW9t8jYWfC4NV8p7Sy1A8yujVlf20m4DOT 0r4bvBpt7EqZ0GSpBn9+tQsetazZbSCD3g7ngiX/hrzvFjFJje7R0k/VZmmad3xnq8mQ aV8RF+8CtsLFBJC0EydnTIl4b+AvFYVohX6Qst/zMoSjEgK/RaKKNjVFLFys7Z8shqEi ppHBVlUVXunLw2a+1/NWXg8LELAqlX1C6HdPYT1S/06AAxB9niq6b0EhwEkM45Epk31K SmIw== X-Gm-Message-State: AOAM530shqyoxYoQU8XY+WcJ33qSNIfPkkCyHe4F/ZuZ1r/A13EU0trP ZM3R3KbYCLBICaVs6HDP9aw= X-Google-Smtp-Source: ABdhPJxnAfGcjjOzp0O5bC+zZRpiwF3pGnF0uWlC/oLTtAZ685s5ouGYEu3QKd0emh/MPnfAeJ4Z0Q== X-Received: by 2002:a62:25c1:0:b029:1a9:ee40:3fd3 with SMTP id l184-20020a6225c10000b02901a9ee403fd3mr7620101pfl.58.1610188424692; Sat, 09 Jan 2021 02:33:44 -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.39 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 09 Jan 2021 02:33:44 -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 4/4] arm64: kaslr: support randomized module area with KASAN_VMALLOC Date: Sat, 9 Jan 2021 18:32:52 +0800 Message-Id: <20210109103252.812517-5-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: After KASAN_VMALLOC works in arm64, we can randomize module region into vmalloc area now. Test: VMALLOC area ffffffc010000000 fffffffdf0000000 before the patch: module_alloc_base/end ffffffc008b80000 ffffffc010000000 after the patch: module_alloc_base/end ffffffdcf4bed000 ffffffc010000000 And the function that insmod some modules is fine. Suggested-by: Ard Biesheuvel Signed-off-by: Lecopzer Chen --- arch/arm64/kernel/kaslr.c | 18 ++++++++++-------- arch/arm64/kernel/module.c | 16 +++++++++------- 2 files changed, 19 insertions(+), 15 deletions(-) diff --git a/arch/arm64/kernel/kaslr.c b/arch/arm64/kernel/kaslr.c index 1c74c45b9494..a2858058e724 100644 --- a/arch/arm64/kernel/kaslr.c +++ b/arch/arm64/kernel/kaslr.c @@ -161,15 +161,17 @@ u64 __init kaslr_early_init(u64 dt_phys) /* use the top 16 bits to randomize the linear region */ memstart_offset_seed = seed >> 48; - if (IS_ENABLED(CONFIG_KASAN_GENERIC) || - IS_ENABLED(CONFIG_KASAN_SW_TAGS)) + if (!IS_ENABLED(CONFIG_KASAN_VMALLOC) && + (IS_ENABLED(CONFIG_KASAN_GENERIC) || + IS_ENABLED(CONFIG_KASAN_SW_TAGS))) /* - * KASAN does not expect the module region to intersect the - * vmalloc region, since shadow memory is allocated for each - * module at load time, whereas the vmalloc region is shadowed - * by KASAN zero pages. So keep modules out of the vmalloc - * region if KASAN is enabled, and put the kernel well within - * 4 GB of the module region. + * KASAN without KASAN_VMALLOC does not expect the module region + * to intersect the vmalloc region, since shadow memory is + * allocated for each module at load time, whereas the vmalloc + * region is shadowed by KASAN zero pages. So keep modules + * out of the vmalloc region if KASAN is enabled without + * KASAN_VMALLOC, and put the kernel well within 4 GB of the + * module region. */ return offset % SZ_2G; diff --git a/arch/arm64/kernel/module.c b/arch/arm64/kernel/module.c index fe21e0f06492..b5ec010c481f 100644 --- a/arch/arm64/kernel/module.c +++ b/arch/arm64/kernel/module.c @@ -40,14 +40,16 @@ void *module_alloc(unsigned long size) NUMA_NO_NODE, __builtin_return_address(0)); if (!p && IS_ENABLED(CONFIG_ARM64_MODULE_PLTS) && - !IS_ENABLED(CONFIG_KASAN_GENERIC) && - !IS_ENABLED(CONFIG_KASAN_SW_TAGS)) + (IS_ENABLED(CONFIG_KASAN_VMALLOC) || + (!IS_ENABLED(CONFIG_KASAN_GENERIC) && + !IS_ENABLED(CONFIG_KASAN_SW_TAGS)))) /* - * KASAN can only deal with module allocations being served - * from the reserved module region, since the remainder of - * the vmalloc region is already backed by zero shadow pages, - * and punching holes into it is non-trivial. Since the module - * region is not randomized when KASAN is enabled, it is even + * KASAN without KASAN_VMALLOC can only deal with module + * allocations being served from the reserved module region, + * since the remainder of the vmalloc region is already + * backed by zero shadow pages, and punching holes into it + * is non-trivial. Since the module region is not randomized + * when KASAN is enabled without KASAN_VMALLOC, it is even * less likely that the module region gets exhausted, so we * can simply omit this fallback in that case. */