From: Dinh Nguyen <dinguyen@kernel.org>
To: Krzysztof Kozlowski <krzysztof.kozlowski@oss.qualcomm.com>,
Matthew Gerlach <matthew.gerlach@altera.com>,
Mahesh Rao <mahesh.rao@altera.com>,
linux-kernel@vger.kernel.org
Cc: Sashiko <sashiko-bot@kernel.org>, stable@vger.kernel.org
Subject: Re: [PATCH] firmware: stratix10-svc: Use proper atomic to fix possible double free
Date: Mon, 9 Nov 2026 11:29:23 -0600 [thread overview]
Message-ID: <4e1b3b0d-f831-450f-9974-746c86ef0c23@kernel.org> (raw)
In-Reply-To: <20261101122908.46723-2-krzysztof.kozlowski@oss.qualcomm.com>
On 11/1/26 06:29, Krzysztof Kozlowski wrote:
> Doing atomic_dec() and then separate atomic_read() leaves small race
> window leading to double free in stratix10_svc_remove_async_client():
>
> CPU 0 CPU 1
> ===== =====
> refcount == 2
>
> stratix10_svc_remove_async_client() stratix10_svc_remove_async_client()
> atomic_dec(&refcount);
> atomic_dec(&refcount);
> if (atomic_read(&refcount) == 0)
> kfree(achan);
> if (atomic_read(&refcount) == 0)
> kfree(achan); // double free
>
> Reported-by: Sashiko <sashiko-bot@kernel.org>
> Closes: https://sashiko.dev/#/bug/linux-506b1474-e503-4085-b62a-929cde036317
> Fixes: bcb9f4f07061 ("firmware: stratix10-svc: Add support for async communication")
> Cc: <stable@vger.kernel.org>
> Signed-off-by: Krzysztof Kozlowski <krzysztof.kozlowski@oss.qualcomm.com>
> ---
> drivers/firmware/stratix10-svc.c | 3 +--
> 1 file changed, 1 insertion(+), 2 deletions(-)
>
> diff --git a/drivers/firmware/stratix10-svc.c b/drivers/firmware/stratix10-svc.c
> index 88391ea161ed..aca4d354bdd7 100644
> --- a/drivers/firmware/stratix10-svc.c
> +++ b/drivers/firmware/stratix10-svc.c
> @@ -1444,8 +1444,7 @@ int stratix10_svc_remove_async_client(struct stratix10_svc_chan *chan)
> }
>
> if (achan == actrl->common_async_chan) {
> - atomic_dec(&actrl->common_achan_refcount);
> - if (atomic_read(&actrl->common_achan_refcount) == 0) {
> + if (atomic_dec_and_test(&actrl->common_achan_refcount)) {
> ida_destroy(&achan->job_id_pool);
> ida_free(&actrl->async_id_pool,
> achan->async_client_id);
Applied!
Thanks,
Dinh
prev parent reply other threads:[~2026-11-09 17:29 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-01 12:29 Krzysztof Kozlowski
2026-11-09 17:29 ` Dinh Nguyen [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=4e1b3b0d-f831-450f-9974-746c86ef0c23@kernel.org \
--to=dinguyen@kernel.org \
--cc=krzysztof.kozlowski@oss.qualcomm.com \
--cc=linux-kernel@vger.kernel.org \
--cc=mahesh.rao@altera.com \
--cc=matthew.gerlach@altera.com \
--cc=sashiko-bot@kernel.org \
--cc=stable@vger.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
all inboxes | Powered by JetHome®