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: 12008055 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.7 required=3.0 tests=BAYES_00, DKIM_ADSP_CUSTOM_MED,DKIM_SIGNED,DKIM_VALID,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=unavailable 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 9FD9EC433DB for ; Sat, 9 Jan 2021 10:36:13 +0000 (UTC) Received: from merlin.infradead.org (merlin.infradead.org [205.233.59.134]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 5D7DE23A01 for ; Sat, 9 Jan 2021 10:36:13 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 5D7DE23A01 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=gmail.com Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=merlin.20170209; h=Sender:Content-Transfer-Encoding: Content-Type:Cc:List-Subscribe:List-Help:List-Post:List-Archive: List-Unsubscribe:List-Id:MIME-Version:References:In-Reply-To:Message-Id:Date: Subject:To:From:Reply-To:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Owner; bh=ziHGRhFB62Co8mJZ3cLFqx2yvmsn+jRVWMxDw499CxA=; b=U4un3rgStrNRi7sLe3/yYacee LGZcMeJDV/ET+cZQ0XuSL3E879hvMcHo7ls5PPj0KoL2iYvSskQ3IhjXodW+MV88FGrGk3qJxjocc iqzjDAbFYX6CMj9ptJxe66pxV5m7Hjsd0h077ED1Lw9Ck3+LyW5iW7yMXKW1cEjsCQRcYD8pHP14f 4k+ze0IgpgzxY4cYxzDNxjI0b83HqpI5hJ33L3AYUPgztJdt9PyADgxuzgBn3fV7ipFQZWqNkumyr rSuvYWvjrzc+F9/zhK66BkkvDVzUc1S7ftbRRMhz3q1lGRknyXcnYtRknesUuxoxG4E2815rYBTy3 jUmV3zwZQ==; Received: from localhost ([::1] helo=merlin.infradead.org) by merlin.infradead.org with esmtp (Exim 4.92.3 #3 (Red Hat Linux)) id 1kyBZM-0007xu-SA; Sat, 09 Jan 2021 10:34:04 +0000 Received: from mail-pj1-x102e.google.com ([2607:f8b0:4864:20::102e]) by merlin.infradead.org with esmtps (Exim 4.92.3 #3 (Red Hat Linux)) id 1kyBYf-0007jE-Hz; Sat, 09 Jan 2021 10:33:23 +0000 Received: by mail-pj1-x102e.google.com with SMTP id f14so5028064pju.4; Sat, 09 Jan 2021 02:33:21 -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=QaS4YI9ecqFL5HAz/jeu/ZZZadoP66GeQvC2+vVtKwibUj9v/cMBlGLftrmcGuyYUt k1Zpd8RiMh6YKxcYE6sLpNPE8t6LLgQ2yx3hG4qI28BhSJbapMZrmeRQQxC0UQFTNg4v OJf7hdv6hVxN5agoUWyRsGTtkC2xdaNUYpnsDYTwHhTs/MNpUUNQvLhYsTXov+mA0gNT DfcqMGOSuSj/uL9mx4YDDtI/X6ZI+6EDamyYMA+QHZ1wtQJ0DoEg8NkhzbH9VfAR0k7o XgytdF5bBBY1VZ2M42udTqEURJSBqbRM5mKWUgN0neaqf7qI2juHVLYsROJ0jMklPWnx SIfA== X-Gm-Message-State: AOAM530p0+JqPrY2XXpSW9sO5TUOTpP80l4R02A+P5GpDEQww7AP0qE5 o2YdWR6plqBjFFivPrYjgkk= 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 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-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20210109_053321_803423_F1CAE136 X-CRM114-Status: GOOD ( 13.49 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: tyhicks@linux.microsoft.com, gustavoars@kernel.org, Lecopzer Chen , glider@google.com, yj.chiang@mediatek.com, robin.murphy@arm.com, andreyknvl@google.com, ardb@kernel.org, Lecopzer Chen , broonie@kernel.org, linux-mediatek@lists.infradead.org, linux@roeck-us.net, rppt@kernel.org, catalin.marinas@arm.com, aryabinin@virtuozzo.com, dan.j.williams@intel.com, vincenzo.frascino@arm.com, will@kernel.org, akpm@linux-foundation.org, dvyukov@google.com Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org 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: 12008059 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.7 required=3.0 tests=BAYES_00, DKIM_ADSP_CUSTOM_MED,DKIM_SIGNED,DKIM_VALID,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 EEBF4C433DB for ; Sat, 9 Jan 2021 10:36:20 +0000 (UTC) Received: from merlin.infradead.org (merlin.infradead.org [205.233.59.134]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id A085D23A01 for ; Sat, 9 Jan 2021 10:36:20 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org A085D23A01 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=gmail.com Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=merlin.20170209; h=Sender:Content-Transfer-Encoding: Content-Type:Cc:List-Subscribe:List-Help:List-Post:List-Archive: List-Unsubscribe:List-Id:MIME-Version:References:In-Reply-To:Message-Id:Date: Subject:To:From:Reply-To:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Owner; bh=xUd4Nh9cOj8kUAnEgK3X9YNQXJZsKD6IFcdjuIVW7cc=; b=KBIQSJXoT0k83PrHRxb27WqFj ksCobYtBkaEfHFk2c1i5Z0P+iXkM8ok7oYI+IXqbjLG2fVdBMiht7w+OY7E5Jkc5tFqhELF6IVH5U AqoqZ0WP3P+4Fmj5Mc6XpaVKVzjDFL124EYkpIM+b42KIJC8FTbVzZ//LwK/8pZZ3+1AVOTsa56zU NydDEPQVgSS2xZX6x6n81agqy815YeWxJXJHamYm/tm77u59I624QMXne6FUX59w40h2WweuiAS6u 3EsHfKGYNPUZ1MCIAicwPFTPPSsJaiPVksNckiOdd5Jt1ftmJ6p0dbcx4qikOrGTY4QH3uCAYiekt ytRH2AmQw==; Received: from localhost ([::1] helo=merlin.infradead.org) by merlin.infradead.org with esmtp (Exim 4.92.3 #3 (Red Hat Linux)) id 1kyBZV-00080Y-6r; Sat, 09 Jan 2021 10:34:13 +0000 Received: from mail-pj1-x1033.google.com ([2607:f8b0:4864:20::1033]) by merlin.infradead.org with esmtps (Exim 4.92.3 #3 (Red Hat Linux)) id 1kyBYn-0007ll-JX; Sat, 09 Jan 2021 10:33:31 +0000 Received: by mail-pj1-x1033.google.com with SMTP id f14so5028194pju.4; Sat, 09 Jan 2021 02:33:29 -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=UseSWNdUoIJeRRvcrg256CK7gWoiKsRB54egqsvCr3PjLc6YH6OlsSloC4u1i8b8M9 01ox1ChbLn8+L4GagHuihwa9PiZKGXgpVwjzlDKdCzJlEezoAB3W8NW4vu9GkIXEOZYn 5Um6jZVDbd5YvtsTqhNS/CrsxJdaUL2GrvSocYPZuOoLsnxp1yenTlVO3j4fZ6RaFKtv SNRTnQ/pVSiHQ9+0d+icj2rfoNJpDoGNYacHRCb0JFYiPJHMQajbEAPNrrPGiQuIBKsF R2hRacZRTO5Wr7us8uN+1JyKq9gvPlzcA/v120P9yR8iSVCGBZt69fbPpJ4/Mrlovs8N ouHg== X-Gm-Message-State: AOAM530Xpub4taD86870AnY135nartpRQl/WoeO7XOkdSjT7g343SfhW YuWLhwSe4YLv8mCdsJRyuZU= 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 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-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20210109_053329_785087_FD9DFEAD X-CRM114-Status: UNSURE ( 9.45 ) X-CRM114-Notice: Please train this message. X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: tyhicks@linux.microsoft.com, gustavoars@kernel.org, Lecopzer Chen , glider@google.com, yj.chiang@mediatek.com, robin.murphy@arm.com, andreyknvl@google.com, ardb@kernel.org, Lecopzer Chen , broonie@kernel.org, linux-mediatek@lists.infradead.org, linux@roeck-us.net, rppt@kernel.org, catalin.marinas@arm.com, aryabinin@virtuozzo.com, dan.j.williams@intel.com, vincenzo.frascino@arm.com, will@kernel.org, akpm@linux-foundation.org, dvyukov@google.com Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org 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: 12008061 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.7 required=3.0 tests=BAYES_00, DKIM_ADSP_CUSTOM_MED,DKIM_SIGNED,DKIM_VALID,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 A09F8C433DB for ; Sat, 9 Jan 2021 10:36:24 +0000 (UTC) Received: from merlin.infradead.org (merlin.infradead.org [205.233.59.134]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 6177F23A01 for ; Sat, 9 Jan 2021 10:36:24 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 6177F23A01 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=gmail.com Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=merlin.20170209; h=Sender:Content-Transfer-Encoding: Content-Type:Cc:List-Subscribe:List-Help:List-Post:List-Archive: List-Unsubscribe:List-Id:MIME-Version:References:In-Reply-To:Message-Id:Date: Subject:To:From:Reply-To:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Owner; bh=KmmhIVX37tEFsDzXkuL/WHxIy9ZAeFjMJeASyKQdH08=; b=lpfWvPWszAlcVeWt/QiAU3Wqa h/MxvO8jRENrfrHFD32J6Oxfb+nLwtXewh8IWBoMhEfe8dddieTatWbu57J1pvyJ9ET79oWpraTT3 JmfG6/Stha9zB4Xcr99SuOBEocuppiadHCprgP6xTMCKLFlNDVNWMrOqHhHG6QHtBk2uSRGE9swzk RAMYBlayNdDeRTAyJynguvllZirTJs/h4iQ/TxayLOt8e5u9d7tLGuvksn69sBJbJm6UivvmB5Yxn meKmG7Qk1fZU7wb6QdF1vSQGW/md2P8uzwbNvbq8wGuvWMTzXm6vHKG9JjNFZ0BLlvIIWSOl3NTZ1 YMRDROM/g==; Received: from localhost ([::1] helo=merlin.infradead.org) by merlin.infradead.org with esmtp (Exim 4.92.3 #3 (Red Hat Linux)) id 1kyBZf-00084b-RY; Sat, 09 Jan 2021 10:34:23 +0000 Received: from mail-pj1-x102b.google.com ([2607:f8b0:4864:20::102b]) by merlin.infradead.org with esmtps (Exim 4.92.3 #3 (Red Hat Linux)) id 1kyBYx-0007pH-7V; Sat, 09 Jan 2021 10:33:40 +0000 Received: by mail-pj1-x102b.google.com with SMTP id iq13so5034716pjb.3; Sat, 09 Jan 2021 02:33:38 -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=Gml6pL9P3iIkbtqizfhgsgtEbdWgVYTRI8AmuoIR8L4Px2TIWjW+4Rverkdh/PKXi+ h4tFzcq234aFrIHVn6zXBtni0rc8kCmyZ99/0NNfeX9/wCGwatiBrh7u3bkItbqiwv78 lSyYTQ9hjQ7lUL6IqLOriMZ6fFkIGUEheCk0prW3KcLoFV7Gtlev0jqewrR9oFabYjYy g91Z3m46otQjE+zDCPGkX7ETVtkTludCbrSGOxhBkUbGU0X31r8HfyxaDw7nnUBc1ff+ QxIM5bBNMnUhKIP4ND0DdpcfNUjv3uMck+NxPp2yo0ioeN7mAk5AHKGMsYC1Apd88BP+ S3hQ== X-Gm-Message-State: AOAM530rXHmM7hdFS7FTy1HKGQA0CpQJM5oq1Cmr7We9rGT6ZORuddi4 iV+fqoFZN0XdHgkuKSS0sxY= 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 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-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20210109_053339_494668_26E2CD0C X-CRM114-Status: GOOD ( 10.12 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: tyhicks@linux.microsoft.com, gustavoars@kernel.org, Lecopzer Chen , glider@google.com, yj.chiang@mediatek.com, robin.murphy@arm.com, andreyknvl@google.com, ardb@kernel.org, Lecopzer Chen , broonie@kernel.org, linux-mediatek@lists.infradead.org, linux@roeck-us.net, rppt@kernel.org, catalin.marinas@arm.com, aryabinin@virtuozzo.com, dan.j.williams@intel.com, vincenzo.frascino@arm.com, will@kernel.org, akpm@linux-foundation.org, dvyukov@google.com Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org 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: 12008063 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.7 required=3.0 tests=BAYES_00, DKIM_ADSP_CUSTOM_MED,DKIM_SIGNED,DKIM_VALID,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=unavailable 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 AD14CC433DB for ; Sat, 9 Jan 2021 10:36:50 +0000 (UTC) Received: from merlin.infradead.org (merlin.infradead.org [205.233.59.134]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 6FC4523A1E for ; Sat, 9 Jan 2021 10:36:50 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 6FC4523A1E Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=gmail.com Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=merlin.20170209; h=Sender:Content-Transfer-Encoding: Content-Type:Cc:List-Subscribe:List-Help:List-Post:List-Archive: List-Unsubscribe:List-Id:MIME-Version:References:In-Reply-To:Message-Id:Date: Subject:To:From:Reply-To:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Owner; bh=Z649O4c2UrgPG5hF+reN6/G7ofBPsp5w4GI+hf6szaY=; b=jH/RbYjCS3rMYAyw34QSP8Ast TZmq2ZYGuvdEPEFkR1K8c98ynqdROu/xWjnnAjAt8CRX1gmnY/eCsvF2VAIqktOUgMnLdSR4wDPgS J7FKUDiV66qG7+MF+uhR8R8XnwOeU8RUCOYt8HnR0NzD3amBj+Pq1SaHlPDE2pR57ZFacZQ/YAxwC h+TV7fODIqsFjyEbmvE2Bpq419NG9r9RyuRWTH9HKPS/KY8+XqHxxPro2qdjOZ+jUF7DptnQG9MVs aBcUU9C6HYvDPr04sT9IOfmh+eFlXZPKODFY+iPGCBN2FMjYiLlZNqEwR7sPauIx1nf7r1zhiOLIR ElcZ5FLqw==; Received: from localhost ([::1] helo=merlin.infradead.org) by merlin.infradead.org with esmtp (Exim 4.92.3 #3 (Red Hat Linux)) id 1kyBZv-0008Ba-0c; Sat, 09 Jan 2021 10:34:39 +0000 Received: from mail-pg1-x536.google.com ([2607:f8b0:4864:20::536]) by merlin.infradead.org with esmtps (Exim 4.92.3 #3 (Red Hat Linux)) id 1kyBZ5-0007sN-5n; Sat, 09 Jan 2021 10:33:49 +0000 Received: by mail-pg1-x536.google.com with SMTP id z21so9312790pgj.4; Sat, 09 Jan 2021 02:33:46 -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=EhtNLpZ4v7HU5yF+p+LJBj1jQv3ibV5DXD22xL7aa/vHGM9Ej2EVNMKJNnU+UKXZAd 9sHrry73jS5j33UbxDEuMX0QwSk84ZnpBi9doUPXffPVAbOCu8oanBRpXX10VZS0ZvxB W9whziK3eSL5beEOEK9YEQL3O/3fu1bxp1SrwWN9ixK5i1c001kWdU68W1/TRQmJT4dm 6IhuepBKX8b4rAb8fbad2QPWpDOnfkWn5Ob81tYHr++HOVCoieFGhnOotHW9V0nbm3GZ 6tfFLjBtCdwD4093EOwO16HwWYJ7nouUmfq+L5Ggkw7oI/kOq81WXYMhcjl/hrioqgT8 Qi8w== X-Gm-Message-State: AOAM531sJqxi46CIUbnzAav7SPfHlQs9DtvL8/bxjrhkoz7mskDCu5zd XmW5YUrwFEepAVS9CjfClN4= 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 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-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20210109_053348_309399_8DEBA999 X-CRM114-Status: GOOD ( 16.00 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: tyhicks@linux.microsoft.com, gustavoars@kernel.org, Lecopzer Chen , glider@google.com, yj.chiang@mediatek.com, robin.murphy@arm.com, andreyknvl@google.com, ardb@kernel.org, Lecopzer Chen , broonie@kernel.org, linux-mediatek@lists.infradead.org, linux@roeck-us.net, rppt@kernel.org, catalin.marinas@arm.com, aryabinin@virtuozzo.com, dan.j.williams@intel.com, vincenzo.frascino@arm.com, will@kernel.org, akpm@linux-foundation.org, dvyukov@google.com Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org 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. */