Received: by 2002:a05:7412:d8a:b0:e2:908c:2ebd with SMTP id b10csp2733480rdg; Mon, 16 Oct 2023 13:09:38 -0700 (PDT) X-Google-Smtp-Source: AGHT+IF086jAc271TOq5kcJ90MSuLUeHicTE5TBQYT+zJY09atGAQSEYjKPtbk7mxyEeKKa/VNZM X-Received: by 2002:a05:6a00:1796:b0:6bd:254a:8876 with SMTP id s22-20020a056a00179600b006bd254a8876mr230775pfg.23.1697486978383; Mon, 16 Oct 2023 13:09:38 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1697486978; cv=none; d=google.com; s=arc-20160816; b=F0VgcSOkQ+3Lpiobslz7LaUFfu7GlxOIUVnBSLSoAZzj0/zybUDsDTjo2xZiPTwLTh nL+hUlLVsAgMmAvlQEIPt38HkuwZh6+MF+9GF0WUGzyn1/4Olk8lUmwWrczeSgtX0B9m OAMAenGHvneInS5rDdwR+1yfYmgdZkVc3iikHwhyxf+Wx0GhsQ5z5NF35uzXp36GaDUC QgMv8rQLFS9ETk43rWoj0v/XHs9W/EeHyUqUUeHx2IqvtMCqf49aokNBBXWYrPKPjIpb RYYSJnoE5xdOyKin4ApeMD1A5CoZpdhxYLWeNLENCMMI8xyJV6PWUD0ydcbM0oLaUo8w dVeA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :message-id:date:subject:cc:to:from:dkim-signature; bh=Uo1ZehGmOuEfx6L9GXwB6nLGeI303wsPbYuWTFD2g2A=; fh=se4dObbLPf77uXKpSBaA+TzURjkN2R3/UgFS9fscKcI=; b=wDAce1rB1s6Mk4lP5lvH6u5736h9aFzuYDtpX8UWv6EkAFQxXHWmLkZJXGhvzQw9Pc kYIxRReurTf49mTEaJzoHk/z8t4adAjdT9/Ur8fDHUZmKy3Dgrm9V8bNg5lO4KwJMSJQ sD+X3mxmLilTjMRX7YvC5qKjCWIz8pY6QvRpFqEYR0pBgyEKlGocsttg5drKSy5x3MtY 5Tw1m0jklrFdvmUb2U6uBd1ApNX2qRzAndNf+yHJwD6Ra163TRYuwMuBee2yOk1ZZDXZ dTVN16n2+lL37rnA9zF7ggfzaeBou87v68s6EKsgHIsRuwkbCa63ee4X0fbmZ35AZ1zZ 9Y/Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=oWcP2frN; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.37 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from snail.vger.email (snail.vger.email. [23.128.96.37]) by mx.google.com with ESMTPS id s5-20020aa78bc5000000b0068ff659af62si484996pfd.106.2023.10.16.13.09.37 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 16 Oct 2023 13:09:38 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.37 as permitted sender) client-ip=23.128.96.37; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=oWcP2frN; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.37 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by snail.vger.email (Postfix) with ESMTP id 46C138029AE6; Mon, 16 Oct 2023 13:09:37 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at snail.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232046AbjJPUJf (ORCPT + 99 others); Mon, 16 Oct 2023 16:09:35 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:46234 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231221AbjJPUJe (ORCPT ); Mon, 16 Oct 2023 16:09:34 -0400 Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 8643C83 for ; Mon, 16 Oct 2023 13:09:33 -0700 (PDT) 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 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-4.4 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_MED, SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (snail.vger.email [0.0.0.0]); Mon, 16 Oct 2023 13:09:37 -0700 (PDT) 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 -- 2.39.2