From patchwork Mon Jul 6 12:24:43 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Linus Walleij X-Patchwork-Id: 11645581 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 3C9BB60D for ; Mon, 6 Jul 2020 12:28:51 +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 15A3520715 for ; Mon, 6 Jul 2020 12:28:51 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=lists.infradead.org header.i=@lists.infradead.org header.b="kYgiM1jb"; dkim=fail reason="signature verification failed" (2048-bit key) header.d=linaro.org header.i=@linaro.org header.b="xrd4KBVx" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 15A3520715 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=linaro.org Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.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=ll3ZxSdFap6UkAxxSeEfdeVs2MrxsbLzyFhDcUeGBVE=; b=kYgiM1jbuVSd40/t8wc0gJKyi o+7VB0jF5PU7T8mQNT9j/Ww+xXLYzvr0tE67hoTrqyOKo3D0Mrylg/Fav+g4cK7kpuWZBC47Tid7F xd4ibEWO701nVIfpNFA3dTqS5zJGN5mWA0tqoFo6334GfNaLLU9vfZv/La2LjxXkPHtGqEfwp0LN+ 43oiJvjdL9XwOvTAwnTYsBRY/N+G0ItcrzGUC5TV7XDkDM7SlqwoXszhXm7s9Ut7XSUN7NgaSrRN3 SimYgfz+OnaBv/6lgwVEyO0+Z/WKQr25gEP8TT30gSCHuO9YjzKavxP/O1OTMnCJfcpwHcT1NYRwe PXFDiLw7g==; Received: from localhost ([::1] helo=merlin.infradead.org) by merlin.infradead.org with esmtp (Exim 4.92.3 #3 (Red Hat Linux)) id 1jsQDW-0006wa-Oj; Mon, 06 Jul 2020 12:27:26 +0000 Received: from mail-lj1-x242.google.com ([2a00:1450:4864:20::242]) by merlin.infradead.org with esmtps (Exim 4.92.3 #3 (Red Hat Linux)) id 1jsQDT-0006ul-F2 for linux-arm-kernel@lists.infradead.org; Mon, 06 Jul 2020 12:27:24 +0000 Received: by mail-lj1-x242.google.com with SMTP id h19so45076037ljg.13 for ; Mon, 06 Jul 2020 05:27:22 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=OD2fwo9UCHwSVakD8iz4327kKhLkFmPd2Kbgh3G3heE=; b=xrd4KBVxIMvCTWYXG42OgKsVisocAzX5Hak8jCf4DJnrDvpycB+k5PkoEQcmc0yse/ HzyVPqSnoKCiH1EAzZkszsf0d3E12GQ8z973MV17spo6XyDF8ta6Y7QbIzJ+0uKgoh8/ UHGSEwIt/AwaNZ/m0gcQVl/vaQolCql5rFJl5yqOas3g43368EpXnS87CFT7t41UJmfl NYjbEJPbYcw38ruR1OZs4+Awyi2Fws3xdgL3PeYtny5iHGwxaVrRRd1CVn0ySImH3zpM tM66FRf2e1BU+3dyMxTetdNyp/6jAg5ILmkoISgATGyguhapLPATRm64WqEr76Z3PU/O 8ckQ== 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=OD2fwo9UCHwSVakD8iz4327kKhLkFmPd2Kbgh3G3heE=; b=KaOKzU4iYNnvMQbcp+XAsjkVKt+ieCKqOzyd7Fd3txDIeExVxLH93dAyFPiuLgKkYR FEu6wNsQBh6xkTJEEOhrPyn2ysdNNI5J+U6GDDArbImbzMMNVBBMAvlsWSbwAAaQ4dSc KM6JbJlwa15RxYHj693IvOaYWpnk3NU/vcItjE7/RQFMkYXa99Hk/Hi1RPXZ2GrhZjoo r6OoAwDkyv8xXmCVSKKKi7Fpt/e8uBfv23TeAp5EnhsyFHNo32AUYCEpaUrpWg8hpBNj QXFM6eW5XUKgCvL/OQ0T8aqrFB067CvK1rRWhK/gnSZ9JirTgX2RiYceSwMmWbrHHfYn nWLg== X-Gm-Message-State: AOAM530pQNnLUdgUACOeNIhkPbdhtroa9wv1t92IQY62YeEL3ML914da qHQKmCbQLN4ynPm8U4FRldhN5g== X-Google-Smtp-Source: ABdhPJw2TmS4eAD+Qe2+QICaad8K4BrZTs2dOfd5XobUG3JF/9EPIX0oljKH+szt56o51qVbv2NVBw== X-Received: by 2002:a2e:3a15:: with SMTP id h21mr15191015lja.112.1594038441250; Mon, 06 Jul 2020 05:27:21 -0700 (PDT) Received: from localhost.localdomain (c-92d7225c.014-348-6c756e10.bbcust.telenor.se. [92.34.215.146]) by smtp.gmail.com with ESMTPSA id v20sm8534223lfr.74.2020.07.06.05.27.20 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 06 Jul 2020 05:27:20 -0700 (PDT) From: Linus Walleij To: Florian Fainelli , Abbott Liu , Russell King , Ard Biesheuvel , Andrey Ryabinin , Mike Rapoport Subject: [PATCH 1/5 v12] ARM: Disable KASan instrumentation for some code Date: Mon, 6 Jul 2020 14:24:43 +0200 Message-Id: <20200706122447.696786-2-linus.walleij@linaro.org> X-Mailer: git-send-email 2.25.4 In-Reply-To: <20200706122447.696786-1-linus.walleij@linaro.org> References: <20200706122447.696786-1-linus.walleij@linaro.org> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20200706_082723_641716_3C3E0C56 X-CRM114-Status: GOOD ( 19.04 ) X-Spam-Score: -0.2 (/) X-Spam-Report: SpamAssassin version 3.4.4 on merlin.infradead.org summary: Content analysis details: (-0.2 points) pts rule name description ---- ---------------------- -------------------------------------------------- -0.0 RCVD_IN_DNSWL_NONE RBL: Sender listed at https://www.dnswl.org/, no trust [2a00:1450:4864:20:0:0:0:242 listed in] [list.dnswl.org] -0.0 SPF_PASS SPF: sender matches SPF record 0.0 SPF_HELO_NONE SPF: HELO does not publish an SPF Record -0.1 DKIM_VALID Message has at least one valid DKIM or DK signature -0.1 DKIM_VALID_AU Message has a valid DKIM or DK signature from author's domain -0.1 DKIM_VALID_EF Message has a valid DKIM or DK signature from envelope-from domain 0.1 DKIM_SIGNED Message has a DKIM or DK signature, not necessarily valid 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: Arnd Bergmann , Marc Zyngier , Linus Walleij , kasan-dev@googlegroups.com, Alexander Potapenko , linux-arm-kernel@lists.infradead.org, Dmitry Vyukov Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org From: Andrey Ryabinin Disable instrumentation for arch/arm/boot/compressed/* since that code is executed before the kernel has even set up its mappings and definately out of scope for KASan. Disable instrumentation of arch/arm/vdso/* because that code is not linked with the kernel image, so the KASan management code would fail to link. Disable instrumentation of arch/arm/mm/physaddr.c. See commit ec6d06efb0ba ("arm64: Add support for CONFIG_DEBUG_VIRTUAL") for more details. Disable kasan check in the function unwind_pop_register because it does not matter that kasan checks failed when unwind_pop_register() reads the stack memory of a task. Cc: Andrey Ryabinin Cc: Alexander Potapenko Cc: Dmitry Vyukov Cc: kasan-dev@googlegroups.com Reviewed-by: Ard Biesheuvel Tested-by: Ard Biesheuvel # QEMU/KVM/mach-virt/LPAE/8G Reported-by: Florian Fainelli Reported-by: Marc Zyngier Signed-off-by: Abbott Liu Signed-off-by: Florian Fainelli Signed-off-by: Linus Walleij --- ChangeLog v11->v12: - Resend with the other changes. ChangeLog v10->v11: - Resend with the other changes. ChangeLog v9->v10: - Rebase on v5.8-rc1 ChangeLog v8->v9: - Collect Ard's tags. ChangeLog v7->v8: - Do not sanitize arch/arm/mm/mmu.c. Apart from being intuitively correct, it turns out that KASan will insert a __asan_load4() into the set_pte_at() function in mmu.c and this is something that KASan calls in the early initialization, to set up the shadow memory. Naturally, __asan_load4() cannot be called before the shadow memory is set up so we need to exclude mmu.c from sanitization. ChangeLog v6->v7: - Removed the KVM instrumentaton disablement since KVM on ARM32 is gone. --- arch/arm/boot/compressed/Makefile | 1 + arch/arm/kernel/unwind.c | 6 +++++- arch/arm/mm/Makefile | 2 ++ arch/arm/vdso/Makefile | 2 ++ 4 files changed, 10 insertions(+), 1 deletion(-) diff --git a/arch/arm/boot/compressed/Makefile b/arch/arm/boot/compressed/Makefile index 00602a6fba04..bb8d193d13de 100644 --- a/arch/arm/boot/compressed/Makefile +++ b/arch/arm/boot/compressed/Makefile @@ -24,6 +24,7 @@ OBJS += hyp-stub.o endif GCOV_PROFILE := n +KASAN_SANITIZE := n # Prevents link failures: __sanitizer_cov_trace_pc() is not linked in. KCOV_INSTRUMENT := n diff --git a/arch/arm/kernel/unwind.c b/arch/arm/kernel/unwind.c index d2bd0df2318d..f35eb584a18a 100644 --- a/arch/arm/kernel/unwind.c +++ b/arch/arm/kernel/unwind.c @@ -236,7 +236,11 @@ static int unwind_pop_register(struct unwind_ctrl_block *ctrl, if (*vsp >= (unsigned long *)ctrl->sp_high) return -URC_FAILURE; - ctrl->vrs[reg] = *(*vsp)++; + /* Use READ_ONCE_NOCHECK here to avoid this memory access + * from being tracked by KASAN. + */ + ctrl->vrs[reg] = READ_ONCE_NOCHECK(*(*vsp)); + (*vsp)++; return URC_OK; } diff --git a/arch/arm/mm/Makefile b/arch/arm/mm/Makefile index 7cb1699fbfc4..99699c32d8a5 100644 --- a/arch/arm/mm/Makefile +++ b/arch/arm/mm/Makefile @@ -7,6 +7,7 @@ obj-y := extable.o fault.o init.o iomap.o obj-y += dma-mapping$(MMUEXT).o obj-$(CONFIG_MMU) += fault-armv.o flush.o idmap.o ioremap.o \ mmap.o pgd.o mmu.o pageattr.o +KASAN_SANITIZE_mmu.o := n ifneq ($(CONFIG_MMU),y) obj-y += nommu.o @@ -16,6 +17,7 @@ endif obj-$(CONFIG_ARM_PTDUMP_CORE) += dump.o obj-$(CONFIG_ARM_PTDUMP_DEBUGFS) += ptdump_debugfs.o obj-$(CONFIG_MODULES) += proc-syms.o +KASAN_SANITIZE_physaddr.o := n obj-$(CONFIG_DEBUG_VIRTUAL) += physaddr.o obj-$(CONFIG_ALIGNMENT_TRAP) += alignment.o diff --git a/arch/arm/vdso/Makefile b/arch/arm/vdso/Makefile index d3c9f03e7e79..71d18d59bd35 100644 --- a/arch/arm/vdso/Makefile +++ b/arch/arm/vdso/Makefile @@ -42,6 +42,8 @@ GCOV_PROFILE := n # Prevents link failures: __sanitizer_cov_trace_pc() is not linked in. KCOV_INSTRUMENT := n +KASAN_SANITIZE := n + # Force dependency $(obj)/vdso.o : $(obj)/vdso.so