From: Herbert Xu <herbert@gondor.apana.org.au>
To: Chen Ridong <chenridong@huaweicloud.com>
Cc: steffen.klassert@secunet.com, daniel.m.jordan@oracle.com,
nstange@suse.de, linux-crypto@vger.kernel.org,
linux-kernel@vger.kernel.org, chenridong@huawei.com,
wangweiyang2@huawei.com
Subject: Re: [PATCH v2 3/3] padata: avoid UAF for reorder_work
Date: Fri, 23 May 2025 11:59:29 +0800 [thread overview]
Message-ID: <aC_yoWXJcsLxfLR4@gondor.apana.org.au> (raw)
In-Reply-To: <20250110061639.1280907-4-chenridong@huaweicloud.com>
On Fri, Jan 10, 2025 at 06:16:39AM +0000, Chen Ridong wrote:
> From: Chen Ridong <chenridong@huawei.com>
>
> Although the previous patch can avoid ps and ps UAF for _do_serial, it
> can not avoid potential UAF issue for reorder_work. This issue can
> happen just as below:
>
> crypto_request crypto_request crypto_del_alg
> padata_do_serial
> ...
> padata_reorder
> // processes all remaining
> // requests then breaks
> while (1) {
> if (!padata)
> break;
> ...
> }
>
> padata_do_serial
> // new request added
> list_add
> // sees the new request
> queue_work(reorder_work)
> padata_reorder
> queue_work_on(squeue->work)
> ...
>
> <kworker context>
> padata_serial_worker
> // completes new request,
> // no more outstanding
> // requests
>
> crypto_del_alg
> // free pd
>
> <kworker context>
> invoke_padata_reorder
> // UAF of pd
Looking back this explanation is actually broken. The call
crypto_del_alg does not free anything immediately. It can only
start freeing things once the final tfm user goes away. Any crypto
request of that tfm must have completed before that happens.
If not there is a serious bug in the Crypto API.
So if crypto_del_alg is leading to a freeing of the pd while there
are still outstanding users of that tfm, then this points to a bug
in the Crypto API and not padata.
Can you still reproduce this bug easily if you revert the patches
in this series? If so we should be able to track down the real bug.
To recap, every tfm holds a ref count on the underlying crypto_alg.
All crypto requests must complete before a tfm can be freed, which
then leads to a drop of the refcount on crypto_alg.
A crypto_alg can only be freed when its ref count hits zero. Only
then will the associated pd be freed.
So what's missing in the above picture is the entity that is freeing
the tfm, thus leading to the actual freeing of the alg and pd.
Thanks,
--
Email: Herbert Xu <herbert@gondor.apana.org.au>
Home Page: http://gondor.apana.org.au/~herbert/
PGP Key: http://gondor.apana.org.au/~herbert/pubkey.txt
next prev parent reply other threads:[~2025-05-23 3:59 UTC|newest]
Thread overview: 12+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-01-10 6:16 [PATCH v2 0/3] padata: fix UAF issues Chen Ridong
2025-01-10 6:16 ` [PATCH v2 1/3] padata: add pd get/put refcnt helper Chen Ridong
2025-01-13 16:57 ` Daniel Jordan
2025-01-10 6:16 ` [PATCH v2 2/3] padata: fix UAF in padata_reorder Chen Ridong
2025-01-13 16:57 ` Daniel Jordan
2025-01-10 6:16 ` [PATCH v2 3/3] padata: avoid UAF for reorder_work Chen Ridong
2025-01-13 17:00 ` Daniel Jordan
2025-01-14 12:22 ` chenridong
2025-05-23 3:59 ` Herbert Xu [this message]
2025-05-26 1:15 ` Chen Ridong
2025-05-26 2:16 ` Herbert Xu
2025-01-19 4:45 ` [PATCH v2 0/3] padata: fix UAF issues Herbert Xu
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=aC_yoWXJcsLxfLR4@gondor.apana.org.au \
--to=herbert@gondor.apana.org.au \
--cc=chenridong@huawei.com \
--cc=chenridong@huaweicloud.com \
--cc=daniel.m.jordan@oracle.com \
--cc=linux-crypto@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=nstange@suse.de \
--cc=steffen.klassert@secunet.com \
--cc=wangweiyang2@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