Linux block layer
 help / color / mirror / Atom feed
* [PATCH v2] loop: fix backing file reference leak on validation error
@ 2025-09-30  0:35 Li Chen
  2025-10-02 21:30 ` Jens Axboe
  0 siblings, 1 reply; 2+ messages in thread
From: Li Chen @ 2025-09-30  0:35 UTC (permalink / raw)
  To: Jens Axboe, Lizhi Xu, linux-block, linux-kernel
  Cc: stable, Markus Elfring, Yang Erkun, Ming Lei, Yu Kuai

loop_change_fd() and loop_configure() call loop_check_backing_file()
to validate the new backing file. If validation fails, the reference
acquired by fget() was not dropped, leaking a file reference.

Fix this by calling fput(file) before returning the error.

Cc: stable@vger.kernel.org
Cc: "Markus Elfring"<Markus.Elfring@web.de>
CC: "Yang Erkun" <yangerkun@huawei.com>
Cc: "Ming Lei"<ming.lei@redhat.com>
Cc: "Yu Kuai"<yukuai1@huaweicloud.com>
Fixes: f5c84eff634b ("loop: Add sanity check for read/write_iter")
Signed-off-by: Li Chen <chenl311@chinatelecom.cn>
Reviewed-by: Ming Lei <ming.lei@redhat.com>
Reviewed-by: Yang Erkun <yangerkun@huawei.com>
---
changelog:
v2: add review by, Fixes and cc stable tags.

 drivers/block/loop.c | 8 ++++++--
 1 file changed, 6 insertions(+), 2 deletions(-)

diff --git a/drivers/block/loop.c b/drivers/block/loop.c
index 053a086d547e..94ec7f747f36 100644
--- a/drivers/block/loop.c
+++ b/drivers/block/loop.c
@@ -551,8 +551,10 @@ static int loop_change_fd(struct loop_device *lo, struct block_device *bdev,
 		return -EBADF;
 
 	error = loop_check_backing_file(file);
-	if (error)
+	if (error) {
+		fput(file);
 		return error;
+	}
 
 	/* suppress uevents while reconfiguring the device */
 	dev_set_uevent_suppress(disk_to_dev(lo->lo_disk), 1);
@@ -993,8 +995,10 @@ static int loop_configure(struct loop_device *lo, blk_mode_t mode,
 		return -EBADF;
 
 	error = loop_check_backing_file(file);
-	if (error)
+	if (error) {
+		fput(file);
 		return error;
+	}
 
 	is_loop = is_loop_device(file);
 
-- 
2.51.0


^ permalink raw reply related	[flat|nested] 2+ messages in thread

* Re: [PATCH v2] loop: fix backing file reference leak on validation error
  2025-09-30  0:35 [PATCH v2] loop: fix backing file reference leak on validation error Li Chen
@ 2025-10-02 21:30 ` Jens Axboe
  0 siblings, 0 replies; 2+ messages in thread
From: Jens Axboe @ 2025-10-02 21:30 UTC (permalink / raw)
  To: Lizhi Xu, linux-block, linux-kernel, Li Chen
  Cc: stable, Markus Elfring, Yang Erkun, Ming Lei, Yu Kuai


On Tue, 30 Sep 2025 08:35:59 +0800, Li Chen wrote:
> loop_change_fd() and loop_configure() call loop_check_backing_file()
> to validate the new backing file. If validation fails, the reference
> acquired by fget() was not dropped, leaking a file reference.
> 
> Fix this by calling fput(file) before returning the error.
> 
> 
> [...]

Applied, thanks!

[1/1] loop: fix backing file reference leak on validation error
      commit: 98b7bf54338b797e3a11e8178ce0e806060d8fa3

Best regards,
-- 
Jens Axboe




^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2025-10-02 21:30 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-09-30  0:35 [PATCH v2] loop: fix backing file reference leak on validation error Li Chen
2025-10-02 21:30 ` Jens Axboe

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox