From: Shuah Khan <skhan@linuxfoundation.org>
To: Igor Matheus Andrade Torrente <igormtorrente@gmail.com>,
mchehab@kernel.org
Cc: linux-media@vger.kernel.org, linux-kernel@vger.kernel.org,
hverkuil-cisco@xs4all.nl, Shuah Khan <skhan@linuxfoundation.org>
Subject: Re: [PATCH] media: em28xx: Fix possible memory leak of em28xx struct
Date: Mon, 3 May 2021 16:06:10 -0400 [thread overview]
Message-ID: <dc285959-080a-3809-2f3e-e1de3440374a@linuxfoundation.org> (raw)
In-Reply-To: <20210503173716.21652-1-igormtorrente@gmail.com>
Hi Igor,
On 5/3/21 11:37 AM, Igor Matheus Andrade Torrente wrote:
> The em28xx struct kref isn't being decreased after an error in the
> em28xx_ir_init, leading to a possible memory leak.
>
> A kref_put is added to the error handler code.
>
> Signed-off-by: Igor Matheus Andrade Torrente <igormtorrente@gmail.com>
> ---
> drivers/media/usb/em28xx/em28xx-input.c | 7 +++++--
> 1 file changed, 5 insertions(+), 2 deletions(-)
>
> diff --git a/drivers/media/usb/em28xx/em28xx-input.c b/drivers/media/usb/em28xx/em28xx-input.c
> index 5aa15a7a49de..b89527014cad 100644
> --- a/drivers/media/usb/em28xx/em28xx-input.c
> +++ b/drivers/media/usb/em28xx/em28xx-input.c
> @@ -720,7 +720,8 @@ static int em28xx_ir_init(struct em28xx *dev)
> dev->board.has_ir_i2c = 0;
> dev_warn(&dev->intf->dev,
> "No i2c IR remote control device found.\n");
> - return -ENODEV;
> + err = -ENODEV;
> + goto ref_put;
This doesn't look right. em28xx_init_buttons() is already happened and
em28xx_shutdown_buttons() needs to be done from fini. fini needs to run
with this ref. If ref is released here, device might be released before
em28xx_shutdown_buttons() can run leading to potential use-after-free
> }
> }
>
> @@ -735,7 +736,7 @@ static int em28xx_ir_init(struct em28xx *dev)
>
> ir = kzalloc(sizeof(*ir), GFP_KERNEL);
> if (!ir)
> - return -ENOMEM;
> + goto ref_put;
This doesn't look right. Same comment as above. fini accounts for null
ir.
em28xx_shutdown_buttons(dev);
/* skip detach on non attached boards */
if (!ir)
goto ref_put;
> rc = rc_allocate_device(RC_DRIVER_SCANCODE);
> if (!rc)
> goto error;
> @@ -839,6 +840,8 @@ static int em28xx_ir_init(struct em28xx *dev)
> dev->ir = NULL;
> rc_free_device(rc);
> kfree(ir);
> +ref_put:
> + kref_put(&dev->ref, em28xx_free_device);
> return err;
> }
>
>
thanks,
-- Shuah
next prev parent reply other threads:[~2021-05-03 20:06 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-05-03 17:37 [PATCH] media: em28xx: Fix possible memory leak of em28xx struct Igor Matheus Andrade Torrente
2021-05-03 17:37 ` [PATCH v4] media: em28xx: Fix race condition between open and init function Igor Matheus Andrade Torrente
2021-05-05 11:21 ` Hans Verkuil
2021-05-05 19:54 ` Igor Torrente
2021-05-06 7:47 ` Hans Verkuil
2021-05-06 13:37 ` Igor Torrente
2021-05-03 20:06 ` Shuah Khan [this message]
2021-05-04 19:07 ` [PATCH] media: em28xx: Fix possible memory leak of em28xx struct Igor Torrente
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=dc285959-080a-3809-2f3e-e1de3440374a@linuxfoundation.org \
--to=skhan@linuxfoundation.org \
--cc=hverkuil-cisco@xs4all.nl \
--cc=igormtorrente@gmail.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-media@vger.kernel.org \
--cc=mchehab@kernel.org \
/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;
as well as URLs for NNTP newsgroup(s).