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 937186FB0; Tue, 5 Dec 2023 03:45:52 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.b="GkaJsvvZ" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 241CDC433C8; Tue, 5 Dec 2023 03:45:51 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1701747952; bh=+IrqwEl3wjfitPscW3PkH/OfWfV9KkMepvpfZ+bMyXw=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=GkaJsvvZ+QnZayE5WUS37C6fj5u9WLWLg0AKst0GoOyIqDFcUmAFDE4y0X0xGeNGD +9C2RP425CeO2MU8UgEafuwr2giqCZiGxYiYRTxPvjSCbfrhl8Mv9DKuu0G3F8xKeb 0bqd0wWVU0pFd56n4FMsJRTb+6Viht/RcdwhUt4c= 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.4 41/94] bcache: check return value from btree_node_alloc_replacement() Date: Tue, 5 Dec 2023 12:17:09 +0900 Message-ID: <20231205031525.178673173@linuxfoundation.org> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20231205031522.815119918@linuxfoundation.org> References: <20231205031522.815119918@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.4-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 @@ -1555,6 +1555,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)) {