From: Pierre-Louis Bossart <pierre-louis.bossart@linux.intel.com>
To: Daniil Dulov <d.dulov@aladdin.ru>, Vinod Koul <vkoul@kernel.org>
Cc: Bard Liao <yung-chuan.liao@linux.intel.com>,
Sanyog Kale <sanyog.r.kale@intel.com>,
alsa-devel@alsa-project.org, linux-kernel@vger.kernel.org,
lvc-project@linuxtesting.org
Subject: Re: [PATCH] soundwire: fix double free of pointer
Date: Mon, 12 Feb 2024 08:49:11 -0600 [thread overview]
Message-ID: <83c8bfa3-4377-4198-b48e-351f9a9f63ed@linux.intel.com> (raw)
In-Reply-To: <20240211150937.4058-1-d.dulov@aladdin.ru>
On 2/11/24 09:09, Daniil Dulov wrote:
> If sdw_ml_sync_bank_switch() returns error not on the first iteration,
> it leads to freeing prevously freed memory. So, set the pointer to NULL
> after each successful bank switch.
>
> Signed-off-by: Daniil Dulov <d.dulov@aladdin.ru>
> ---
> drivers/soundwire/stream.c | 1 +
> 1 file changed, 1 insertion(+)
>
> diff --git a/drivers/soundwire/stream.c b/drivers/soundwire/stream.c
> index 304ff2ee7d75..d650e6f0f8e7 100644
> --- a/drivers/soundwire/stream.c
> +++ b/drivers/soundwire/stream.c
> @@ -833,6 +833,7 @@ static int do_bank_switch(struct sdw_stream_runtime *stream)
> "multi link bank switch failed: %d\n", ret);
> goto error;
> }
> + bus->defer_msg.msg = NULL;
>
> if (multi_link)
> mutex_unlock(&bus->msg_lock);
Not following what the issue is...
On success, sdw_ml_sync_bank_switch() frees the buffers with
if (bus->defer_msg.msg) {
kfree(bus->defer_msg.msg->buf);
kfree(bus->defer_msg.msg);
bus->defer_msg.msg = NULL;
}
So if there is an issue on the second iteration, then the loop will
detect already freed memory in the previous iteration and skip it:
/* Check if bank switch was successful */
ret = sdw_ml_sync_bank_switch(bus);
if (ret < 0) {
dev_err(bus->dev,
"multi link bank switch failed: %d\n", ret);
goto error;
}
error:
list_for_each_entry(m_rt, &stream->master_list, stream_node) {
bus = m_rt->bus;
if (bus->defer_msg.msg) { <<<< TEST FOR FREED MEMORY
kfree(bus->defer_msg.msg->buf);
kfree(bus->defer_msg.msg);
bus->defer_msg.msg = NULL;
}
}
It could very well be that I need more coffee on this post-SuperBowl
Monday morning, but I just don't see the problem.
prev parent reply other threads:[~2024-02-12 14:54 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-02-11 15:09 [PATCH] soundwire: fix double free of pointer Daniil Dulov
2024-02-12 14:49 ` Pierre-Louis Bossart [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=83c8bfa3-4377-4198-b48e-351f9a9f63ed@linux.intel.com \
--to=pierre-louis.bossart@linux.intel.com \
--cc=alsa-devel@alsa-project.org \
--cc=d.dulov@aladdin.ru \
--cc=linux-kernel@vger.kernel.org \
--cc=lvc-project@linuxtesting.org \
--cc=sanyog.r.kale@intel.com \
--cc=vkoul@kernel.org \
--cc=yung-chuan.liao@linux.intel.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