Skip to content

Commit 6d42ddf

Browse files
chrboeaxboe
authored andcommitted
drbd: only clone bio if we have a backing device
Commit c347a78 (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: c347a78 ("drbd: set ->bi_bdev in drbd_req_new") Co-developed-by: Christoph Böhmwalder <christoph.boehmwalder@linbit.com> Signed-off-by: Christoph Böhmwalder <christoph.boehmwalder@linbit.com> Co-developed-by: Joel Colledge <joel.colledge@linbit.com> Signed-off-by: Joel Colledge <joel.colledge@linbit.com> Reviewed-by: Christoph Hellwig <hch@lst.de> Link: https://lore.kernel.org/r/20221020085205.129090-1-christoph.boehmwalder@linbit.com Signed-off-by: Jens Axboe <axboe@kernel.dk>
1 parent 70ee4a4 commit 6d42ddf

1 file changed

Lines changed: 6 additions & 8 deletions

File tree

drivers/block/drbd/drbd_req.c

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -30,11 +30,6 @@ static struct drbd_request *drbd_req_new(struct drbd_device *device, struct bio
3030
return NULL;
3131
memset(req, 0, sizeof(*req));
3232

33-
req->private_bio = bio_alloc_clone(device->ldev->backing_bdev, bio_src,
34-
GFP_NOIO, &drbd_io_bio_set);
35-
req->private_bio->bi_private = req;
36-
req->private_bio->bi_end_io = drbd_request_endio;
37-
3833
req->rq_state = (bio_data_dir(bio_src) == WRITE ? RQ_WRITE : 0)
3934
| (bio_op(bio_src) == REQ_OP_WRITE_ZEROES ? RQ_ZEROES : 0)
4035
| (bio_op(bio_src) == REQ_OP_DISCARD ? RQ_UNMAP : 0);
@@ -1219,9 +1214,12 @@ drbd_request_prepare(struct drbd_device *device, struct bio *bio)
12191214
/* Update disk stats */
12201215
req->start_jif = bio_start_io_acct(req->master_bio);
12211216

1222-
if (!get_ldev(device)) {
1223-
bio_put(req->private_bio);
1224-
req->private_bio = NULL;
1217+
if (get_ldev(device)) {
1218+
req->private_bio = bio_alloc_clone(device->ldev->backing_bdev,
1219+
bio, GFP_NOIO,
1220+
&drbd_io_bio_set);
1221+
req->private_bio->bi_private = req;
1222+
req->private_bio->bi_end_io = drbd_request_endio;
12251223
}
12261224

12271225
/* process discards always from our submitter thread */

0 commit comments

Comments
 (0)