blob: 53b1bd01b2178f7c2e0fec590408726854393116 [file] [log] [blame]
From 39d240ea1b253c2267a824d791ab5a7721058099 Mon Sep 17 00:00:00 2001
From: Coly Li <>
Date: Fri, 24 Jan 2020 01:01:30 +0800
Subject: [PATCH] bcache: fix use-after-free in register_bcache()
commit ae3cd299919af6eb670d5af0bc9d7ba14086bd8e upstream.
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: Paul Gortmaker <>
diff --git a/drivers/md/bcache/super.c b/drivers/md/bcache/super.c
index 27af2bbd7841..25fa9f85599d 100644
--- a/drivers/md/bcache/super.c
+++ b/drivers/md/bcache/super.c
@@ -2400,10 +2400,11 @@ static ssize_t register_bcache(struct kobject *k, struct kobj_attribute *attr,
+ path = NULL;
- pr_info("error %s: %s", path, err);
+ pr_info("error %s: %s", path?path:"", err);
return ret;