diff mbox series

nbd: fix a block_device refcount leak in nbd_release

Message ID 20201109173059.2500429-1-hch@lst.de (mailing list archive)
State New, archived
Headers show
Series nbd: fix a block_device refcount leak in nbd_release | expand

Commit Message

Christoph Hellwig Nov. 9, 2020, 5:30 p.m. UTC
bdget_disk needs to be paired with bdput to not leak a reference
on the block device inode.

Fixes: 08ba91ee6e2c ("nbd: Add the nbd NBD_DISCONNECT_ON_CLOSE config flag.")
Signed-off-by: Christoph Hellwig <hch@lst.de>
---
 drivers/block/nbd.c | 1 +
 1 file changed, 1 insertion(+)

Comments

Josef Bacik Nov. 9, 2020, 6:02 p.m. UTC | #1
On 11/9/20 12:30 PM, Christoph Hellwig wrote:
> bdget_disk needs to be paired with bdput to not leak a reference
> on the block device inode.
> 
> Fixes: 08ba91ee6e2c ("nbd: Add the nbd NBD_DISCONNECT_ON_CLOSE config flag.")
> Signed-off-by: Christoph Hellwig <hch@lst.de>

Reviewed-by: Josef Bacik <josef@toxicpanda.com>

Thanks,

Josef
Jens Axboe Nov. 10, 2020, 3:01 p.m. UTC | #2
On 11/9/20 10:30 AM, Christoph Hellwig wrote:
> bdget_disk needs to be paired with bdput to not leak a reference
> on the block device inode.

Applied, thanks.
diff mbox series

Patch

diff --git a/drivers/block/nbd.c b/drivers/block/nbd.c
index a6f51934391edb..45b0423ef2c53d 100644
--- a/drivers/block/nbd.c
+++ b/drivers/block/nbd.c
@@ -1493,6 +1493,7 @@  static void nbd_release(struct gendisk *disk, fmode_t mode)
 	if (test_bit(NBD_RT_DISCONNECT_ON_CLOSE, &nbd->config->runtime_flags) &&
 			bdev->bd_openers == 0)
 		nbd_disconnect_and_put(nbd);
+	bdput(bdev);
 
 	nbd_config_put(nbd);
 	nbd_put(nbd);