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 DB971D1AD2E for ; Wed, 16 Oct 2024 09:00:09 +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:In-Reply-To:Content-Type: MIME-Version:References: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:List-Owner; bh=eW2Jbg3nlnX7I5JH3mEfcDGQV5DPyPH8vsQabfEjuW8=; b=ZF4YPVxL5pQnQOhHuu1/fbtwA+ tvxMQysjE0k80CnajhKSJQxIFGDgpJS95EhDRLJE11mOTaoS4NoJG92FPXMt9/IMsfG5CcmBh/DzU hbyFnUdFErNTT8+QQV9xzNBrhGXfkgJSRFOAL4GgubKC//ExBX9eQisqwDILA5mzLyyXIULoXajDY CMNOm+k3eP/Nz7cxGM3JYpJoX0ItYCQdqDCNf0GFlYfZtmiV71nP6Ol22PBVs/kPFoFGaL5tY3gSO 6/mKA0SAu/pupIJDnI6crWWuszBFlwvk4LvqhvnlBGGoeyAd6Xxw25XSYfcj5GMYj0cREIQEOPxwy Oe/+QL+Q==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.98 #2 (Red Hat Linux)) id 1t0zsr-0000000B8fi-34c6; Wed, 16 Oct 2024 08:59:57 +0000 Received: from foss.arm.com ([217.140.110.172]) by bombadil.infradead.org with esmtp (Exim 4.98 #2 (Red Hat Linux)) id 1t0zov-0000000B7i1-0KUd for linux-arm-kernel@lists.infradead.org; Wed, 16 Oct 2024 08:55:54 +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 465ADFEC; Wed, 16 Oct 2024 01:56:19 -0700 (PDT) Received: from J2N7QTR9R3 (usa-sjc-imap-foss1.foss.arm.com [10.121.207.14]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id 04EAC3F528; Wed, 16 Oct 2024 01:55:47 -0700 (PDT) Date: Wed, 16 Oct 2024 09:55:38 +0100 From: Mark Rutland To: Ard Biesheuvel Cc: Linus Walleij , Clement LE GOFFIC , Russell King , "Russell King (Oracle)" , Kees Cook , AngeloGioacchino Del Regno , Mark Brown , linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, linux-stm32@st-md-mailman.stormreply.com, Antonio Borneo Subject: Re: Crash on armv7-a using KASAN Message-ID: References: MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20241016_015553_231029_E18AAD9E X-CRM114-Status: GOOD ( 27.01 ) 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 On Tue, Oct 15, 2024 at 07:28:06PM +0200, Ard Biesheuvel wrote: > On Tue, 15 Oct 2024 at 18:27, Mark Rutland wrote: > > > > On Tue, Oct 15, 2024 at 06:07:00PM +0200, Ard Biesheuvel wrote: > > > On Tue, 15 Oct 2024 at 17:26, Mark Rutland wrote: > > > > Looking some more, I don't see how VMAP_STACK guarantees that the > > > > old/active stack is mapped in the new mm when switching from the old mm > > > > to the new mm (which happens before __switch_to()). > > > > > > > > Either I'm missing something, or we have a latent bug. Maybe we have > > > > some explicit copying/prefaulting elsewhere I'm missing? > > > > > > We bump the vmalloc_seq counter for that. Given that the top-level > > > page table can only gain entries covering the kernel space, this > > > should be sufficient for the old task's stack to be mapped in the new > > > task's page tables. > > > > Ah, yep -- I had missed that. Thanks for the pointer! > > > > From a superficial look, it sounds like it should be possible to extend > > that to also handle the KASAN shadow of the vmalloc area (which > > __check_vmalloc_seq() currently doesn't copy), but I'm not sure of > > exactly when we initialise the shadow for a vmalloc allocation relative > > to updating vmalloc_seq. > > > > Indeed. It appears both vmalloc_seq() and arch_sync_kernel_mappings() > need to take the vmalloc shadow into account specifically. And we may > also need the dummy read from the stack's shadow in __switch_to - I am > pretty sure I added that for a reason. I believe that's necessary for the lazy TLB switch, at least for SMP: // CPU 0 // CPU 1 << switches to task X's mm >> << creates kthread task Y >> << maps task Y's new stack >> << maps task Y's new shadow >> // Y switched out context_switch(..., Y, ..., ...); // Switch from X to Y context_switch(..., X, Y, ...) { // prev = X // next = Y if (!next->mm) { // Y has no mm // No switch_mm() here // ... so no check_vmalloc_seq() } else { // not taken } ... // X's mm still lacks Y's stack + shadow here switch_to(prev, next, prev); } ... so probably worth a comment that we're faulting in the new stack+shadow for for lazy tlb when switching to a task with no mm? In the lazy tlb case the current/old mappings don't disappear from the active mm, and so we don't need to go add those to the new mm, which is what we need check_vmalloc_seq() for. Mark.