From: Harald Freudenberger <freude@linux.ibm.com>
To: sashiko-reviews@lists.linux.dev
Cc: Alexander Gordeev <agordeev@linux.ibm.com>,
Christian Borntraeger <borntraeger@linux.ibm.com>,
linux-s390@vger.kernel.org, Vasily Gorbik <gor@linux.ibm.com>,
Heiko Carstens <hca@linux.ibm.com>
Subject: Re: [PATCH v5 6/8] s390/crypto: Fix handling of EBUSY in PHMAC when req is pushed to crypto engine
Date: Fri, 21 Aug 2026 10:08:11 +0200 [thread overview]
Message-ID: <4be21507d2d364d9a36d81512f4b3e5b@linux.ibm.com> (raw)
In-Reply-To: <20260820143522.7C3221F000E9@smtp.kernel.org>
On 2026-08-20 16:35, sashiko-bot@kernel.org wrote:
> Thank you for your contribution! Sashiko AI review found 1 potential
> issue(s) to consider:
>
> Pre-existing issues:
> - [High] Incorrect module teardown order in `s390_phmac_exit` leads to
> kthread leaks and Use-After-Free of the `crypto_engine`.
> --
>
> --- Patch [6]: [PATCH v5 6/8] s390/crypto: Fix handling of EBUSY in
> PHMAC when req is pushed to crypto engine ---
> commit c74c807c2aeebffc7e981ca45b5b377727342ad1
> Author: Harald Freudenberger <freude@linux.ibm.com>
>
> s390/crypto: Fix handling of EBUSY in PHMAC when req is pushed to
> crypto engine
>
> When a request is transferred to the engine via
> crypto_transfer_hash_request_to_engine() there are two return codes
> signaling a successful transfer: EINPROGRESS and EBUSY. However the
> correct handling of EBUSY was missing and has been added as a return
> code indicating a successful transfer to the crypto engine.
>
> Cc: stable@vger.kernel.org # 6.17+
>
>> diff --git a/arch/s390/crypto/phmac_s390.c
>> b/arch/s390/crypto/phmac_s390.c
>> index 03ca33ffe6ccf..30c8a59af1a4e 100644
>> --- a/arch/s390/crypto/phmac_s390.c
>> +++ b/arch/s390/crypto/phmac_s390.c
>
> [ ... ]
>
>> @@ -716,15 +726,17 @@ static int phmac_finup(struct ahash_request
>> *req)
>> /* req->async_op has been set to either OP_FINUP or OP_FINAL */
>> atomic_inc(&tfm_ctx->via_engine_ctr);
>> rc = crypto_transfer_hash_request_to_engine(phmac_crypto_engine,
>> req);
>> - if (rc != -EINPROGRESS)
>> + if (rc == -EINPROGRESS || rc == -EBUSY)
>> + cleanup = false;
>> + else
>> atomic_dec(&tfm_ctx->via_engine_ctr);
>> }
>>
>> - if (rc != -EINPROGRESS)
>> + if (cleanup && hwh->walkbytes > 0)
>> hwh_advance(hwh, rc);
>>
>> out:
>> - if (rc != -EINPROGRESS)
>> + if (cleanup)
>> memzero_explicit(kmac_ctx, sizeof(*kmac_ctx));
>> pr_debug("rc=%d\n", rc);
>> return rc;
>
> [Severity: High]
> This is a pre-existing issue, but while reviewing this file I noticed a
> potential module teardown order problem in s390_phmac_exit() in
> arch/s390/crypto/phmac_s390.c:
>
> if (phmac_crypto_engine) {
> crypto_engine_stop(phmac_crypto_engine);
> crypto_engine_exit(phmac_crypto_engine);
> }
>
> for (i = ARRAY_SIZE(phmac_algs) - 1; i >= 0; i--) {
> phmac = &phmac_algs[i];
> if (phmac->registered)
> crypto_engine_unregister_ahash(&phmac->alg);
> }
>
> Could this lead to kthread leaks and a use-after-free of the
> crypto_engine?
>
> If s390_phmac_init() fails to register a subsequent algorithm after
> successfully registering the first, it jumps to the error path and
> calls s390_phmac_exit().
>
> Because the first algorithm is already registered and the module is in
> MODULE_STATE_COMING, a concurrent userspace program can successfully
> allocate it and continuously submit hash requests.
>
> Since s390_phmac_exit() calls crypto_engine_stop() before unregistering
> the algorithms, the continuous stream of requests keeps the engine
> busy.
> This can cause crypto_engine_stop() to time out and return -EBUSY,
> which leads to crypto_engine_exit() returning without destroying the
> kworker thread.
>
> Finally, misc_deregister() destroys the device, freeing the
> devm-managed
> crypto_engine struct, and the module is subsequently unloaded.
>
> Would the still-running kworker thread then access freed memory and
> execute freed module code, potentially causing a kernel panic?
This will be addressed in another series. There is a new tracking
bugzilla for this:
https://bugzilla.linux.ibm.com/show_bug.cgi?id=222134
next prev parent reply other threads:[~2026-08-21 8:08 UTC|newest]
Thread overview: 19+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-08-20 14:19 [PATCH v5 0/8] Fixes and rework for paes_s390 and phmac_s390 Harald Freudenberger
2026-08-20 14:19 ` [PATCH v5 1/8] s390/crypto: Fix return code handling at skcipher_walk_done in PAES algorithms Harald Freudenberger
2026-08-20 14:30 ` sashiko-bot
2026-08-20 14:19 ` [PATCH v5 2/8] s390/crypto: Fix missing scrub of temp buffers with PAES algorithm Harald Freudenberger
2026-08-20 14:29 ` sashiko-bot
2026-08-20 14:19 ` [PATCH v5 3/8] s390/crypto: Fix use of mutex in atomic context in PAES Harald Freudenberger
2026-08-20 14:29 ` sashiko-bot
2026-08-20 14:19 ` [PATCH v5 4/8] s390/crypto: Fix missing cra_flags in paes_s390 Harald Freudenberger
2026-08-20 14:26 ` sashiko-bot
2026-08-20 14:19 ` [PATCH v5 5/8] s390/crypto: Fix handling of EBUSY in PAES when req is pushed to crypto engine Harald Freudenberger
2026-08-20 14:31 ` sashiko-bot
2026-08-20 14:19 ` [PATCH v5 6/8] s390/crypto: Fix handling of EBUSY in PHMAC " Harald Freudenberger
2026-08-20 14:35 ` sashiko-bot
2026-08-21 8:08 ` Harald Freudenberger [this message]
2026-08-20 14:19 ` [PATCH v5 7/8] s390/crypto: Fix wrong return code to engine in asynch callbacks Harald Freudenberger
2026-08-20 14:26 ` sashiko-bot
2026-08-20 14:19 ` [PATCH v5 8/8] s390/crypto: Map EBUSY to EIO when key conversion fails repeatedly Harald Freudenberger
2026-08-20 14:32 ` sashiko-bot
2026-08-21 8:10 ` Holger Dengler
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=4be21507d2d364d9a36d81512f4b3e5b@linux.ibm.com \
--to=freude@linux.ibm.com \
--cc=agordeev@linux.ibm.com \
--cc=borntraeger@linux.ibm.com \
--cc=gor@linux.ibm.com \
--cc=hca@linux.ibm.com \
--cc=linux-s390@vger.kernel.org \
--cc=sashiko-reviews@lists.linux.dev \
/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).