Linux block layer
 help / color / mirror / Atom feed
From: Li Chen <me@linux.beauty>
To: "Yu Kuai" <yukuai1@huaweicloud.com>
Cc: "Jens Axboe" <axboe@kernel.dk>,
	"linux-block" <linux-block@vger.kernel.org>,
	"linux-kernel" <linux-kernel@vger.kernel.org>,
	"yukuai" <yukuai3@huawei.com>
Subject: Re: [PATCH] loop: fix backing file reference leak on validation error
Date: Mon, 29 Sep 2025 20:56:30 +0800	[thread overview]
Message-ID: <199958bca6a.7ea76c7c550787.2798726002425326647@linux.beauty> (raw)
In-Reply-To: <68aebe91-4dcd-925f-4232-1c432fe6899d@huaweicloud.com>

Hi Yu,

 ---- On Mon, 29 Sep 2025 09:11:04 +0800  Yu Kuai <yukuai1@huaweicloud.com> wrote --- 
 > Hi,
 > 
 > 在 2025/09/26 20:12, Li Chen 写道:
 > > 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.
 > > 
 > > Signed-off-by: Li Chen <chenl311@chinatelecom.cn>
 > > ---
 > >   drivers/block/loop.c | 8 ++++++--
 > >   1 file changed, 6 insertions(+), 2 deletions(-)
 > > 
 > > diff --git a/drivers/block/loop.c b/drivers/block/loop.c
 > > index 053a086d547e..94ec7f747f36 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);
 > >   
 > > 
 > 
 > The changes look correct, however, I'll prefer to change the error path
 > to the reverse order and add a new error tag.

Thanks, but I will switch to scope-based resource management in v2, as suggested by Markus.

Regards,
Li

  reply	other threads:[~2025-09-29 12:56 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-09-26 12:12 [PATCH] loop: fix backing file reference leak on validation error Li Chen
2025-09-28  1:54 ` yangerkun
2025-09-29 12:54   ` Li Chen
2025-09-28 13:48 ` Markus Elfring
2025-09-29 12:53   ` Li Chen
2025-09-29 15:01     ` Ming Lei
2025-09-30  0:05       ` Li Chen
2025-09-29  1:11 ` Yu Kuai
2025-09-29 12:56   ` Li Chen [this message]
2025-09-29  5:14 ` Ming Lei

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=199958bca6a.7ea76c7c550787.2798726002425326647@linux.beauty \
    --to=me@linux.beauty \
    --cc=axboe@kernel.dk \
    --cc=linux-block@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=yukuai1@huaweicloud.com \
    --cc=yukuai3@huawei.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox