From: alexious@zju.edu.cn
To: "Dan Carpenter" <dan.carpenter@linaro.org>
Cc: "Parthiban Veerasooran" <parthiban.veerasooran@microchip.com>,
"Christian Gromm" <christian.gromm@microchip.com>,
"Dan Carpenter" <error27@gmail.com>,
"Greg Kroah-Hartman" <gregkh@linuxfoundation.org>,
linux-kernel@vger.kernel.org
Subject: Re: [PATCH] most: fix a memleak in audio_probe_channel
Date: Mon, 29 Jan 2024 20:56:52 +0800 (GMT+08:00) [thread overview]
Message-ID: <1eef96d5.2150.18d554b44ca.Coremail.alexious@zju.edu.cn> (raw)
In-Reply-To: <4e065b3a-240e-4cd9-acd8-53e5a56abed0@moroto.mountain>
> On Tue, Jan 23, 2024 at 01:20:44AM +0800, Zhipeng Lu wrote:
> > When get_channel fails, audio_probe_channel should free adpt like all
> > its following error-handling paths after get_channel. Otherwise there
> > could be a memleak.
> >
> > Fixes: 15600aea2754 ("staging: most: sound: create one sound card w/ multiple PCM devices per MOST device")
> > Signed-off-by: Zhipeng Lu <alexious@zju.edu.cn>
> > ---
> > drivers/most/most_snd.c | 3 ++-
> > 1 file changed, 2 insertions(+), 1 deletion(-)
> >
> > diff --git a/drivers/most/most_snd.c b/drivers/most/most_snd.c
> > index 45d762804c5e..6cccc9c26796 100644
> > --- a/drivers/most/most_snd.c
> > +++ b/drivers/most/most_snd.c
> > @@ -564,7 +564,8 @@ static int audio_probe_channel(struct most_interface *iface, int channel_id,
> > if (get_channel(iface, channel_id)) {
> > pr_err("channel (%s:%d) is already linked\n",
> > iface->description, channel_id);
> > - return -EEXIST;
> > + ret = -EEXIST;
> > + goto err_free_adpt;
>
> No, this doesn't work. Someone should add a comment here explaining
> why.
>
> This function is a bit complicated because we sometimes allocate "adpt"
> and sometimes we don't. Why can we not make it consistently one way or
> the other? This is not my code and I don't know. But presumably there
> is a good reason. I looked up the previous discussion of this and found
> this thread.
>
> https://lore.kernel.org/all/78cc59b31042f865e947a2c09a5d10cc60ddc01c.camel@microchip.com/
>
> Anyway, in the end, we're trying to clean up and on the other error
> paths we're allowed to free "adpt" even though we didn't allocate it.
>
> However once it's got a channel linked then we cannot. At that stage
> "adpt" is already added to the &iface->p->channel_list list. The
> release_adapter() adapter function will free it without removing it from
> the list so it leads to a use after free.
>
> However, memory on this path is not leaked as your commit message says.
> "adpt" is still on the lists. The stuff is in a messed up state so the
> user will need to tear it all down manually and recreate the
> configuration. Quoting the email I linked to, "This
> involves the call to mdev_link_destroy_link_store() that cleans up
> everything."
>
> So we can't apply your patch because it leads to a use after free. But
> we could apply a patch which adds a comment like:
>
> /*
> * This error path doesn't leak. If the channel is already set
> * up then something has gone badly wrong. The user will have
> * to tear everything down and reconfigure from scratch. The
> * memory will be released via mdev_link_destroy_link_store().
> *
> */
>
Thank you for your correction and advise.
We would like to submit a new patch to add such comment.\
Regards,
Zhipeng.
> regards,
> dan carpenter
prev parent reply other threads:[~2024-01-29 12:57 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-01-22 17:20 Zhipeng Lu
2024-01-23 6:04 ` Dan Carpenter
2024-01-29 12:56 ` alexious [this message]
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=1eef96d5.2150.18d554b44ca.Coremail.alexious@zju.edu.cn \
--to=alexious@zju.edu.cn \
--cc=christian.gromm@microchip.com \
--cc=dan.carpenter@linaro.org \
--cc=error27@gmail.com \
--cc=gregkh@linuxfoundation.org \
--cc=linux-kernel@vger.kernel.org \
--cc=parthiban.veerasooran@microchip.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
all inboxes | Powered by JetHome®