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 27EC954BE9; Thu, 30 Nov 2023 16:34:29 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.b="u7XlQMIL" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 5297EC433CA; Thu, 30 Nov 2023 16:34:29 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1701362069; bh=LhwdA09/0/Rtn3FwEy1pY7Np4U12wpzlYy8U8aflmIs=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=u7XlQMILooUNiCUbJ+RdY78HO1vy1YsnbqZ1lEJKS1O9Equ2hHbZTwd77eR11Iu8n G0x0hJsHqg3j6/YWzewISMmnw3T6lGTKVWmozDxQ7DVAffG1SP8WZbQDCzy2uTiD8/ keOlkaal2Oqq4EcL6iYbF6wjqRoSDG+d+vK0GqA8= From: Greg Kroah-Hartman To: stable@vger.kernel.org Cc: Greg Kroah-Hartman , patches@lists.linux.dev, Coly Li , Dan Carpenter , Jens Axboe Subject: [PATCH 5.15 55/69] bcache: check return value from btree_node_alloc_replacement() Date: Thu, 30 Nov 2023 16:22:52 +0000 Message-ID: <20231130162134.870379130@linuxfoundation.org> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20231130162133.035359406@linuxfoundation.org> References: <20231130162133.035359406@linuxfoundation.org> User-Agent: quilt/0.67 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 5.15-stable review patch. If anyone has any objections, please let me know. ------------------ From: Coly Li commit 777967e7e9f6f5f3e153abffb562bffaf4430d26 upstream. In btree_gc_rewrite_node(), pointer 'n' is not checked after it returns from btree_gc_rewrite_node(). There is potential possibility that 'n' is a non NULL ERR_PTR(), referencing such error code is not permitted in following code. Therefore a return value checking is necessary after 'n' is back from btree_node_alloc_replacement(). Signed-off-by: Coly Li Reported-by: Dan Carpenter Cc: Link: https://lore.kernel.org/r/20231120052503.6122-3-colyli@suse.de Signed-off-by: Jens Axboe Signed-off-by: Greg Kroah-Hartman --- drivers/md/bcache/btree.c | 2 ++ 1 file changed, 2 insertions(+) --- a/drivers/md/bcache/btree.c +++ b/drivers/md/bcache/btree.c @@ -1506,6 +1506,8 @@ static int btree_gc_rewrite_node(struct return 0; n = btree_node_alloc_replacement(replace, NULL); + if (IS_ERR(n)) + return 0; /* recheck reserve after allocating replacement node */ if (btree_check_reserve(b, NULL)) {