From patchwork Mon Oct 7 05:23:40 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Melon Liu X-Patchwork-Id: 13824064 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 22986CFB440 for ; Mon, 7 Oct 2024 05:27:04 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender:List-Subscribe:List-Help :List-Post:List-Archive:List-Unsubscribe:List-Id:Content-Type:MIME-Version: Message-ID:Subject:Cc:To:From:Date:Reply-To:Content-Transfer-Encoding: Content-ID:Content-Description:Resent-Date:Resent-From:Resent-Sender: Resent-To:Resent-Cc:Resent-Message-ID:In-Reply-To:References:List-Owner; bh=324PJEeBYpJfWCK8xWbXB9A56qDSOD1jxIROj5ssz1g=; b=431suuz5bYRYwd+NaVvXgDcskj /vuRgWSAJgDaX5/pNTPAwK3rd6d7KJM59Qtcb65+8wfclJrS7kW5CefhtTvPSGoUHDWgxWcpx8O8c O4J0Tso/T03kmgWPwd7pllQ5I+zloPC5aZczgnoKhkFnqCEOfyESeIGrQ26KEzmlOFVM8XiJrBCVI wllAzpHTHQ+mioBe3CCAGW/uvFLRMVpMIj2jlpDQ3KIP0P5ZbZTckVoUgdwHA7TOPLL7U4/3AQ9VR ywcnVSIIFxv6KqyrYlq1jjP3A4jchQX5cMBOr5brRITjBqRKeSnMtWvqtz21ZGOHEWVA4UpFCP2Ef x/PbOD8w==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.98 #2 (Red Hat Linux)) id 1sxgGk-00000001JBL-1YtB; Mon, 07 Oct 2024 05:26:54 +0000 Received: from m16.mail.163.com ([220.197.31.5]) by bombadil.infradead.org with esmtp (Exim 4.98 #2 (Red Hat Linux)) id 1sxgF5-00000001J2m-2GK4 for linux-arm-kernel@lists.infradead.org; Mon, 07 Oct 2024 05:25:13 +0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=163.com; s=s110527; h=Date:From:Subject:Message-ID:MIME-Version: Content-Type; bh=324PJEeBYpJfWCK8xWbXB9A56qDSOD1jxIROj5ssz1g=; b=EkcWkra3uZT2kbTGpHZYgb7udCwytAwrTEGLutzPRkZseEfRYKfbZQLg8ZU1tk MeDPNHt1Hd8wjLQgHtEI22zJHaTWChvSByJ8W2l2+M2zC2ND/C440wemjEhFjjHU FRI3qkCyHan9TCOK8lH3pge4yGy38GAC1Bb2uKNkDMU0c= Received: from localhost (unknown [39.144.4.86]) by gzga-smtp-mtada-g0-2 (Coremail) with SMTP id _____wBnN4NccANnI_KQBQ--.20392S3; Mon, 07 Oct 2024 13:23:41 +0800 (CST) Date: Mon, 7 Oct 2024 13:23:40 +0800 From: Melon Liu To: linux@armlinux.org.uk, lecopzer.chen@mediatek.com, linus.walleij@linaro.org Cc: linux-arm-kernel@lists.infradead.org, kasan-dev@googlegroups.com, linux-kernel@vger.kernel.org, stable@vger.kernel.org Subject: [PATCH] ARM/mm: Fix stack recursion caused by KASAN Message-ID: MIME-Version: 1.0 Content-Disposition: inline X-CM-TRANSID: _____wBnN4NccANnI_KQBQ--.20392S3 X-Coremail-Antispam: 1Uf129KBjvJXoW7uw4xWFy5XFWDGr1xGF18uFg_yoW8uF1xpF 43Ca4rArsxXr1akrW3Xa18uF95t3WkK3WUt392gayrWrWUKr1UJF40qFWfu34UWrW8AFWa yFWSya45urn7t3JanT9S1TB71UUUUU7qnTZGkaVYY2UrUUUUjbIjqfuFe4nvWSU5nxnvy2 9KBjDUYxBIdaVFxhVjvjDU0xZFpf9x07joHq7UUUUU= X-Originating-IP: [39.144.4.86] X-CM-SenderInfo: ppho00irttkqqrwthudrp/xtbBhQlxIWcDZn9sZQAAso X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20241006_222512_035355_33B8CA55 X-CRM114-Status: UNSURE ( 9.34 ) X-CRM114-Notice: Please train this message. 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: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org When accessing the KASAN shadow area corresponding to the task stack which is in vmalloc space, the stack recursion would occur if the area`s page tables are unpopulated. Calltrace: ... __dabt_svc+0x4c/0x80 __asan_load4+0x30/0x88 do_translation_fault+0x2c/0x110 do_DataAbort+0x4c/0xec __dabt_svc+0x4c/0x80 __asan_load4+0x30/0x88 do_translation_fault+0x2c/0x110 do_DataAbort+0x4c/0xec __dabt_svc+0x4c/0x80 sched_setscheduler_nocheck+0x60/0x158 kthread+0xec/0x198 ret_from_fork+0x14/0x28 Fixes: 565cbaad83d ("ARM: 9202/1: kasan: support CONFIG_KASAN_VMALLOC") Cc: Signed-off-by: Melon Liu Reviewed-by: Linus Walleij --- arch/arm/mm/ioremap.c | 23 +++++++++++++++++++---- 1 file changed, 19 insertions(+), 4 deletions(-) diff --git a/arch/arm/mm/ioremap.c b/arch/arm/mm/ioremap.c index 794cfea9f..f952b0b0f 100644 --- a/arch/arm/mm/ioremap.c +++ b/arch/arm/mm/ioremap.c @@ -115,16 +115,31 @@ int ioremap_page(unsigned long virt, unsigned long phys, } EXPORT_SYMBOL(ioremap_page); +static inline void sync_pgds(struct mm_struct *mm, unsigned long start, + unsigned long end) +{ + end = ALIGN(end, PGDIR_SIZE); + memcpy(pgd_offset(mm, start), pgd_offset_k(start), + sizeof(pgd_t) * (pgd_index(end) - pgd_index(start))); +} + +static inline void sync_vmalloc_pgds(struct mm_struct *mm) +{ + sync_pgds(mm, VMALLOC_START, VMALLOC_END); + if (IS_ENABLED(CONFIG_KASAN_VMALLOC)) + sync_pgds(mm, (unsigned long)kasan_mem_to_shadow( + (void *)VMALLOC_START), + (unsigned long)kasan_mem_to_shadow( + (void *)VMALLOC_END)); +} + void __check_vmalloc_seq(struct mm_struct *mm) { int seq; do { seq = atomic_read(&init_mm.context.vmalloc_seq); - memcpy(pgd_offset(mm, VMALLOC_START), - pgd_offset_k(VMALLOC_START), - sizeof(pgd_t) * (pgd_index(VMALLOC_END) - - pgd_index(VMALLOC_START))); + sync_vmalloc_pgds(mm); /* * Use a store-release so that other CPUs that observe the * counter's new value are guaranteed to see the results of the