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 BC7723B52ED; Thu, 15 Jan 2026 16:54:51 +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=1768496091; cv=none; b=F4nEOfNmaMctHW9hB8Z1tr+lTcCVhMcAgzqn5iReapTtikOkUgqR3H28jwl2Vdr8iycHKMy+qcdh9ka06Dc0QQCJoDab5Za0+UWB88/81XDfjqlErNQErApvhjYJYD7n/6Bh6O2kqJmvUNWbk8RGtL6RT9zi1UJwRIuEvsNpBvE= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1768496091; c=relaxed/simple; bh=JR2JylqvRkzUxvJvy0o6ib4e65VvP2+eWbIXo5Rz6CE=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=AC2dWQ6/t+8K/sdhXfFHMQjXWGIQpmoJIl739QfK2T/i0SYR1SKfd94iV08NVQBiHTSYjq7lOCIeiUiSjnsUq6/IfmoSoXnTVaA8joCpj/8J+byLxWt5/UzQw1rd3paXVFHa/0MeHDm/VjbX+Mdj9lTMrDCENTS+ODWtNwtSn+w= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.b=QFTbOrC9; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.b="QFTbOrC9" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 477A9C116D0; Thu, 15 Jan 2026 16:54:51 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1768496091; bh=JR2JylqvRkzUxvJvy0o6ib4e65VvP2+eWbIXo5Rz6CE=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=QFTbOrC9zXEs1if1MiNRXQBUeUXcA3wxzpsNhpOYe7aYttZQlwYYG8k34n+kte+I8 mD4hVk6JM0xGv3IUVkgPkdDNxbbZKFfyJu2EMHOkPfnlZ3OvlShEq1VcqoFhdGx9W/ L/W/wF5IeebH/FrnKUXx05d5+t0v9oV4yiofzZic= From: Greg Kroah-Hartman To: stable@vger.kernel.org Cc: Greg Kroah-Hartman , patches@lists.linux.dev, Tuo Li , Viacheslav Dubeyko , Ilya Dryomov Subject: [PATCH 6.18 041/181] libceph: make free_choose_arg_map() resilient to partial allocation Date: Thu, 15 Jan 2026 17:46:18 +0100 Message-ID: <20260115164203.811470351@linuxfoundation.org> X-Mailer: git-send-email 2.52.0 In-Reply-To: <20260115164202.305475649@linuxfoundation.org> References: <20260115164202.305475649@linuxfoundation.org> User-Agent: quilt/0.69 X-stable: review X-Patchwork-Hint: ignore Precedence: bulk X-Mailing-List: stable@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit 6.18-stable review patch. If anyone has any objections, please let me know. ------------------ From: Tuo Li commit e3fe30e57649c551757a02e1cad073c47e1e075e upstream. free_choose_arg_map() may dereference a NULL pointer if its caller fails after a partial allocation. For example, in decode_choose_args(), if allocation of arg_map->args fails, execution jumps to the fail label and free_choose_arg_map() is called. Since arg_map->size is updated to a non-zero value before memory allocation, free_choose_arg_map() will iterate over arg_map->args and dereference a NULL pointer. To prevent this potential NULL pointer dereference and make free_choose_arg_map() more resilient, add checks for pointers before iterating. Cc: stable@vger.kernel.org Co-authored-by: Ilya Dryomov Signed-off-by: Tuo Li Reviewed-by: Viacheslav Dubeyko Signed-off-by: Ilya Dryomov Signed-off-by: Greg Kroah-Hartman --- net/ceph/osdmap.c | 20 ++++++++++++-------- 1 file changed, 12 insertions(+), 8 deletions(-) --- a/net/ceph/osdmap.c +++ b/net/ceph/osdmap.c @@ -241,22 +241,26 @@ static struct crush_choose_arg_map *allo static void free_choose_arg_map(struct crush_choose_arg_map *arg_map) { - if (arg_map) { - int i, j; + int i, j; - WARN_ON(!RB_EMPTY_NODE(&arg_map->node)); + if (!arg_map) + return; + WARN_ON(!RB_EMPTY_NODE(&arg_map->node)); + + if (arg_map->args) { for (i = 0; i < arg_map->size; i++) { struct crush_choose_arg *arg = &arg_map->args[i]; - - for (j = 0; j < arg->weight_set_size; j++) - kfree(arg->weight_set[j].weights); - kfree(arg->weight_set); + if (arg->weight_set) { + for (j = 0; j < arg->weight_set_size; j++) + kfree(arg->weight_set[j].weights); + kfree(arg->weight_set); + } kfree(arg->ids); } kfree(arg_map->args); - kfree(arg_map); } + kfree(arg_map); } DEFINE_RB_FUNCS(choose_arg_map, struct crush_choose_arg_map, choose_args_index,