diff mbox series

[vfs.all,21/26] block: fix module reference leakage from bdev_open_by_dev error path

Message ID 20240406090930.2252838-22-yukuai1@huaweicloud.com (mailing list archive)
State New, archived
Headers show
Series fs & block: remove bdev->bd_inode | expand

Commit Message

Yu Kuai April 6, 2024, 9:09 a.m. UTC
From: Yu Kuai <yukuai3@huawei.com>

At the time bdev_may_open() is called, module reference is grabbed
already, hence module reference should be released if bdev_may_open()
failed.

This problem is found by code review.

Fixes: ed5cc702d311 ("block: Add config option to not allow writing to mounted devices")
Signed-off-by: Yu Kuai <yukuai3@huawei.com>
---
 block/bdev.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

Comments

Christian Brauner April 11, 2024, 9:16 a.m. UTC | #1
On Sat, 06 Apr 2024 17:09:25 +0800, Yu Kuai wrote:
> At the time bdev_may_open() is called, module reference is grabbed
> already, hence module reference should be released if bdev_may_open()
> failed.
> 
> This problem is found by code review.
> 
> 
> [...]

Bugfix for current code that should go separately.

---

Applied to the vfs.fixes branch of the vfs/vfs.git tree.
Patches in the vfs.fixes branch should appear in linux-next soon.

Please report any outstanding bugs that were missed during review in a
new review to the original patch series allowing us to drop it.

It's encouraged to provide Acked-bys and Reviewed-bys even though the
patch has now been applied. If possible patch trailers will be updated.

Note that commit hashes shown below are subject to change due to rebase,
trailer updates or similar. If in doubt, please check the listed branch.

tree:   https://git.kernel.org/pub/scm/linux/kernel/git/vfs/vfs.git
branch: vfs.fixes

[21/26] block: fix module reference leakage from bdev_open_by_dev error path
        https://git.kernel.org/vfs/vfs/c/9617cd6f24b2
diff mbox series

Patch

diff --git a/block/bdev.c b/block/bdev.c
index 82fb1688f4c9..86db97b0709e 100644
--- a/block/bdev.c
+++ b/block/bdev.c
@@ -890,7 +890,7 @@  int bdev_open(struct block_device *bdev, blk_mode_t mode, void *holder,
 		goto abort_claiming;
 	ret = -EBUSY;
 	if (!bdev_may_open(bdev, mode))
-		goto abort_claiming;
+		goto put_module;
 	if (bdev_is_partition(bdev))
 		ret = blkdev_get_part(bdev, mode);
 	else