From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=100.103.45.18 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796387656; b=frbbhrTVKduHsXNzZvgcSR+YmJ3ZRoJBrjaFa5Y01wXZC9CgtrkgIOy0n5b7aZtHD7tg lnreXMygGsNijAVP6YqopLUa3UKJlNA5H81GyCBh2IdNwvHBP1+8AxUhy7EBQ0jSF0/2L VZux7sb75sUP/oNSGcG+WDJ8Bj4E53frfaAdLnkPtDbDHqWHDtrWu60sWeGU70d3Flvrr GGlHfEAm2GWI+GwYjULTeRX4xt6RekxM8mefEcupLFqQRW/kRkijVPCo8UgZjSvV97B9M f3oa4R1Eb3WUAJiro3asU40b2RbMinT7A2kekZTOjVSunDWehaN6C5NKRFQKkzvvpJA== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796387656; h=Received:DKIM-Signature:From:To:Cc:Subject:Date:Message-ID:X-Mailer: In-Reply-To:References:User-Agent:X-stable:X-Patchwork-Hint: MIME-Version:Content-Transfer-Encoding; bh=NiJlUjVjNeWgg2KEBYmm+fXN/VxbUURp24Z32mBHy7Q=; b=llKpLsKZjAqG18X2518q5PViYlcghmMS1iXopIKK5A3Y6z3CpEdK6rwVRhPhR68BjeqD E2nU702UgmOyD4RhCVJ4ts8066PEdt86ptEnt+hR1dgbW1RpyxS7oFHtUu4rPqzhPIx5a 05D1IZ+md1tqXGUXQOhcDARCP1RmIYF04tvuFQQi2AY+h2X4xItyKVqEBka7lt09w9hHz JRo/uLpb2wTVEeryogd4utQJV4Grb3tenu9G0LASLt7dxhufajqjdwsqAplO3gGhpiEo1 9fzNnnr030UNrcycYvlAm7XJHh7nu7aoZrlPOwfy5xZPsC7ER6bAImVpj1hYcILAA4g== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass header.d=linuxfoundation.org header.i=@linuxfoundation.org header.a=rsa-sha256 header.s=korg header.b=tEON5NsP; arc=none smtp.remote-ip=100.103.45.18 Received: from smtp.kernel.org (quasi.space.kernel.org [100.103.45.18]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (prime256v1)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id E6396606A330; Fri, 4 Dec 2026 12:34:15 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.a=rsa-sha256 header.s=korg header.b=tEON5NsP Received: by smtp.kernel.org (Postfix) with ESMTPSA id 637921F000C2; Fri, 4 Dec 2026 12:34:15 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linuxfoundation.org; s=korg; t=1796387655; bh=NiJlUjVjNeWgg2KEBYmm+fXN/VxbUURp24Z32mBHy7Q=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=tEON5NsPya8sCZGEc3nQneoYq9q/KDQUsSV8KpZU4NLvimRg3tE5gbvOtvNBF/+xD pwsV2nz7cEUJe3W1KsAzRSae9qorYN4v4M7GirVhLCM6tUpOC0gC/PxsIxssibwDda DpvNk/ZPOnkSUzjSUAJ/+ZEXMWSDd0+P9lrSxJzs= From: Greg Kroah-Hartman To: stable@vger.kernel.org Cc: Greg Kroah-Hartman , patches@lists.linux.dev, Qing Ming , Alexander Aring , David Teigland , Sasha Levin Subject: [PATCH 6.1 0336/1059] dlm: validate node weights before building member array Date: Fri, 4 Dec 2026 18:57:47 +0900 Message-ID: <20261204100652.972909913@linuxfoundation.org> X-Mailer: git-send-email 2.56.1 In-Reply-To: <20261204100643.980430235@linuxfoundation.org> References: <20261204100643.980430235@linuxfoundation.org> User-Agent: quilt/0.69 X-stable: review X-Patchwork-Hint: ignore X-Mailing-List: patches@lists.linux.dev List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 Content-Transfer-Encoding: 8bit 6.1-stable review patch. If anyone has any objections, please let me know. ------------------ From: Qing Ming [ Upstream commit 7f662eb1807ed732ac7d5e119753c8185f241bb8 ] DLM node weights are parsed as signed integers and copied into the member list. make_member_array() uses their sum as the allocation count, but only positive weights contribute entries to the array. A negative weight can therefore reduce the allocation without reducing the number of writes. The issue was found through static analysis of the configfs input and member array construction. With two recovery members weighted -31 and 32, the sum is 1, so recovery allocates one int and then writes the positive member's node ID 32 times. A reproducer using dlm_controld and dlm_tool triggered the same report on a KASAN kernel: BUG: KASAN: slab-out-of-bounds in dlm_recover_members [dlm] Write of size 4 by task dlm_recoverd Call Trace: dlm_recover_members dlm_recoverd kthread ret_from_fork Reject negative weights at the configfs input boundary. Also detect overflow when adding non-negative weights to the signed allocation count, and propagate array construction errors to the recovery path. Fixes: e7fd41792fc0 ("[DLM] The core of the DLM for GFS2/CLVM") Signed-off-by: Qing Ming Assisted-by: Codex:gpt-5 Acked-by: Alexander Aring Signed-off-by: Alexander Aring Signed-off-by: David Teigland [ sashal: Kept the tree's kmalloc_array() instead of kmalloc_objs() and dropped the early ls_total_weight assignment; ping_members(ls) context also differs. ] Signed-off-by: Sasha Levin --- fs/dlm/config.c | 9 ++++++++- fs/dlm/member.c | 17 +++++++++++------ 2 files changed, 19 insertions(+), 7 deletions(-) diff --git a/fs/dlm/config.c b/fs/dlm/config.c index 20b60709eccf0..3d48d7548c1cd 100644 --- a/fs/dlm/config.c +++ b/fs/dlm/config.c @@ -804,10 +804,17 @@ static ssize_t node_weight_show(struct config_item *item, char *buf) static ssize_t node_weight_store(struct config_item *item, const char *buf, size_t len) { - int rc = kstrtoint(buf, 0, &config_item_to_node(item)->weight); + struct dlm_node *node = config_item_to_node(item); + int weight; + int rc; + rc = kstrtoint(buf, 0, &weight); if (rc) return rc; + if (weight < 0) + return -EINVAL; + + node->weight = weight; return len; } diff --git a/fs/dlm/member.c b/fs/dlm/member.c index 2af2ccfe43a9d..aece94eaf66f8 100644 --- a/fs/dlm/member.c +++ b/fs/dlm/member.c @@ -386,7 +386,7 @@ void dlm_clear_members_gone(struct dlm_ls *ls) clear_memb_list(&ls->ls_nodes_gone, NULL); } -static void make_member_array(struct dlm_ls *ls) +static int make_member_array(struct dlm_ls *ls) { struct dlm_member *memb; int i, w, x = 0, total = 0, all_zero = 0, *array; @@ -395,8 +395,8 @@ static void make_member_array(struct dlm_ls *ls) ls->ls_node_array = NULL; list_for_each_entry(memb, &ls->ls_nodes, list) { - if (memb->weight) - total += memb->weight; + if (check_add_overflow(total, memb->weight, &total)) + return -EOVERFLOW; } /* all nodes revert to weight of 1 if all have weight 0 */ @@ -406,10 +406,9 @@ static void make_member_array(struct dlm_ls *ls) all_zero = 1; } - ls->ls_total_weight = total; array = kmalloc_array(total, sizeof(*array), GFP_NOFS); if (!array) - return; + return -ENOMEM; list_for_each_entry(memb, &ls->ls_nodes, list) { if (!all_zero && !memb->weight) @@ -426,7 +425,10 @@ static void make_member_array(struct dlm_ls *ls) array[x++] = memb->nodeid; } + ls->ls_total_weight = total; ls->ls_node_array = array; + + return 0; } /* send a status request to all members just to establish comms connections */ @@ -583,7 +585,10 @@ int dlm_recover_members(struct dlm_ls *ls, struct dlm_recover *rv, int *neg_out) } ls->ls_low_nodeid = low; - make_member_array(ls); + error = make_member_array(ls); + if (error) + return error; + *neg_out = neg; error = ping_members(ls); -- 2.53.0