From: Coly Li Date: Mon, 20 Nov 2023 05:24:55 +0000 (+0800) Subject: bcache: check return value from btree_node_alloc_replacement() X-Git-Tag: v6.6.17~2418 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=30ed07af096eb32eb4a62e542933b086457bd616;p=platform%2Fkernel%2Flinux-rpi.git bcache: check return value from btree_node_alloc_replacement() 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 --- diff --git a/drivers/md/bcache/btree.c b/drivers/md/bcache/btree.c index e922c6a..418f85f 100644 --- a/drivers/md/bcache/btree.c +++ b/drivers/md/bcache/btree.c @@ -1527,6 +1527,8 @@ static int btree_gc_rewrite_node(struct btree *b, struct btree_op *op, 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)) {