From: Li Chen Date: Tue, 30 Sep 2025 00:35:59 +0000 (+0800) Subject: loop: fix backing file reference leak on validation error X-Git-Tag: v6.18-rc1~20^2~6 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=98b7bf54338b797e3a11e8178ce0e806060d8fa3;p=thirdparty%2Flinux.git 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 CC: Yang Erkun Cc: Ming Lei Cc: Yu Kuai Fixes: f5c84eff634b ("loop: Add sanity check for read/write_iter") Signed-off-by: Li Chen Reviewed-by: Ming Lei Reviewed-by: Yang Erkun Signed-off-by: Jens Axboe --- diff --git a/drivers/block/loop.c b/drivers/block/loop.c index 053a086d547ec..94ec7f747f367 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);