From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 5A5AC1CBA1D for ; Tue, 15 Oct 2024 15:26:16 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=217.140.110.172 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1729005978; cv=none; b=Xs2aNKRnolVJG++Dp2TI4BA2iUcrDi811ye0Yvv8tH5DLCkI8HLFQ0AK9UR8xls8oNNMc+L4eGFnHl1u80PJR0buJdbFcX2BJMc0qfc2BXdvO0W/TqqcxR7fclRNDeex7sTdQNC3A3xWckdiljjoHxsLO+JmhzvgsuU17HRPgBk= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1729005978; c=relaxed/simple; bh=bqwtlhzJ3wh01w6QEQuywq4iwW9mt1CLvMHit2Oma5g=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=ft3ohWGzB1ggZYtNLtHiGg5fYPBXEhZKyMa2saIlf6BoVvh+ie1wR+sfllf87Lz387jOIe/iFt89JrIklFI4YCeAdMfbK6ofIGJzyva+xANO59hcJrE+u7vUZk0cSgwNX5+iEtjpB9TBAFEQ5O/ofniFZ+cF3+qLD4GVztliGxk= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=arm.com; spf=pass smtp.mailfrom=arm.com; arc=none smtp.client-ip=217.140.110.172 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=arm.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=arm.com 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 2E0FB1007; Tue, 15 Oct 2024 08:26:45 -0700 (PDT) Received: from J2N7QTR9R3.cambridge.arm.com (usa-sjc-imap-foss1.foss.arm.com [10.121.207.14]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id BBA0B3F528; Tue, 15 Oct 2024 08:26:13 -0700 (PDT) Date: Tue, 15 Oct 2024 16:26:11 +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: Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: On Tue, Oct 15, 2024 at 04:44:56PM +0200, Ard Biesheuvel wrote: > On Tue, 15 Oct 2024 at 16:35, Mark Rutland wrote: > > > > On Tue, Oct 15, 2024 at 04:22:20PM +0200, Ard Biesheuvel wrote: > > > On Tue, 15 Oct 2024 at 16:00, Mark Rutland wrote: > > > > > > > > On Tue, Oct 15, 2024 at 03:51:02PM +0200, Linus Walleij wrote: > > > > > On Tue, Oct 15, 2024 at 12:28 PM Mark Rutland wrote: > > > > > > On Mon, Oct 14, 2024 at 03:19:49PM +0200, Clement LE GOFFIC wrote: > > > > > > > > > > > I think what's happening here is that when switching from prev to next > > > > > > in the scheduler, we switch to next's mm before we actually switch to > > > > > > next's register state, and there's a transient window where prev is > > > > > > executed using next's mm. AFAICT we don't map prev's KASAN stack shadow > > > > > > into next's mm anywhere, and so inlined KASAN_STACK checks recursively > > > > > > fault on this until we switch to the overflow stack. > > > > [...] > > > > > > > Yeah it looks like a spot-on identification of the problem, I can try to > > > > > think about how we could fix this if I can reproduce it, I keep trying > > > > > to provoke the crash :/ > > > > > > > > It's a bit grotty -- AFAICT you'd either need to prefault in the > > > > specific part of the vmalloc space when switching tasks, or we'd need to > > > > preallocate all the shared vmalloc tables at the start of time so that > > > > they're always up-to-date. > > > > > > > > While we could disable KASAN_STACK, that's only going to mask the > > > > problem until this happens for any other vmalloc shadow... > > > > > > Is the other vmalloc shadow not covered by the ordinary on-demand faulting? > > > > It depends on what the vmalloc memory is used for; if it's anything else > > used in the fault handling path, that'll fault recursively, and it's > > possible that'll happen indirectly via other instrumentation. > > > > > When I implemented VMAP_STACK for ARM, I added an explicit load from > > > the new stack while still running from the old one (in __switch_to) so > > > that the ordinary faulting code can deal with it. Couldn't we do the > > > same for the vmalloc shadow of the new stack? > > > > We could do something similar, but note that it's backwards: we need to > > ensure that the old/current stack shadow will be mapped in the new mm. > > > > So the usual fault handling can't handle that as-is, because you need to > > fault-in pages for an mm which isn't yet in use. That logic could be > > factored out and shared, though. > > Not sure I follow you here. The crash is in the kernel, no? Yep; I'm referring to the vmalloc space being lazily faulted-in and copied from init_mm into the active pgd under do_translation_fault(). 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? What happens when switching between two tasks whose stacks happen to be in distinct sub-trees of the vmalloc tables? > So there is only a single vmalloc space where all the mappings should > reside, but each process has its own copy of the top level page table, > which needs to be synced up when it goes stale. Yep -- the problem is when we can safely do that syncing up, since the lazy syncing in do_translation_fault() can't safely be used to sync anything that's used during do_translation_fault(), including the stack, etc. Mark.