From: Shenghui Wang Date: Wed, 24 Apr 2019 16:48:42 +0000 (+0800) Subject: bcache: fix wrong usage use-after-freed on keylist in out_nocoalesce branch of btree_... X-Git-Tag: v5.4-rc1~945^2~56 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=f16277ca20acf2c213fcd4b645f4c1cffcadf533;p=platform%2Fkernel%2Flinux-rpi.git bcache: fix wrong usage use-after-freed on keylist in out_nocoalesce branch of btree_gc_coalesce Elements of keylist should be accessed before the list is freed. Move bch_keylist_free() calling after the while loop to avoid wrong content accessed. Signed-off-by: Shenghui Wang Signed-off-by: Coly Li Signed-off-by: Jens Axboe --- diff --git a/drivers/md/bcache/btree.c b/drivers/md/bcache/btree.c index 64def33..b139858 100644 --- a/drivers/md/bcache/btree.c +++ b/drivers/md/bcache/btree.c @@ -1476,11 +1476,11 @@ static int btree_gc_coalesce(struct btree *b, struct btree_op *op, out_nocoalesce: closure_sync(&cl); - bch_keylist_free(&keylist); while ((k = bch_keylist_pop(&keylist))) if (!bkey_cmp(k, &ZERO_KEY)) atomic_dec(&b->c->prio_blocked); + bch_keylist_free(&keylist); for (i = 0; i < nodes; i++) if (!IS_ERR_OR_NULL(new_nodes[i])) {