Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

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: 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>
Signed-off-by: Jens Axboe <axboe@kernel.dk>

authored by

Li Chen and committed by
Jens Axboe
98b7bf54 e1b1d03c

+6 -2
+6 -2
drivers/block/loop.c
··· 551 551 return -EBADF; 552 552 553 553 error = loop_check_backing_file(file); 554 - if (error) 554 + if (error) { 555 + fput(file); 555 556 return error; 557 + } 556 558 557 559 /* suppress uevents while reconfiguring the device */ 558 560 dev_set_uevent_suppress(disk_to_dev(lo->lo_disk), 1); ··· 995 993 return -EBADF; 996 994 997 995 error = loop_check_backing_file(file); 998 - if (error) 996 + if (error) { 997 + fput(file); 999 998 return error; 999 + } 1000 1000 1001 1001 is_loop = is_loop_device(file); 1002 1002