Skip to content

Commit

Permalink
bcache: check return value from btree_node_alloc_replacement()
Browse files Browse the repository at this point in the history
commit 777967e 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 <colyli@suse.de>
Reported-by: Dan Carpenter <dan.carpenter@linaro.org>
Cc:  <stable@vger.kernel.org>
Link: https://lore.kernel.org/r/20231120052503.6122-3-colyli@suse.de
Signed-off-by: Jens Axboe <axboe@kernel.dk>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
  • Loading branch information
Coly Li authored and gregkh committed Dec 3, 2023
1 parent 4241b51 commit 366f364
Showing 1 changed file with 2 additions and 0 deletions.
2 changes: 2 additions & 0 deletions drivers/md/bcache/btree.c
Original file line number Diff line number Diff line change
Expand Up @@ -1506,6 +1506,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)) {
Expand Down

0 comments on commit 366f364

Please sign in to comment.