From patchwork Wed Oct 27 04:58:42 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alexandre Ghiti X-Patchwork-Id: 12586409 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id C5B98C433EF for ; Wed, 27 Oct 2021 04:59:12 +0000 (UTC) Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (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 7D47F610A0 for ; Wed, 27 Oct 2021 04:59:12 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.1 mail.kernel.org 7D47F610A0 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=canonical.com Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=lists.infradead.org DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version:Message-Id:Date:Subject:Cc :To:From:Reply-To:Content-ID:Content-Description:Resent-Date:Resent-From: Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:In-Reply-To:References: List-Owner; bh=oHdC5xf4QhB6HYMf5oixNhPe4enWn/KurUrEkqEbPJs=; b=XAX9GBYMjQdeDz DF3Ks/sq49i8bjmARddhiFxjcoCbu++NAV8zjJarLwO9fsNB1rzQSjhzWkyk4Jp/3w5vGr8SEhzbp +bXoXWZ/Zpvjemef+KDiuG/Og5cQVRSoOczZhu/QBqx+H1zMe+Pe4fheq2dgpECvnAXApxLBw7gPW S840GiBRvjZS2zjRmgakNvtKw0m59Kkr3VJPlZkQvyRSQjd1/+6mYTp4ly0gwJwKi2qySh8zV5aSm 16YuquoOy8JRnIr35E7qHdMfQAw6wRvSGMysmSgvC0t9W1UePq4nBV2ylWz9IcLNqNwWHpjQBRqzT c//pYqBohjOJscFkLejw==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1mfb1f-003rvy-8b; Wed, 27 Oct 2021 04:58:59 +0000 Received: from smtp-relay-internal-1.canonical.com ([185.125.188.123]) by bombadil.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1mfb1b-003rvE-Nk for linux-riscv@lists.infradead.org; Wed, 27 Oct 2021 04:58:57 +0000 Received: from mail-wm1-f69.google.com (mail-wm1-f69.google.com [209.85.128.69]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by smtp-relay-internal-1.canonical.com (Postfix) with ESMTPS id 1CE453FFF8 for ; Wed, 27 Oct 2021 04:58:48 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=canonical.com; s=20210705; t=1635310728; bh=OZLbG+qup29O7pa3I3sT9lWunjud959dueLBGLyt7Gg=; h=From:To:Cc:Subject:Date:Message-Id:MIME-Version; b=IMdq8wnNV8k/11/aeviaqlBActJziQGxwOuTl5ZpYTDx6m6Q4JqrTyLglGCyfsMpt OX1kwlsavjv/fw+LKoWYKhKuc0ZTXdiAdfKGaO8bLvqJBFiy6xYVNcGgxPUp660aG1 WFySlvX5h6Jn7eiy8v2ACOa3QhKgFCrKmhXY+GBAlEYkBxOaSHp6DTL5IwWYf2YZGY yDnsozatXjU2gB6zkVsTXbbZ9SKps7KCdP1/t1NAb8KPPkCUtjw/w8Qyj8R3J8w9jo LI/KL6J4BvL+Pm/NtMQG1pga6Eu4rehT8ENBYYHcgubcsc3wLGq1hQdrkf79zh5b8R N22nTxTMYCkOA== Received: by mail-wm1-f69.google.com with SMTP id g77-20020a1c2050000000b0032ccc05989cso704005wmg.4 for ; Tue, 26 Oct 2021 21:58:48 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=OZLbG+qup29O7pa3I3sT9lWunjud959dueLBGLyt7Gg=; b=ckiqa+KsNg/7XrSCA+t1Z97o/u+8URaWcL+fpNL8zsm6RFzblkPAqGz7mLXbG5TeQe mZwWhI3MkPs5QEgV7uyGi8gKoDM3nyhRc/co+UBdo5wI7YCXOZESY4qh+6QxatLPBoD1 CHWMS8hJwaFJ18X/RoGqFJEkgVAp7LQK0ATV/vpJeMqbkONWuFFu8ShPnHS3JxLOOO8k y+PEg7emVJQtRe51LH6t49SFYpFQlm94gVvUTvMjHabKU9vFNmml+pv9RHE1bG/wMNgX 1e+r+8DRynuRB4qTFFb4GWh83ngCA0IOYb3FxT0DiN2LF5+nnRO28tWUh62+/tnVnEn6 Z2pg== X-Gm-Message-State: AOAM531Qy0LffVbHTIcNE3w3GpZ9/t1w/1FmYVl4AjW0qc4w+bgxvgWZ UWoolhjpbKZMKPX45xNE7DfR8LzMxspIyAGLFQWEflhJk2Skyq3H2GvC9oah1CV04gqR/8mkAfQ +V4pq84kVVW9nlIndEbF/CHOqXNXDd+J/HLI4fjW2bWYZ9w== X-Received: by 2002:a1c:e911:: with SMTP id q17mr3260833wmc.174.1635310727617; Tue, 26 Oct 2021 21:58:47 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwg7IteDGRbP/J7J7K13Z6DV5E7wAMFK7YSWsyBJTzgY5coRfA+N5jl6QLw37giV6SMkvlgDw== X-Received: by 2002:a1c:e911:: with SMTP id q17mr3260825wmc.174.1635310727489; Tue, 26 Oct 2021 21:58:47 -0700 (PDT) Received: from alex.home (lfbn-lyo-1-470-249.w2-7.abo.wanadoo.fr. [2.7.60.249]) by smtp.gmail.com with ESMTPSA id o1sm11775586wru.91.2021.10.26.21.58.46 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 26 Oct 2021 21:58:47 -0700 (PDT) From: Alexandre Ghiti To: Paul Walmsley , Palmer Dabbelt , Albert Ou , Andrey Ryabinin , Alexander Potapenko , Andrey Konovalov , Dmitry Vyukov , linux-riscv@lists.infradead.org, linux-kernel@vger.kernel.org, kasan-dev@googlegroups.com Cc: Alexandre Ghiti , Nathan Chancellor Subject: [PATCH 1/2] riscv: Fix asan-stack clang build Date: Wed, 27 Oct 2021 06:58:42 +0200 Message-Id: <20211027045843.1770770-1-alexandre.ghiti@canonical.com> X-Mailer: git-send-email 2.30.2 MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20211026_215855_950655_A8D2BEE5 X-CRM114-Status: GOOD ( 12.83 ) X-BeenThere: linux-riscv@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-riscv" Errors-To: linux-riscv-bounces+linux-riscv=archiver.kernel.org@lists.infradead.org Nathan reported that because KASAN_SHADOW_OFFSET was not defined in Kconfig, it prevents asan-stack from getting disabled with clang even when CONFIG_KASAN_STACK is disabled: fix this by defining the corresponding config. Reported-by: Nathan Chancellor Signed-off-by: Alexandre Ghiti --- arch/riscv/Kconfig | 6 ++++++ arch/riscv/include/asm/kasan.h | 3 +-- arch/riscv/mm/kasan_init.c | 3 +++ 3 files changed, 10 insertions(+), 2 deletions(-) diff --git a/arch/riscv/Kconfig b/arch/riscv/Kconfig index c1abbc876e5b..79250b1ed54e 100644 --- a/arch/riscv/Kconfig +++ b/arch/riscv/Kconfig @@ -162,6 +162,12 @@ config PAGE_OFFSET default 0xffffffff80000000 if 64BIT && MAXPHYSMEM_2GB default 0xffffffe000000000 if 64BIT && MAXPHYSMEM_128GB +config KASAN_SHADOW_OFFSET + hex + depends on KASAN_GENERIC + default 0xdfffffc800000000 if 64BIT + default 0xffffffff if 32BIT + config ARCH_FLATMEM_ENABLE def_bool !NUMA diff --git a/arch/riscv/include/asm/kasan.h b/arch/riscv/include/asm/kasan.h index a2b3d9cdbc86..b00f503ec124 100644 --- a/arch/riscv/include/asm/kasan.h +++ b/arch/riscv/include/asm/kasan.h @@ -30,8 +30,7 @@ #define KASAN_SHADOW_SIZE (UL(1) << ((CONFIG_VA_BITS - 1) - KASAN_SHADOW_SCALE_SHIFT)) #define KASAN_SHADOW_START KERN_VIRT_START #define KASAN_SHADOW_END (KASAN_SHADOW_START + KASAN_SHADOW_SIZE) -#define KASAN_SHADOW_OFFSET (KASAN_SHADOW_END - (1ULL << \ - (64 - KASAN_SHADOW_SCALE_SHIFT))) +#define KASAN_SHADOW_OFFSET _AC(CONFIG_KASAN_SHADOW_OFFSET, UL) void kasan_init(void); asmlinkage void kasan_early_init(void); diff --git a/arch/riscv/mm/kasan_init.c b/arch/riscv/mm/kasan_init.c index d7189c8714a9..8175e98b9073 100644 --- a/arch/riscv/mm/kasan_init.c +++ b/arch/riscv/mm/kasan_init.c @@ -17,6 +17,9 @@ asmlinkage void __init kasan_early_init(void) uintptr_t i; pgd_t *pgd = early_pg_dir + pgd_index(KASAN_SHADOW_START); + BUILD_BUG_ON(KASAN_SHADOW_OFFSET != + KASAN_SHADOW_END - (1UL << (64 - KASAN_SHADOW_SCALE_SHIFT))); + for (i = 0; i < PTRS_PER_PTE; ++i) set_pte(kasan_early_shadow_pte + i, mk_pte(virt_to_page(kasan_early_shadow_page), From patchwork Wed Oct 27 04:58:43 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alexandre Ghiti X-Patchwork-Id: 12586411 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id CBB55C433F5 for ; Wed, 27 Oct 2021 05:00:04 +0000 (UTC) Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (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 8258B610A0 for ; Wed, 27 Oct 2021 05:00:04 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.1 mail.kernel.org 8258B610A0 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=canonical.com Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=lists.infradead.org DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version:References:In-Reply-To: Message-Id:Date:Subject:Cc:To:From:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=kC26ojYNgGPDsKFKfXmAVoaIFqXqkJU0WcDUs+9/0+w=; b=am23Th/dHls33v YuI7ojxeVLhZrASitO2z7N3IrPtO4qoOHc1RU0Svs0Jiq2dd7OZ5yz55AiYyw+C/pLNKkGTTZio5V iVaI5uVFzLjWROkr8Fd04jyfFOxXKY/bwqcHoPyS6gtdmzQ1GM0u5HJ3wjgQAblLSkL9T8PVkw8Ek Zk6/MrBpaYXVKm640zJZQsdzZZ75lE2nuAWNXBH1R6qWgfzNVZF28A9kA6xoDDYpPi9s1CGxaEp2H g8gfirKSLxUuOltvUT1vdoLhPv120+iRh2qpos29lLER3OxJAT/2deBted+YrX1vAlnYe45IheDJz J0daGlC55WAWtgSqLoDQ==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1mfb2Y-003s07-1H; Wed, 27 Oct 2021 04:59:54 +0000 Received: from smtp-relay-internal-1.canonical.com ([185.125.188.123]) by bombadil.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1mfb2U-003rz0-6d for linux-riscv@lists.infradead.org; Wed, 27 Oct 2021 04:59:52 +0000 Received: from mail-wm1-f70.google.com (mail-wm1-f70.google.com [209.85.128.70]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by smtp-relay-internal-1.canonical.com (Postfix) with ESMTPS id 0663D3FFFB for ; Wed, 27 Oct 2021 04:59:49 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=canonical.com; s=20210705; t=1635310789; bh=LTVtpyKftoE0IH0g/BXOTfVkolo16F3nizMPYgvUIg8=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=c1yrvb6RM5aoDZ7D5pEMLP2ieBb2cD0sHvRMkAiXJGIzQAm3xDgdaNUAvgyNsKSEm eYo9XDtPGsV+g8xB5RFyCkYkuOgAOVvPyPJM+Y+hKl3O1Tx2oa982/qwvoReEtd4pR sPBbxycUgUHN9AGe1H5vuVTbrk735Q1ekWwRTA/0TJdMv3kOKF4V0vQR3J5wbf3IAq Vyhkugrijtk1LRwF+lSut6SleKQrFiSC4eFtDVMZhveDfakGz1u7MaacxIIYlps0Vu h8ETJLhKVnFr2+z1D/R3XWKvZL7oR18uegrFNYETIySQlG6YZLx0gJB/1fTGmUuar8 kHUwLqV761OsQ== Received: by mail-wm1-f70.google.com with SMTP id u14-20020a05600c19ce00b0030d8549d49aso1360309wmq.0 for ; Tue, 26 Oct 2021 21:59:49 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=LTVtpyKftoE0IH0g/BXOTfVkolo16F3nizMPYgvUIg8=; b=BuwsyZJNHsn/xGvBh4EUmRawBnDZBvyHM7uNrJpNCuHmIUYFznfcOEXQlQdU2BwUSs 46xKFlPHAXTkInSC78OgBiglgCmuk1MFLYz3SrqiSOQOU5baqiSeWH/SuzYQlMM9S7iN d3KQk4Y4KYX4OmUlbx5MpSRFWxtrhT9FyPg3rd13/k8qMpPbhgkPrILt4/sM/MQ/XbN1 Sc7lBE637UL9BQ8KF+4i1fei9afifjgPiPPEE6r2MgZUtyAoiiBHyzmfOtSXa4hMKrfE /cdEekwQgbeKkfC6jnuF+/KMyQvQZTbORVcEyhBKD676B9ICUgltMaJUtlErhfMXdnfc +G8Q== X-Gm-Message-State: AOAM531b+zAVy655abnNBJBeZOdVsidg7n1zs0iTbkP6J9lTxjitIiJI v9vYkqmJQ7uBwm/UUczBEW5NSBD1k4k3PcK9Er0HyshTAPUu7Xj6WU6tWVrQmUs4cnmAlzbFpsO xl4cPvR4iVVQBuola1jJO0nVNwQsrmi4LWdIUqG73d1Ve7w== X-Received: by 2002:a7b:ce93:: with SMTP id q19mr3460073wmj.98.1635310788755; Tue, 26 Oct 2021 21:59:48 -0700 (PDT) X-Google-Smtp-Source: ABdhPJy8O7sqkwoLrKnw5Xt6p5dLSckvr1ImPBad0sPPzwGeWPQZemV8X1dl0PrG0R5bBdfsawaeAA== X-Received: by 2002:a7b:ce93:: with SMTP id q19mr3460062wmj.98.1635310788623; Tue, 26 Oct 2021 21:59:48 -0700 (PDT) Received: from alex.home (lfbn-lyo-1-470-249.w2-7.abo.wanadoo.fr. [2.7.60.249]) by smtp.gmail.com with ESMTPSA id c15sm20432877wrs.19.2021.10.26.21.59.48 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 26 Oct 2021 21:59:48 -0700 (PDT) From: Alexandre Ghiti To: Paul Walmsley , Palmer Dabbelt , Albert Ou , Andrey Ryabinin , Alexander Potapenko , Andrey Konovalov , Dmitry Vyukov , linux-riscv@lists.infradead.org, linux-kernel@vger.kernel.org, kasan-dev@googlegroups.com Cc: Alexandre Ghiti Subject: [PATCH 2/2] riscv: Fix CONFIG_KASAN_STACK build Date: Wed, 27 Oct 2021 06:58:43 +0200 Message-Id: <20211027045843.1770770-2-alexandre.ghiti@canonical.com> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20211027045843.1770770-1-alexandre.ghiti@canonical.com> References: <20211027045843.1770770-1-alexandre.ghiti@canonical.com> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20211026_215950_400015_4DC37B3C X-CRM114-Status: GOOD ( 13.11 ) X-BeenThere: linux-riscv@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-riscv" Errors-To: linux-riscv-bounces+linux-riscv=archiver.kernel.org@lists.infradead.org Now that CONFIG_KASAN_SHADOW_OFFSET is correctly defined, the boot hung while populating the shadow memory right after the call to kasan_populate_early_shadow: when calling this function, all the shadow memory is already populated with kasan_early_shadow_pte which has PAGE_KERNEL protection. kasan_populate_early_shadow write-protects the mapping of the range of addresses passed in argument in zero_pte_populate, which actually write-protects all the shadow memory mapping since kasan_early_shadow_pte is used for all the shadow memory at this point. And then when using memblock API to populate the shadow memory, the first write access to the kernel stack triggers a trap. We already manually populate all the shadow memory in kasan_early_init and we write-protect kasan_early_shadow_pte at the end of kasan_init which makes the call to kasan_populate_early_shadow superfluous so we can remove it. Signed-off-by: Alexandre Ghiti --- arch/riscv/mm/kasan_init.c | 7 ------- 1 file changed, 7 deletions(-) diff --git a/arch/riscv/mm/kasan_init.c b/arch/riscv/mm/kasan_init.c index 8175e98b9073..8df937902630 100644 --- a/arch/riscv/mm/kasan_init.c +++ b/arch/riscv/mm/kasan_init.c @@ -175,13 +175,6 @@ void __init kasan_init(void) phys_addr_t p_start, p_end; u64 i; - /* - * Populate all kernel virtual address space with kasan_early_shadow_page - * except for the linear mapping and the modules/kernel/BPF mapping. - */ - kasan_populate_early_shadow((void *)KASAN_SHADOW_START, - (void *)kasan_mem_to_shadow((void *) - VMEMMAP_END)); if (IS_ENABLED(CONFIG_KASAN_VMALLOC)) kasan_shallow_populate( (void *)kasan_mem_to_shadow((void *)VMALLOC_START),