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=1796385048; b=xV69eDfuWgHxr4ILKUV60xSj2KzpLWeYivBrnQNiTrMGz0BuYPdWSEhS3GA2ZJKJnDaT 9S45iRcO+bTYo390uuYX4PuxZDjBhVuD/jTdngolkaddji83DJsXlEA23+BZ2nm2vJajR MkQGuNxXmATDyincy8Tks1hYQw4tmtt3xwl4scvr4YOFMsdy6/1uogQvvDD1V74lcTo0d WDd4H8viQSWN5tt8vdMpiHev5VjP1oQmN+EbpcQ4z+7Zd/oSSkqy+9XczyOnXORekdpiQ a9YjJY6Dlgbp6D3eTeE9i8QnVJaqXFTEGuQzWi0vv57K0944Mc0MgLYWmlsNCGMN5Hw== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796385048; 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=1SVP0YXNUiTP0Oo4lC4RqdWJONwTY/agAKnTqrWDqpQ=; b=2rJGv594whorq0gime2swqzxU780WYThhIe9w370SL6qq5wso/ZX3e8wsShrzC/jRt2a SFcx6+GTsR7rWT19mMoMVIdRsWOk9djDnSHdGFPKJAfxPi5+rzu00Hz6BNBXBaZmoLGJa 2sxPg7URJBlsTCsH5a7mLHMpblEs4I7HQrQvtE1FNz7Kmgjvb7efrt+lj7bTTpO0FkSio h2/o6YfVkelmLle9igWs2SMGHSTLhb35ASQ94sLwGWCaOrFy+pFf0N6YvPaDgLeQP+fkB 5tFGxshQAbH107FDFlJqlFL+tTyjG1l+gJFVrTwY9iHiqQ8y0r2SMl5o4g9Ue68MxHQ== 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=ZL8xkWwO; 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 2D735606A322; Fri, 4 Dec 2026 11:50:48 +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=ZL8xkWwO Received: by smtp.kernel.org (Postfix) with ESMTPSA id 9D5981F000C2; Fri, 4 Dec 2026 11:50:47 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linuxfoundation.org; s=korg; t=1796385048; bh=1SVP0YXNUiTP0Oo4lC4RqdWJONwTY/agAKnTqrWDqpQ=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=ZL8xkWwOc8IH2SaS77v7PbpkytwvO6SGFrz4KmMJrXfC52jngJoUb0PTB0fH/DssT H6n41YotDC7Z3vmSUuEAieJmAShQTKmtKND26W0oYqFEsMabrzRP3F3ZmFBhX1xwlm 1zQyjFlENWsbB5WTf7N3TSnuMfbBKc5aO9u53C8k= 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.6 0370/1167] dlm: validate node weights before building member array Date: Fri, 4 Dec 2026 18:56:37 +0900 Message-ID: <20261204100711.625447826@linuxfoundation.org> X-Mailer: git-send-email 2.56.1 In-Reply-To: <20261204100702.047403948@linuxfoundation.org> References: <20261204100702.047403948@linuxfoundation.org> User-Agent: quilt/0.69 X-stable: review X-Patchwork-Hint: ignore X-Mailing-List: stable@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 Content-Transfer-Encoding: 8bit 6.6-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 branch's kmalloc_array() instead of upstream's kmalloc_objs() in make_member_array(), and dropped the early ls_total_weight assignment as upstream does. ] 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 e55e0a2cd2e86..ff9d418368bca 100644 --- a/fs/dlm/config.c +++ b/fs/dlm/config.c @@ -789,10 +789,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 be7909ead71b4..7d13f3683711f 100644 --- a/fs/dlm/member.c +++ b/fs/dlm/member.c @@ -404,7 +404,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; @@ -413,8 +413,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 */ @@ -424,10 +424,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) @@ -444,7 +443,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 */ @@ -604,7 +606,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, rv->seq); -- 2.53.0