From nobody Sun Feb 8 16:35:54 2026 Received: from mail-ed1-f47.google.com (mail-ed1-f47.google.com [209.85.208.47]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 259E12248A5 for ; Sat, 3 Jan 2026 16:58:18 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.208.47 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1767459502; cv=none; b=tJvji9ZWh2ECs9U7xbvt9IpbNz4vnVoJ5SYre3lqpLWlzsTYMhw5hz35O5q7DTG7UcgnDqBODgSl5b59qRCLCRqxhY3Gx6AOtQpOP5JCLXe3UH5360Xr4KlCJ/t8Un6qCVogHPC0+3B2h2FktyHp0DR/BunqH5FJKyzr/hFOEDE= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1767459502; c=relaxed/simple; bh=Oe4A4xMV2CK0X/XnMRaU8IMmmLd+lfhjwkFulf3SUuw=; h=From:To:Cc:Subject:Date:Message-ID:MIME-Version:Content-Type; b=RgzEJxXWMZ7b5WfUbx4Svu3TgB/xYEt90iZxLkPb4CGqLxB6IJBTE3VevLUMNOhv2EktObKcJinWL6ktGdpi/Cx6j5TqVAKyq6/vbZtHFcqC/VHmVi+4+L3AIi1BLjqUzVRYkMpgDLzj3BB8pc6cn24iXlzIj8BDrG96TVkSTHA= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=delta-utec.com; spf=none smtp.mailfrom=delta-utec.com; dkim=pass (2048-bit key) header.d=delta-utec-com.20230601.gappssmtp.com header.i=@delta-utec-com.20230601.gappssmtp.com header.b=i6GS8yxd; arc=none smtp.client-ip=209.85.208.47 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=delta-utec.com Authentication-Results: smtp.subspace.kernel.org; spf=none smtp.mailfrom=delta-utec.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=delta-utec-com.20230601.gappssmtp.com header.i=@delta-utec-com.20230601.gappssmtp.com header.b="i6GS8yxd" Received: by mail-ed1-f47.google.com with SMTP id 4fb4d7f45d1cf-64b9cb94ff5so16403996a12.2 for ; Sat, 03 Jan 2026 08:58:18 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=delta-utec-com.20230601.gappssmtp.com; s=20230601; t=1767459497; x=1768064297; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:from:to:cc:subject:date:message-id:reply-to; bh=9j+lytdvFaQc0rDMkV0fSvoJ/5Wk5aT873gsJML9tGo=; b=i6GS8yxdqavAlKHIxNz2R3NGe2dT8pRutqDK24edJtEMl+MTQpSAPd24SfJb9BSQqB rJ+GMLqAsVIclhGtTkDqD4ncAleiJMM0a1B1oXjgIEDnV5+9N44z8ZyKhlFwkZ44FcL7 qT+96W2lE+taCL4yigIDoV7UIMR8cptmYcF4SOvsJJCsy2zWkVMO5YY8IJPv55jYzVS2 ZTmpwhEWR+ZOMjzB1XtB3YUc3pXIMLqfMuqZ5JytnIitCRRc+5tNseA+wbQIXV66Ypby GI/j0oG8Ov43tEDcgCsFPbgZQDuH1NpKnJ4UPPPKlQFQGjTwIIWNbs3zIMFsQ1fVdNil 2DaQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1767459497; x=1768064297; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-gg:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to; bh=9j+lytdvFaQc0rDMkV0fSvoJ/5Wk5aT873gsJML9tGo=; b=wFxyCOv02opXQ/CfGb3KUCY6fXOj0NbH2mYkjyGpedLcyY4wRJ6q20iyXZqBApJAIt H4aHmnaHNHTsc7Cgxvx3qSaldeBwCEuiTW+4whp6uH6b/AQjePHB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-Source: AGHT+IGTM8oiOr+3z0DU0MxA7Zl9Alho44cHAql3c2v17Ye0cAmOQUtpCtyGbcS8YqyfsBgebhZFlw== X-Received: by 2002:a05:6402:40d1:b0:64f:cfa0:9024 with SMTP id 4fb4d7f45d1cf-64fcfa0a2camr3365926a12.34.1767459497264; Sat, 03 Jan 2026 08:58:17 -0800 (PST) Received: from localhost.localdomain (2001-1c00-3405-d100-e1ff-2c8c-c190-2ee3.cable.dynamic.v6.ziggo.nl. [2001:1c00:3405:d100:e1ff:2c8c:c190:2ee3]) by smtp.gmail.com with ESMTPSA id 4fb4d7f45d1cf-64b9159ac90sm47948224a12.29.2026.01.03.08.58.16 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 03 Jan 2026 08:58:16 -0800 (PST) From: Boudewijn van der Heide To: "Liam R . Howlett" Cc: Alice Ryhl , Andrew Ballance , Andrew Morton , maple-tree@lists.infradead.org, linux-mm@kvack.org, linux-kernel@vger.kernel.org, Boudewijn van der Heide Subject: [PATCH] maple_tree: Add dead node check in mas_dup_alloc() Date: Sat, 3 Jan 2026 17:57:58 +0100 Message-ID: <20260103165758.74094-1-boudewijn@delta-utec.com> X-Mailer: git-send-email 2.47.3 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: quoted-printable 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() =E2=86=92 mas_dup_build() =E2=86=92 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. --- lib/maple_tree.c | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/lib/maple_tree.c b/lib/maple_tree.c index 5aa4c9500018..f623a7aabd53 100644 --- a/lib/maple_tree.c +++ b/lib/maple_tree.c @@ -6251,6 +6251,11 @@ static inline void mas_dup_alloc(struct ma_state *ma= s, struct ma_state *new_mas, /* Allocate memory for child nodes. */ type =3D mte_node_type(mas->node); new_slots =3D ma_slots(new_node, type); + if (unlikely(ma_dead_node(node))) { + mas_set_err(mas, -EBUSY); + return; + } + count =3D mas->node_request =3D mas_data_end(mas) + 1; mas_alloc_nodes(mas, gfp); if (unlikely(mas_is_err(mas))) --=20 2.47.3