From mboxrd@z Thu Jan 1 00:00:00 1970 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 vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 2530EC433F5 for ; Thu, 2 Dec 2021 16:30:55 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1347974AbhLBQeN (ORCPT ); Thu, 2 Dec 2021 11:34:13 -0500 Received: from foss.arm.com ([217.140.110.172]:37560 "EHLO foss.arm.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230060AbhLBQeE (ORCPT ); Thu, 2 Dec 2021 11:34:04 -0500 Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.121.207.14]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id E490F1515; Thu, 2 Dec 2021 08:30:41 -0800 (PST) Received: from lakrids (usa-sjc-imap-foss1.foss.arm.com [10.121.207.14]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id 8067D3F73B; Thu, 2 Dec 2021 08:30:36 -0800 (PST) Date: Thu, 2 Dec 2021 16:30:30 +0000 From: Mark Rutland To: Andrey Konovalov Cc: Linux ARM , Catalin Marinas , Dmitry Vyukov , Alexander Potapenko , LKML , Andrey Ryabinin , Will Deacon Subject: Re: [PATCH 3/3] arm64: mm: log potential KASAN shadow alias Message-ID: References: <20211202112731.3346975-1-mark.rutland@arm.com> <20211202112731.3346975-4-mark.rutland@arm.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Thu, Dec 02, 2021 at 05:20:56PM +0100, Andrey Konovalov wrote: > On Thu, Dec 2, 2021 at 12:27 PM Mark Rutland wrote: > > > > When the kernel is built with KASAN_GENERIC or KASAN_SW_TAGS, shadow > > memory is allocated and mapped for all legitimate kernel addresses, and > > prior to a regular memory access instrumentation will read from the > > corresponding shadow address. > > > > Due to the way memory addresses are converted to shadow addresses, > > bogus pointers (e.g. NULL) can generate shadow addresses out of the > > bounds of allocated shadow memory. For example, with KASAN_GENERIC and > > 48-bit VAs, NULL would have a shadow address of dfff800000000000, which > > falls between the TTBR ranges. > > > > To make such cases easier to debug, this patch makes die_kernel_fault() > > recover dump the real memory address range for any potential KASAN > > shadow access. Since we can't reliably distinguish shadow accesses from > > regular accesses, we always dump this information when shadow memory is > > in use. > > @@ -297,6 +297,12 @@ static void die_kernel_fault(const char *msg, unsigned long addr, > > pr_alert("Unable to handle kernel %s at virtual address %016lx\n", msg, > > addr); > > > > +#if defined(CONFIG_KASAN_GENERIC) || defined(CONFIG_KASAN_SW_TAGS) > > + pr_alert("Possible KASAN shadow access for range [%016lx..%016lx]\n", > > + (unsigned long)kasan_shadow_to_mem((void *)addr), > > + (unsigned long)kasan_shadow_to_mem((void *)addr + 1) - 1); > > +#endif > > Hi Mark, > > There's the kasan_non_canonical_hook() function that's used on x86 for > the same purpose: adding clarity to GPF faults caused by KASAN shadow > accesses. Would it possible to reuse it for arm64? Aha! That looks like exactly what I'm after; I'll go try that for v2. Thanks for the pointer! Mark. From mboxrd@z Thu Jan 1 00:00:00 1970 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 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 smtp.lore.kernel.org (Postfix) with ESMTPS id 51DB7C433EF for ; Thu, 2 Dec 2021 16:32:06 +0000 (UTC) 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:In-Reply-To:MIME-Version:References: Message-ID:Subject:Cc:To:From:Date:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=n8jlo0w+HtEqGfCIK2MAiWlFPT3UuEV0kzLWJcN0eGs=; b=U6yt1pEFdmHkEB SjooPxoBPaQYuRSZl1o+g1M1gahBy48b6nLj6J/wizaLA6A8paXEJGPeu9hB+jXrc2NQgmhSKWqBA T2OrDbGPp5zgO+0y0K6AP3hjMeAcWdu2tg3C44vFVmFb0NIcy9jOa1WNCKNs4LphAzM5oKT3T+wmk SQaAz4f7P8l+Ack5degmAT2lrX1isEIKbObZur8gnmXH44lO5b0+SUZhy2v+qU0shfD6TW/5fiW6g Dl0454/RYWMJMCLW4Ab+uVls1o5TE9PrIo9aWvkF82+veGf6mTJnwW678+/6AOUiHF+coccHhUTlA hSrX/r4NXCih+JW7hOtQ==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1msoyr-00D24c-NN; Thu, 02 Dec 2021 16:30:45 +0000 Received: from foss.arm.com ([217.140.110.172]) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1msoyo-00D240-L9 for linux-arm-kernel@lists.infradead.org; Thu, 02 Dec 2021 16:30:44 +0000 Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.121.207.14]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id E490F1515; Thu, 2 Dec 2021 08:30:41 -0800 (PST) Received: from lakrids (usa-sjc-imap-foss1.foss.arm.com [10.121.207.14]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id 8067D3F73B; Thu, 2 Dec 2021 08:30:36 -0800 (PST) Date: Thu, 2 Dec 2021 16:30:30 +0000 From: Mark Rutland To: Andrey Konovalov Cc: Linux ARM , Catalin Marinas , Dmitry Vyukov , Alexander Potapenko , LKML , Andrey Ryabinin , Will Deacon Subject: Re: [PATCH 3/3] arm64: mm: log potential KASAN shadow alias Message-ID: References: <20211202112731.3346975-1-mark.rutland@arm.com> <20211202112731.3346975-4-mark.rutland@arm.com> MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20211202_083042_767071_DA54C1FA X-CRM114-Status: GOOD ( 20.10 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org On Thu, Dec 02, 2021 at 05:20:56PM +0100, Andrey Konovalov wrote: > On Thu, Dec 2, 2021 at 12:27 PM Mark Rutland wrote: > > > > When the kernel is built with KASAN_GENERIC or KASAN_SW_TAGS, shadow > > memory is allocated and mapped for all legitimate kernel addresses, and > > prior to a regular memory access instrumentation will read from the > > corresponding shadow address. > > > > Due to the way memory addresses are converted to shadow addresses, > > bogus pointers (e.g. NULL) can generate shadow addresses out of the > > bounds of allocated shadow memory. For example, with KASAN_GENERIC and > > 48-bit VAs, NULL would have a shadow address of dfff800000000000, which > > falls between the TTBR ranges. > > > > To make such cases easier to debug, this patch makes die_kernel_fault() > > recover dump the real memory address range for any potential KASAN > > shadow access. Since we can't reliably distinguish shadow accesses from > > regular accesses, we always dump this information when shadow memory is > > in use. > > @@ -297,6 +297,12 @@ static void die_kernel_fault(const char *msg, unsigned long addr, > > pr_alert("Unable to handle kernel %s at virtual address %016lx\n", msg, > > addr); > > > > +#if defined(CONFIG_KASAN_GENERIC) || defined(CONFIG_KASAN_SW_TAGS) > > + pr_alert("Possible KASAN shadow access for range [%016lx..%016lx]\n", > > + (unsigned long)kasan_shadow_to_mem((void *)addr), > > + (unsigned long)kasan_shadow_to_mem((void *)addr + 1) - 1); > > +#endif > > Hi Mark, > > There's the kasan_non_canonical_hook() function that's used on x86 for > the same purpose: adding clarity to GPF faults caused by KASAN shadow > accesses. Would it possible to reuse it for arm64? Aha! That looks like exactly what I'm after; I'll go try that for v2. Thanks for the pointer! Mark. _______________________________________________ linux-arm-kernel mailing list linux-arm-kernel@lists.infradead.org http://lists.infradead.org/mailman/listinfo/linux-arm-kernel