From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 36C0E2C181 for ; Sat, 3 Jan 2026 18:32:48 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1767465168; cv=none; b=tafrdFxZJsdDcoBTG6oMe9UvRnR/PlLV+ONhEpiSlPPRupcwFRByV3Ft4WPnXcYUfV+5PyXkk0Y5IyZxpChHzTqJ2gA8cDcnX2N4c3BOIDXCo4u1knMgOOMnS87mOrTgNAduBoMFh/5ea9YYjFdzkAk0t1tzYwsW1rR704zgaVQ= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1767465168; c=relaxed/simple; bh=POEHkpqzM2Kgm3O+hKTFaWkCDbY6suH1seQWUDCuBvg=; h=Date:From:To:Cc:Subject:Message-Id:In-Reply-To:References: Mime-Version:Content-Type; b=T6/NUNRjp6csRfsi4Nb/Jz9yoWDEyKGcXPNoImuXgoUe4+N+AGnz0ldPdn26i6ouKNXEr7pSHnz68xNsn5omLJmtdkfBa05DdEv97rreOL1OPU/BTCezqvf16auIEHH/uvM8NyT6TQcbP5tUfOj1gsdHFFfTuseru36bppRQDsw= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linux-foundation.org header.i=@linux-foundation.org header.b=H/ze6AGO; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linux-foundation.org header.i=@linux-foundation.org header.b="H/ze6AGO" Received: by smtp.kernel.org (Postfix) with ESMTPSA id B9E24C113D0; Sat, 3 Jan 2026 18:32:47 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linux-foundation.org; s=korg; t=1767465168; bh=POEHkpqzM2Kgm3O+hKTFaWkCDbY6suH1seQWUDCuBvg=; h=Date:From:To:Cc:Subject:In-Reply-To:References:From; b=H/ze6AGOHL2UKpgvWQ/ttEcMNhy8xDpH4nEjyXFSro+iW2tpN/qnPR/YWXuEOmAXu 6L4GquYtEkuscArkUslWJd8GVVl1Yo1H46Iynb0yUvq8ywiuFzxQ3HDrlFrmXO0VEy vuGtiYXFOsmia3yqvZAVjiEZgEjQxhUOEYal4JN8= Date: Sat, 3 Jan 2026 10:32:47 -0800 From: Andrew Morton To: Boudewijn van der Heide Cc: "Liam R . Howlett" , Alice Ryhl , Andrew Ballance , maple-tree@lists.infradead.org, linux-mm@kvack.org, linux-kernel@vger.kernel.org Subject: Re: [PATCH] maple_tree: Add dead node check in mas_dup_alloc() Message-Id: <20260103103247.9140cb2556280927b09f59d3@linux-foundation.org> In-Reply-To: <20260103165758.74094-1-boudewijn@delta-utec.com> References: <20260103165758.74094-1-boudewijn@delta-utec.com> X-Mailer: Sylpheed 3.8.0beta1 (GTK+ 2.24.33; x86_64-pc-linux-gnu) 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-Transfer-Encoding: 8bit On Sat, 3 Jan 2026 17:57:58 +0100 Boudewijn van der Heide wrote: > The __mt_dup() function is exported and can be called without internal > locking, relying on the caller to provide appropriate synchronization. > If a caller fails to hold proper locks, the source tree may be modified > concurrently, potentially resulting in dead nodes during traversal. > > The call stack is: > __mt_dup() > → mas_dup_build() > → mas_dup_alloc() [accesses node->slot[]] > > The mas_dup_alloc() function may access node slots without first > verifying that the node is still alive. If a dead node is encountered, > its memory layout may have been switched to the RCU union member, making > slot array access undefined behavior as we would be reading from the > rcu_head structure instead. > > Add an explicit dead node check to detect concurrent modification during > duplication. When a dead node is detected, return -EBUSY to indicate that > the tree is undergoing concurrent modification. > > Signed-off-by: Boudewijn van der Heide > > --- > > Build-tested and boot-tested with QEMU with Buildroot on x86_64. The > kernel booted and basic commandline operations work correctly. The race > condition this patch addresses is difficult to reproduce in testing, as > it requires concurrent tree modifications without proper locking. Thanks. What are the worst-case userspace-visible runtime effects when this happens? If they're bad then presumably we'll want to backport this fix into earlier kernels with a Cc: and, very preferably a Fixes: line.