Patch "drbd: only clone bio if we have a backing device" has been added to the 6.0-stable tree

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



This is a note to let you know that I've just added the patch titled

    drbd: only clone bio if we have a backing device

to the 6.0-stable tree which can be found at:
    http://www.kernel.org/git/?p=linux/kernel/git/stable/stable-queue.git;a=summary

The filename of the patch is:
     drbd-only-clone-bio-if-we-have-a-backing-device.patch
and it can be found in the queue-6.0 subdirectory.

If you, or anyone else, feels it should not be added to the stable tree,
please let <stable@xxxxxxxxxxxxxxx> know about it.



commit 452ec9983151098eef95611cc32453de24b4600b
Author: Christoph Böhmwalder <christoph.boehmwalder@xxxxxxxxxx>
Date:   Thu Oct 20 10:52:05 2022 +0200

    drbd: only clone bio if we have a backing device
    
    [ Upstream commit 6d42ddf7f27b6723549ee6d4c8b1b418b59bf6b5 ]
    
    Commit c347a787e34cb (drbd: set ->bi_bdev in drbd_req_new) moved a
    bio_set_dev call (which has since been removed) to "earlier", from
    drbd_request_prepare to drbd_req_new.
    
    The problem is that this accesses device->ldev->backing_bdev, which is
    not NULL-checked at this point. When we don't have an ldev (i.e. when
    the DRBD device is diskless), this leads to a null pointer deref.
    
    So, only allocate the private_bio if we actually have a disk. This is
    also a small optimization, since we don't clone the bio to only to
    immediately free it again in the diskless case.
    
    Fixes: c347a787e34cb ("drbd: set ->bi_bdev in drbd_req_new")
    Co-developed-by: Christoph Böhmwalder <christoph.boehmwalder@xxxxxxxxxx>
    Signed-off-by: Christoph Böhmwalder <christoph.boehmwalder@xxxxxxxxxx>
    Co-developed-by: Joel Colledge <joel.colledge@xxxxxxxxxx>
    Signed-off-by: Joel Colledge <joel.colledge@xxxxxxxxxx>
    Reviewed-by: Christoph Hellwig <hch@xxxxxx>
    Link: https://lore.kernel.org/r/20221020085205.129090-1-christoph.boehmwalder@xxxxxxxxxx
    Signed-off-by: Jens Axboe <axboe@xxxxxxxxx>
    Signed-off-by: Sasha Levin <sashal@xxxxxxxxxx>

diff --git a/drivers/block/drbd/drbd_req.c b/drivers/block/drbd/drbd_req.c
index 8f7f144e54f3..7f9bcc82fc9c 100644
--- a/drivers/block/drbd/drbd_req.c
+++ b/drivers/block/drbd/drbd_req.c
@@ -30,11 +30,6 @@ static struct drbd_request *drbd_req_new(struct drbd_device *device, struct bio
 		return NULL;
 	memset(req, 0, sizeof(*req));
 
-	req->private_bio = bio_alloc_clone(device->ldev->backing_bdev, bio_src,
-					   GFP_NOIO, &drbd_io_bio_set);
-	req->private_bio->bi_private = req;
-	req->private_bio->bi_end_io = drbd_request_endio;
-
 	req->rq_state = (bio_data_dir(bio_src) == WRITE ? RQ_WRITE : 0)
 		      | (bio_op(bio_src) == REQ_OP_WRITE_ZEROES ? RQ_ZEROES : 0)
 		      | (bio_op(bio_src) == REQ_OP_DISCARD ? RQ_UNMAP : 0);
@@ -1219,9 +1214,12 @@ drbd_request_prepare(struct drbd_device *device, struct bio *bio)
 	/* Update disk stats */
 	req->start_jif = bio_start_io_acct(req->master_bio);
 
-	if (!get_ldev(device)) {
-		bio_put(req->private_bio);
-		req->private_bio = NULL;
+	if (get_ldev(device)) {
+		req->private_bio = bio_alloc_clone(device->ldev->backing_bdev,
+						   bio, GFP_NOIO,
+						   &drbd_io_bio_set);
+		req->private_bio->bi_private = req;
+		req->private_bio->bi_end_io = drbd_request_endio;
 	}
 
 	/* process discards always from our submitter thread */



[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Index of Archives]     [Linux USB Devel]     [Linux Audio Users]     [Yosemite News]     [Linux Kernel]     [Linux SCSI]

  Powered by Linux