From: Mikulas Patocka <mpatocka@redhat.com>
To: Herbert Xu <herbert@gondor.apana.org.au>
Cc: "David S. Miller" <davem@davemloft.net>,
Harald Freudenberger <freude@linux.ibm.com>,
Ingo Franzki <ifranzki@linux.ibm.com>,
linux-crypto@vger.kernel.org, Eric Biggers <ebiggers@kernel.org>,
dengler@linux.ibm.com, linux-s390@vger.kernel.org,
dm-devel@lists.linux.dev, agk@redhat.com, snitzer@kernel.org,
Milan Broz <gmazyland@gmail.com>
Subject: Re: [PATCH] crypto/authenc: don't return -EBUSY when enqueuing the hash request
Date: Tue, 23 Sep 2025 16:36:05 +0200 (CEST) [thread overview]
Message-ID: <1235adba-148c-c9ea-12d2-dd407a3ae28d@redhat.com> (raw)
In-Reply-To: <194f9d1e-b6b0-54c7-6eb8-37ac0c0c1f9d@redhat.com>
On Tue, 23 Sep 2025, Mikulas Patocka wrote:
>
>
> On Tue, 23 Sep 2025, Herbert Xu wrote:
>
> > If authenc gets EBUSY from the ahash, then the ahash is responsible
> > for sending an EINPROGRESS notification. I just checked the authenc
> > code and it does pass the notification back up to the caller (which
> > is dm-crypt).
> >
> > So if EINPROGRESS is not being received, then it's a bug in the
> > ahash layer or the underlying ahash algorithm.
>
> static void authenc_request_complete(struct aead_request *req, int err)
> {
> if (err != -EINPROGRESS)
> aead_request_complete(req, err);
> }
>
> This prevents -EINPROGRESS from reaching dm-crypt. If I remove the
> condition "err != -EINPROGRESS", the deadlock goes away. Though, removing
> it may break other things - we may send -EINPROGRESS twice, first for the
> hash and then for the decryption.
>
> > Which phmac implementation was this?
>
> It was pseudo_phmac out-of-tree module sent by Harald Freudenberger. He
> CC'd you, so you should have it as an attachment in your inbox.
>
> The following scripts creates the buggy device mapper device:
>
> #!/bin/sh -ex
> sync
> modprobe crypto_engine
> insmod ~/c/phmac/pseudo_phmac/phmac.ko
> modprobe brd rd_size=1048576
> dmsetup create cr_dif --table '0 2031880 integrity 1:0 32768 32 J 7 block_size:4096 interleave_sectors:32768 buffer_sectors:128 journal_sectors:16368 journal_watermark:50 commit_time:10000 fix_padding'
> dmsetup create cr --table '0 2031880 crypt capi:authenc(phmac(sha256),xts(aes))-plain64 00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000 0 252:0 0 2 integrity:32:aead sector_size:4096'
> dd if=/dev/zero of=/dev/mapper/cr bs=1M oflag=direct status=progress
>
> > Cheers,
>
> Mikulas
What do you think about this patch? Do you think that it is the right
direction to fix it?
Mikulas
From: Mikulas Patocka <mpatocka@redhat.com>
The function authenc_request_complete ignores -EINPROGRESS. This causes
deadlock in dm-crypt when using it with authenticated encryption with an
asynchronous hash implementation.
This patch makes it pass -EINPROGRESS to the caller. Note that we don't
want to report -EINPROGRESS twice (one for the hash and the second one
for the cipher), so we set a flag and report -EINPROGRESS just once.
Signed-off-by: Mikulas Patocka <mpatocka@redhat.com>
---
crypto/authenc.c | 11 +++++++++--
include/linux/crypto.h | 1 +
2 files changed, 10 insertions(+), 2 deletions(-)
Index: linux-2.6/crypto/authenc.c
===================================================================
--- linux-2.6.orig/crypto/authenc.c 2025-09-23 16:15:42.000000000 +0200
+++ linux-2.6/crypto/authenc.c 2025-09-23 16:32:57.000000000 +0200
@@ -37,8 +37,15 @@ struct authenc_request_ctx {
static void authenc_request_complete(struct aead_request *req, int err)
{
- if (err != -EINPROGRESS)
- aead_request_complete(req, err);
+ if (unlikely(err == -EINPROGRESS)) {
+ req->base.flags |= CRYPTO_TFM_REQ_REPORT_EINPROGRESS;
+ return;
+ }
+ if (unlikely(req->base.flags & CRYPTO_TFM_REQ_REPORT_EINPROGRESS)) {
+ aead_request_complete(req, -EINPROGRESS);
+ req->base.flags &=~ CRYPTO_TFM_REQ_REPORT_EINPROGRESS;
+ }
+ aead_request_complete(req, err);
}
int crypto_authenc_extractkeys(struct crypto_authenc_keys *keys, const u8 *key,
Index: linux-2.6/include/linux/crypto.h
===================================================================
--- linux-2.6.orig/include/linux/crypto.h 2025-08-15 17:28:24.000000000 +0200
+++ linux-2.6/include/linux/crypto.h 2025-09-23 16:17:05.000000000 +0200
@@ -151,6 +151,7 @@
#define CRYPTO_TFM_REQ_MAY_SLEEP 0x00000200
#define CRYPTO_TFM_REQ_MAY_BACKLOG 0x00000400
#define CRYPTO_TFM_REQ_ON_STACK 0x00000800
+#define CRYPTO_TFM_REQ_REPORT_EINPROGRESS 0x00100000
/*
* Miscellaneous stuff.
next prev parent reply other threads:[~2025-09-23 14:36 UTC|newest]
Thread overview: 34+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-09-08 13:16 [PATCH v2 0/7] dm-integrity: asynchronous hash support Mikulas Patocka
2025-09-08 13:16 ` [PATCH v2 1/7] dm-integrity: use internal variable for digestsize Mikulas Patocka
2025-09-08 13:16 ` [PATCH v2 2/7] dm-integrity: replace bvec_kmap_local with kmap_local_page Mikulas Patocka
2025-09-08 13:16 ` [PATCH v2 3/7] dm-integrity: introduce integrity_kmap and integrity_kunmap Mikulas Patocka
2025-09-08 13:16 ` [PATCH v2 4/7] dm-integrity: allocate the recalculate buffer with kmalloc Mikulas Patocka
2025-09-08 13:16 ` [PATCH v2 5/7] dm-integrity: add the "offset" argument Mikulas Patocka
2025-09-08 13:16 ` [PATCH v2 6/7] dm-integrity: rename internal_hash Mikulas Patocka
2025-09-08 13:16 ` [PATCH v2 7/7] dm-integrity: enable asynchronous hash interface Mikulas Patocka
2025-09-09 9:04 ` [PATCH v2 0/7] dm-integrity: asynchronous hash support Ingo Franzki
2025-09-09 9:42 ` Mikulas Patocka
2025-09-09 11:18 ` Ingo Franzki
2025-09-09 11:47 ` Milan Broz
2025-09-09 11:50 ` Ingo Franzki
2025-09-09 12:15 ` Milan Broz
2025-09-09 12:23 ` Ingo Franzki
2025-09-09 12:40 ` Milan Broz
2025-09-09 13:51 ` Harald Freudenberger
2025-09-09 14:12 ` Milan Broz
2025-09-11 13:43 ` Ingo Franzki
2025-09-11 15:58 ` Mikulas Patocka
2025-09-12 8:08 ` Ingo Franzki
2025-09-15 9:26 ` Harald Freudenberger
2025-09-18 15:00 ` Harald Freudenberger
2025-09-19 6:53 ` Ingo Franzki
2025-09-22 19:08 ` [PATCH] crypto/authenc: don't return -EBUSY when enqueuing the hash request Mikulas Patocka
2025-09-23 3:47 ` Herbert Xu
2025-09-23 11:14 ` Mikulas Patocka
2025-09-23 14:36 ` Mikulas Patocka [this message]
2025-09-23 15:17 ` Herbert Xu
2025-09-24 10:20 ` [PATCH] crypto: authenc - Correctly pass EINPROGRESS back up to the caller Herbert Xu
2025-09-24 13:17 ` Ingo Franzki
2025-11-25 14:02 ` [PATCH] crypto/authenc: don't return -EBUSY when enqueuing the hash request Mikulas Patocka
2025-11-26 5:16 ` Herbert Xu
2025-09-09 13:36 ` [PATCH v2 0/7] dm-integrity: asynchronous hash support Harald Freudenberger
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=1235adba-148c-c9ea-12d2-dd407a3ae28d@redhat.com \
--to=mpatocka@redhat.com \
--cc=agk@redhat.com \
--cc=davem@davemloft.net \
--cc=dengler@linux.ibm.com \
--cc=dm-devel@lists.linux.dev \
--cc=ebiggers@kernel.org \
--cc=freude@linux.ibm.com \
--cc=gmazyland@gmail.com \
--cc=herbert@gondor.apana.org.au \
--cc=ifranzki@linux.ibm.com \
--cc=linux-crypto@vger.kernel.org \
--cc=linux-s390@vger.kernel.org \
--cc=snitzer@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