loop: fix backing file reference leak on validation error
Subsystems (2)
PATCH v2 1/1 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 "Markus Elfring"<[email protected]>
CC "Yang Erkun" <[email protected]>
Cc "Ming Lei"<[email protected]>
Cc "Yu Kuai"<[email protected]>
Fixes f5c84eff634b ("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]>
---
changelog:
v2: add review by, Fixes and cc stable tags.
drivers/block/loop.c | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-)
drivers/block/loop.c +6 -2
@@ -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);
Signature · 1 line
2.51.0
Quoted 8 lines · Li Chen
loop_change_fd()andloop_configure()callloop_check_backing_file()to validate the new backing file. If validation fails, the reference acquired byfget()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,
Signature · 1 line
Jens Axboe