]> git.proxmox.com Git - mirror_ubuntu-jammy-kernel.git/commitdiff
md: bcache: check the return value of kzalloc() in detached_dev_do_request()
authorJia-Ju Bai <baijiaju1990@gmail.com>
Fri, 27 May 2022 15:28:18 +0000 (23:28 +0800)
committerStefan Bader <stefan.bader@canonical.com>
Wed, 10 Aug 2022 07:25:32 +0000 (09:25 +0200)
BugLink: https://bugs.launchpad.net/bugs/1981864
commit 40f567bbb3b0639d2ec7d1c6ad4b1b018f80cf19 upstream.

The function kzalloc() in detached_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 <oslab@tsinghua.edu.cn>
Signed-off-by: Jia-Ju Bai <baijiaju1990@gmail.com>
Signed-off-by: Coly Li <colyli@suse.de>
Link: https://lore.kernel.org/r/20220527152818.27545-4-colyli@suse.de
Signed-off-by: Jens Axboe <axboe@kernel.dk>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Signed-off-by: Kamal Mostafa <kamal@canonical.com>
Signed-off-by: Stefan Bader <stefan.bader@canonical.com>
drivers/md/bcache/request.c

index 6d1de889baeb1c2caeb813a29f58dc6ec84de131..9f4a2850aa47e8cfdd0bd0a7c3393826b317736a 100644 (file)
@@ -1107,6 +1107,12 @@ 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) {
+               bio->bi_status = BLK_STS_RESOURCE;
+               bio->bi_end_io(bio);
+               return;
+       }
+
        ddip->d = d;
        /* Count on the bcache device */
        ddip->orig_bdev = orig_bdev;