From: Coly Li Date: Thu, 23 Jan 2020 17:01:30 +0000 (+0800) Subject: bcache: fix use-after-free in register_bcache() X-Git-Tag: v5.5.6~67 X-Git-Url: https://www.infradead.org/git/?a=commitdiff_plain;h=2d5ff654d9c2e82adcd576b6cd5dd0f6d7c3bdc5;p=users%2Fdwmw2%2Flinux.git bcache: fix use-after-free in register_bcache() [ Upstream commit ae3cd299919af6eb670d5af0bc9d7ba14086bd8e ] The patch "bcache: rework error unwinding in register_bcache" introduces a use-after-free regression in register_bcache(). Here are current code, 2510 out_free_path: 2511 kfree(path); 2512 out_module_put: 2513 module_put(THIS_MODULE); 2514 out: 2515 pr_info("error %s: %s", path, err); 2516 return ret; If some error happens and the above code path is executed, at line 2511 path is released, but referenced at line 2515. Then KASAN reports a use- after-free error message. This patch changes line 2515 in the following way to fix the problem, 2515 pr_info("error %s: %s", path?path:"", err); Signed-off-by: Coly Li Cc: Christoph Hellwig Signed-off-by: Jens Axboe Signed-off-by: Sasha Levin --- diff --git a/drivers/md/bcache/super.c b/drivers/md/bcache/super.c index bd2ae1d78fe15..05cb94664efee 100644 --- a/drivers/md/bcache/super.c +++ b/drivers/md/bcache/super.c @@ -2475,10 +2475,11 @@ out_free_sb: kfree(sb); out_free_path: kfree(path); + path = NULL; out_module_put: module_put(THIS_MODULE); out: - pr_info("error %s: %s", path, err); + pr_info("error %s: %s", path?path:"", err); return ret; }