md: bcache: check the return value of kzalloc() in detached_dev_do_request()
PATCH 1/1 md: bcache: check the return value of kzalloc() in detached_dev_do_request()
The function kzalloc() in detached_dev_do_request() can fail, so its return value should be checked.
--- drivers/md/bcache/request.c | 2 ++ 1 file changed, 2 insertions(+)
drivers/md/bcache/request.c +2 -0
@@ -1107,6 +1107,8 @@ static void detached_dev_do_request(struct bcache_device *d, struct bio *bio,* which would call closure_get(&dc->disk.cl) */ ddip =kzalloc (sizeof (struct detached_dev_io_private ),GFP_NOIO ); +if (!ddip) +return ; ddip->d = d;/* Count on the bcache device */ ddip->orig_bdev = orig_bdev;
Signature · 1 line
2.17.1
Quoted 15 lines · Jia-Ju Bai
The function
kzalloc()indetached_dev_do_request()can fail, so its return value should be checked.Fixes bc082a55d25c (bcache: fix inaccurate io state for detached bcache devices)Reported-by TOTE Robot <[email protected]>Signed-off-by Jia-Ju Bai <[email protected]>--- drivers/md/bcache/request.c | 2 ++ 1 file changed, 2 insertions(+)drivers/md/bcache/request.c +0
-0
drivers/md/bcache/request.c static void detached_dev_do_request(struct bcache_device *d, struct bio *bio, · line 1109
Quoted 3 lines
drivers/md/bcache/request.c +0
-0@@ -1107,6 +1107,8 @@ static void detached_dev_do_request(struct bcache_device *d, struct bio *bio,* which would call closure_get(&dc->disk.cl) */ ddip =kzalloc (sizeof (struct detached_dev_io_private ),GFP_NOIO );
Yes this is a potential problem, may result NULL pointer deference.
drivers/md/bcache/request.c static void detached_dev_do_request(struct bcache_device *d, struct bio *bio, · line 1111
Quoted 2 lines
drivers/md/bcache/request.c +2
-0+if (!ddip) +return ;
The fix here is incorrect. A proper way to fix might be something like this,
if (!ddip) {
bio->bi_status = BLK_STS_RESOURCE;
bio->bi_end_io(bio);
return;
}
The orignal patch will make I/O task be in sleep forever.
Quoted 3 lines
drivers/md/bcache/request.c +0
-0ddip->d = d;/* Count on the bcache device */ ddip->orig_bdev = orig_bdev;
Quoted 33 lines · Coly Li
Quoted 15 lines · Jia-Ju Bai
The function
kzalloc()indetached_dev_do_request()can fail, so its return value should be checked.Fixes bc082a55d25c (bcache: fix inaccurate io state for detached bcache devices)Reported-by TOTE Robot <[email protected]>Signed-off-by Jia-Ju Bai <[email protected]>---
drivers/md/bcache/request.c| 2 ++1 file changed, 2 insertions(+)drivers/md/bcache/request.c +0
-0drivers/md/bcache/request.c static void detached_dev_do_request(struct · line 1110
Quoted 4 lines
drivers/md/bcache/request.c +0
-0@@ -1107,6 +1107,8 @@ static void detached_dev_do_request(structbcache_device *d, struct bio *bio, * which would call closure_get(&dc->disk.cl) */ ddip = kzalloc(sizeof(struct detached_dev_io_private), GFP_NOIO);Yes this is a potential problem, may result NULL pointer deference.
drivers/md/bcache/request.c static void detached_dev_do_request(struct bcache_device *d, struct bio *bio, · line 1111
Quoted 2 lines
drivers/md/bcache/request.c +2
-0+ if (!ddip) + return;The fix here is incorrect. A proper way to fix might be something like this,
if (!ddip) {
bio->bi_status=BLK_STS_RESOURCE;
Quoted 13 lines
bio->bi_end_io(bio);return;
}
The orignal patch will make I/O task be in sleep forever.
Quoted 3 lines
drivers/md/bcache/request.c +0
-0ddip->d = d; /* Count on the bcache device */
ddip->orig_bdev=orig_bdev;
Hi Coly,
Thanks for the advice!
I will send a V2 patch.
Best wishes,
Jia-Ju Bai