diff options
author | Zheng Wang <zyytlz.wz@163.com> | 2023-06-15 20:12:22 +0800 |
---|---|---|
committer | Jens Axboe <axboe@kernel.dk> | 2023-06-15 07:32:00 -0600 |
commit | 80fca8a10b604afad6c14213fdfd816c4eda3ee4 (patch) | |
tree | 793f15566eb23b2d44ab32877b562766c5504c6c /drivers/md/bcache/btree.c | |
parent | 028ddcac477b691dd9205c92f991cc15259d033e (diff) | |
download | lwn-80fca8a10b604afad6c14213fdfd816c4eda3ee4.tar.gz lwn-80fca8a10b604afad6c14213fdfd816c4eda3ee4.zip |
bcache: Fix __bch_btree_node_alloc to make the failure behavior consistent
In some specific situations, the return value of __bch_btree_node_alloc
may be NULL. This may lead to a potential NULL pointer dereference in
caller function like a calling chain :
btree_split->bch_btree_node_alloc->__bch_btree_node_alloc.
Fix it by initializing the return value in __bch_btree_node_alloc.
Fixes: cafe56359144 ("bcache: A block layer cache")
Cc: stable@vger.kernel.org
Signed-off-by: Zheng Wang <zyytlz.wz@163.com>
Signed-off-by: Coly Li <colyli@suse.de>
Link: https://lore.kernel.org/r/20230615121223.22502-6-colyli@suse.de
Signed-off-by: Jens Axboe <axboe@kernel.dk>
Diffstat (limited to 'drivers/md/bcache/btree.c')
-rw-r--r-- | drivers/md/bcache/btree.c | 4 |
1 files changed, 3 insertions, 1 deletions
diff --git a/drivers/md/bcache/btree.c b/drivers/md/bcache/btree.c index 7c21e54468bf..0ddf91204782 100644 --- a/drivers/md/bcache/btree.c +++ b/drivers/md/bcache/btree.c @@ -1090,10 +1090,12 @@ struct btree *__bch_btree_node_alloc(struct cache_set *c, struct btree_op *op, struct btree *parent) { BKEY_PADDED(key) k; - struct btree *b = ERR_PTR(-EAGAIN); + struct btree *b; mutex_lock(&c->bucket_lock); retry: + /* return ERR_PTR(-EAGAIN) when it fails */ + b = ERR_PTR(-EAGAIN); if (__bch_bucket_alloc_set(c, RESERVE_BTREE, &k.key, wait)) goto err; |