Skip to content

Commit 98b7bf5

Browse files
FirstLoveLifeaxboe
authored andcommitted
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: [email protected] Cc: Markus Elfring <[email protected]> CC: Yang Erkun <[email protected]> Cc: Ming Lei <[email protected]> Cc: Yu Kuai <[email protected]> Fixes: f5c84ef ("loop: Add sanity check for read/write_iter") Signed-off-by: Li Chen <[email protected]> Reviewed-by: Ming Lei <[email protected]> Reviewed-by: Yang Erkun <[email protected]> Signed-off-by: Jens Axboe <[email protected]>
1 parent e1b1d03 commit 98b7bf5

1 file changed

Lines changed: 6 additions & 2 deletions

File tree

drivers/block/loop.c

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

553553
error = loop_check_backing_file(file);
554-
if (error)
554+
if (error) {
555+
fput(file);
555556
return error;
557+
}
556558

557559
/* suppress uevents while reconfiguring the device */
558560
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,
993995
return -EBADF;
994996

995997
error = loop_check_backing_file(file);
996-
if (error)
998+
if (error) {
999+
fput(file);
9971000
return error;
1001+
}
9981002

9991003
is_loop = is_loop_device(file);
10001004

0 commit comments

Comments
 (0)