Skip to content

Commit bac1b8d

Browse files
author
Ming Lei
committed
loop: fix backing file reference leak on validation error
JIRA: https://issues.redhat.com/browse/RHEL-118049 commit 98b7bf5 Author: Li Chen <me@linux.beauty> Date: Tue Sep 30 08:35:59 2025 +0800 loop: fix backing file reference leak on validation error 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: f5c84ef ("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> Signed-off-by: Jens Axboe <axboe@kernel.dk> Signed-off-by: Ming Lei <ming.lei@redhat.com>
1 parent 14c3cf9 commit bac1b8d

File tree

1 file changed

+6
-2
lines changed

1 file changed

+6
-2
lines changed

drivers/block/loop.c

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -541,8 +541,10 @@ static int loop_change_fd(struct loop_device *lo, struct block_device *bdev,
541541
return -EBADF;
542542

543543
error = loop_check_backing_file(file);
544-
if (error)
544+
if (error) {
545+
fput(file);
545546
return error;
547+
}
546548

547549
/* suppress uevents while reconfiguring the device */
548550
dev_set_uevent_suppress(disk_to_dev(lo->lo_disk), 1);
@@ -983,8 +985,10 @@ static int loop_configure(struct loop_device *lo, blk_mode_t mode,
983985
return -EBADF;
984986

985987
error = loop_check_backing_file(file);
986-
if (error)
988+
if (error) {
989+
fput(file);
987990
return error;
991+
}
988992

989993
is_loop = is_loop_device(file);
990994

0 commit comments

Comments
 (0)