]> git.baikalelectronics.ru Git - kernel.git/commit
drbd: only clone bio if we have a backing device
authorChristoph Böhmwalder <christoph.boehmwalder@linbit.com>
Thu, 20 Oct 2022 08:52:05 +0000 (10:52 +0200)
committerJens Axboe <axboe@kernel.dk>
Thu, 20 Oct 2022 12:45:21 +0000 (05:45 -0700)
commita2c695f6437055612b32cd0d83f388d3e5f2d5fa
tree8428578275365a3e9a8871bfbce3231c22b2a680
parent5744a66525630573521af44c4f0025162ef85ec8
drbd: only clone bio if we have a backing device

Commit 571901cc61bea (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: 571901cc61bea ("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>
drivers/block/drbd/drbd_req.c