From: T Pratham <t-pratham@ti.com>
To: Herbert Xu <herbert@gondor.apana.org.au>,
"David S. Miller" <davem@davemloft.net>
Cc: <linux-crypto@vger.kernel.org>, <linux-kernel@vger.kernel.org>,
"Manorit Chawdhry" <m-chawdhry@ti.com>,
Shiva Tripathi <s-tripathi1@ti.com>,
"Kamlesh Gurudasani" <kamlesh@ti.com>
Subject: [BUG] crypto: tcrypt - data corruption in ahash tests with CRYPTO_AHASH_ALG_BLOCK_ONLY
Date: Thu, 15 Jan 2026 15:38:50 +0530 [thread overview]
Message-ID: <70710115-6bde-465b-91f2-a005bede1602@ti.com> (raw)
Hi,
Commit 9d7a0ab1c7536 ("crypto: ahash - Handle partial blocks in API")
introduced partial block handling for ahashes in the crypto API layer
itself.
In ahash with CRYPTO_AHASH_ALG_BLOCK_ONLY flag set, the code replaces
the callback in the request in ahash_save_req:
crypto/ahash.c:
int crypto_ahash_update(struct ahash_request *req)
{
// stuff happens
[...]
ahash_save_req(req, ahash_update_done);
err = ahash_do_req_chain(req, &crypto_ahash_alg(tfm)->update);
if (err == -EINPROGRESS || err == -EBUSY)
return err;
return ahash_update_finish(req, err);
}
Same in crypto_ahash_finup().
When the update or finup returns -EINPROGRESS or -EBUSY, see that
ahash_update_finish/ahash_finup_finish is not called which calls the
ahash_restore_req to restore the callback and data. This seems
intentional as the code wants to call it's custom callback to cleanup
stuff done for block only algos.
However, in tcrypt, the wait struct is accessed as below:
crypto/tcrypt.c:
static inline int do_one_ahash_op(struct ahash_request *req, int ret)
{
struct crypto_wait *wait = req->base.data;
return crypto_wait_req(ret, wait);
}
Hence, when -EINPROGRESS or -EBUSY is returned by ahash, inside tcrypt,
when do_one_ahash_op accesses req->base.data, it gets the modified data
and then goes on to operate with the same, resulting in data corruption
and segfault.
Here are the logs when I test with DTHEv2 SHA512 driver (yet to send
upstream):
https://gist.github.com/Pratham-T/3c017c719d3e8c8a0bc7ea96bf896996
--
Regards
T Pratham <t-pratham@ti.com>
next reply other threads:[~2026-01-15 10:08 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-01-15 10:08 T Pratham [this message]
2026-01-16 2:30 ` Herbert Xu
2026-01-16 8:33 ` T Pratham
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=70710115-6bde-465b-91f2-a005bede1602@ti.com \
--to=t-pratham@ti.com \
--cc=davem@davemloft.net \
--cc=herbert@gondor.apana.org.au \
--cc=kamlesh@ti.com \
--cc=linux-crypto@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=m-chawdhry@ti.com \
--cc=s-tripathi1@ti.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®