From patchwork Mon Oct 16 20:08:38 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Arnd Bergmann X-Patchwork-Id: 13424073 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 kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id D5588CDB482 for ; Mon, 16 Oct 2023 20:09:39 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 68E5180028; Mon, 16 Oct 2023 16:09:39 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 63E9880008; Mon, 16 Oct 2023 16:09:39 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 5066680028; Mon, 16 Oct 2023 16:09:39 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0010.hostedemail.com [216.40.44.10]) by kanga.kvack.org (Postfix) with ESMTP id 3DCF180008 for ; Mon, 16 Oct 2023 16:09:39 -0400 (EDT) Received: from smtpin30.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay05.hostedemail.com (Postfix) with ESMTP id 1ED6340AA7 for ; Mon, 16 Oct 2023 20:09:39 +0000 (UTC) X-FDA: 81352414878.30.513B049 Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by imf30.hostedemail.com (Postfix) with ESMTP id 78C948000F for ; Mon, 16 Oct 2023 20:09:37 +0000 (UTC) Authentication-Results: imf30.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20201202 header.b=oWcP2frN; spf=pass (imf30.hostedemail.com: domain of arnd@kernel.org designates 139.178.84.217 as permitted sender) smtp.mailfrom=arnd@kernel.org; dmarc=pass (policy=none) header.from=kernel.org ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1697486977; a=rsa-sha256; cv=none; b=mHFfFbG4XpaVLha9Jv8x+dPGtLGqLNQA2I+kI/FGKx7lzhM5CsECMb/u9s3DCa+fyB9Glp LlMhbqXRz4z89Qbvph0z8njoPCnZC0AOBU1HhvjvyOsW4Ym4x/IxPP+Hl4sBdpS8IT826l dEZPv1K0sjQop8FbHtjefte73bqapYw= ARC-Authentication-Results: i=1; imf30.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20201202 header.b=oWcP2frN; spf=pass (imf30.hostedemail.com: domain of arnd@kernel.org designates 139.178.84.217 as permitted sender) smtp.mailfrom=arnd@kernel.org; dmarc=pass (policy=none) header.from=kernel.org ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1697486977; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-transfer-encoding:content-transfer-encoding: in-reply-to:references:dkim-signature; bh=Uo1ZehGmOuEfx6L9GXwB6nLGeI303wsPbYuWTFD2g2A=; b=WpADN4c/7lGRoiUcCp5WxM5aqpe4Q/unpgqsdH9p6iIKvgApjjGhwhPiHa4GMZf7gMAyIE Iz8/aFpogGlwiBgzQj9f4wExfX01hZz+NpoFzceFRZ5xCn+565bNlsyBq3ZAxYF1mkmwtr rl3MnDQ9EglqMPptu7s9hdFMtrIVhs4= Received: from smtp.kernel.org (transwarp.subspace.kernel.org [100.75.92.58]) by dfw.source.kernel.org (Postfix) with ESMTP id E9EC060F6E; Mon, 16 Oct 2023 20:09:35 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 8126CC433C8; Mon, 16 Oct 2023 20:09:30 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1697486973; bh=RpFwpEjjw4hJ7B1Z4cK20onhtIjTiNBnDbHOS4Sy1JE=; h=From:To:Cc:Subject:Date:From; b=oWcP2frNFRtqkU/QYvUgGpWLjWYPq0lsoHhihsZ1pOUX6Cr16FU6g+uKDzgIlYX3V 09KzDJxwrhdlo3/I/9/JJJIiWp0XKjlIhY5auTT7g4PeKHjIZLAdhk51KN/1cvECG1 9iYjs4hxQCqNFZuAexRg/8dZHQEC1kJb+dDsLu2SYNTDOFjrQL+Sb+HkL4aHhv1+nG 0zvLGTIQ/Vi/PTqJ+C3tQzPlkxibOk9++gXWlCDt0wwFPau/aKF8SoZADD44RmQJBY QuvTAn1Lk9lns/PNLOnjMDvakyGN4CebvOPL50wFy2Lx+6TeJ7LYRMAhJTK6f3G6yQ H9Nj7nV8TJSAg== From: Arnd Bergmann To: Andrey Ryabinin , Andrew Morton , Andrey Konovalov , Haibo Li Cc: Arnd Bergmann , Alexander Potapenko , Dmitry Vyukov , Vincenzo Frascino , Kees Cook , kasan-dev@googlegroups.com, linux-kernel@vger.kernel.org, linux-mm@kvack.org Subject: [PATCH] kasan: disable kasan_non_canonical_hook() for HW tags Date: Mon, 16 Oct 2023 22:08:38 +0200 Message-Id: <20231016200925.984439-1-arnd@kernel.org> X-Mailer: git-send-email 2.39.2 MIME-Version: 1.0 X-Rspamd-Server: rspam08 X-Rspamd-Queue-Id: 78C948000F X-Stat-Signature: uc1ibo1xffmazds9u8yhem15xjjhozys X-Rspam-User: X-HE-Tag: 1697486977-120629 X-HE-Meta: U2FsdGVkX19RDc3WYJ3/N0tI80bqhndXE8leFfHy3nE0C12piNzzcyO/aLitb4pQqqbHyo0G7cjY/rLMrL9e5soy6WbOZghy85EYe75yjXddZDjOSVLx+PCByZVACRfKL3t1sYDeWLxNl5/07vxl/ApPWzVqG5qRGkksnZO1JYePh1CbdtKbDgrQjgkDCR07II2xU/njMDK12ZDpQmW3oPlS4zu679krhpOnXvR/kxcKOsqDuwVWmWtyDVL4nojEyMMMNCzf3ZiP1PI+Gz/L8spF79u+Atm6AUC7bGI1Zc2nXATe1mSHrBiFgB4+3yn1NwRVzB9STicT6wARfBahienItnRKMVskgnnh2UgzIeHqLLQ+cZYSU4qlpp4hM4V478D1GGzLFxPDJAG0n0My7aCHVxs0b9JuhLl+dU6KF6z+dVY8WJ/v6cYT5pYbV3lyMqJtqpk5aoV+wPpBXuOrqwO071v/o6qBwWdTgaBeqJmjOcDBpSXa0Eqe0Tx49FuCE1D1iphqt7kGrVYr38CkxSYeBsyKXkOICYFt6epWaedKw/HDAX8U70b3c7+njH0vdd/fWuc12Lmsy2CVW6PiXIgXbxwfPaxy7JxtgM6AlETgZNDlEjT/o3H+IGb/92G8pQv5ZN40TXfR1CvSXmF1iZ4H7jdoZXAMtGYF/YhJAorAHsPKHDSO8wpsDWlM//01brvUEpZUh0HOfKpnQFqe0EztPFW7zyY+WoDefQyXoiFmzZLX++yTh7K17j5FTD+/Wa0xoIKlVUs9Ah/dJxgP2xv8Ea+ZgRd8XD3yRwlB5as8//Ech2L8I2mo3ofj/kxJYPXdfRHkH9+AO5SFuMw3J0WhSeYep05WmbaUlIEqK5rYknf04k1Pd/amsrtj8DrRT1+Bkuu6Ble/cd53nxCMNY1MLjLFE3CgLrMkRsEHt96oCuYDR9fYZf//hqL8KLSyoaYisoGSiAeEtl8ZLft AiAlBOOE Is06a17lDrzjUSIV0PESLhcqTQrBiqh6FRhdYp9Ez4RyBkeOtJk9lGuelV8vFWYhDO/tjSEfLnQ4qEhATMTEcbGtaOPUm7FgPRNO24mJm79bgIXDvQwgewv7YhKol1vw04hikgvfaGEIh3i4f0X7hTZ1fBJOBCaJXf422sAhu3LFWIIgKUfclgx11gJCvL8f+ebPJJK063a4kTiab5UL9e8TZyaamlwoCAaayz4oBfkrCwgwfYxN2b7If8Fy+40PxNIh3tA7mPOjEk5see/azjM4QclU1m11aJqLbUMljkEHft78= 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: From: Arnd Bergmann On arm64, building with CONFIG_KASAN_HW_TAGS now causes a compile-time error: mm/kasan/report.c: In function 'kasan_non_canonical_hook': mm/kasan/report.c:637:20: error: 'KASAN_SHADOW_OFFSET' undeclared (first use in this function) 637 | if (addr < KASAN_SHADOW_OFFSET) | ^~~~~~~~~~~~~~~~~~~ mm/kasan/report.c:637:20: note: each undeclared identifier is reported only once for each function it appears in mm/kasan/report.c:640:77: error: expected expression before ';' token 640 | orig_addr = (addr - KASAN_SHADOW_OFFSET) << KASAN_SHADOW_SCALE_SHIFT; This was caused by removing the dependency on CONFIG_KASAN_INLINE that used to prevent this from happening. Use the more specific dependency on KASAN_SW_TAGS || KASAN_GENERIC to only ignore the function for hwasan mode. Fixes: 12ec6a919b0f ("kasan: print the original fault addr when access invalid shadow") Signed-off-by: Arnd Bergmann --- It looks like the comment above the function needs to be adjusted as well, and it's possible we should still provide it even for hwasan but fix it in a different way. I saw this a few days ago but didn't actually send the patch right away, so there is a good chance that someone has already produced a better patch, just ignore my report in that case. --- include/linux/kasan.h | 6 +++--- mm/kasan/report.c | 4 +++- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/include/linux/kasan.h b/include/linux/kasan.h index 485452e8cc0dc..72cb693b075b7 100644 --- a/include/linux/kasan.h +++ b/include/linux/kasan.h @@ -468,10 +468,10 @@ static inline void kasan_free_module_shadow(const struct vm_struct *vm) {} #endif /* (CONFIG_KASAN_GENERIC || CONFIG_KASAN_SW_TAGS) && !CONFIG_KASAN_VMALLOC */ -#ifdef CONFIG_KASAN +#if defined(CONFIG_KASAN_GENERIC) || defined(CONFIG_KASAN_SW_TAGS) void kasan_non_canonical_hook(unsigned long addr); -#else /* CONFIG_KASAN */ +#else /* CONFIG_KASAN_GENERIC || CONFIG_KASAN_SW_TAGS */ static inline void kasan_non_canonical_hook(unsigned long addr) { } -#endif /* CONFIG_KASAN */ +#endif /* CONFIG_KASAN_GENERIC || CONFIG_KASAN_SW_TAGS */ #endif /* LINUX_KASAN_H */ diff --git a/mm/kasan/report.c b/mm/kasan/report.c index b738be3b6e5cc..e77facb629007 100644 --- a/mm/kasan/report.c +++ b/mm/kasan/report.c @@ -621,8 +621,9 @@ void kasan_report_async(void) } #endif /* CONFIG_KASAN_HW_TAGS */ +#if defined(CONFIG_KASAN_GENERIC) || defined(CONFIG_KASAN_SW_TAGS) /* - * With CONFIG_KASAN, accesses to bogus pointers (outside the high + * With CONFIG_KASAN_INLINE, accesses to bogus pointers (outside the high * canonical half of the address space) cause out-of-bounds shadow memory reads * before the actual access. For addresses in the low canonical half of the * address space, as well as most non-canonical addresses, that out-of-bounds @@ -658,3 +659,4 @@ void kasan_non_canonical_hook(unsigned long addr) pr_alert("KASAN: %s in range [0x%016lx-0x%016lx]\n", bug_type, orig_addr, orig_addr + KASAN_GRANULE_SIZE - 1); } +#endif