Linux s390 Architecture development
 help / color / mirror / Atom feed
From: Harald Freudenberger <freude@linux.ibm.com>
To: sashiko-reviews@lists.linux.dev
Cc: Heiko Carstens <hca@linux.ibm.com>,
	Alexander Gordeev <agordeev@linux.ibm.com>,
	Christian Borntraeger <borntraeger@linux.ibm.com>,
	linux-s390@vger.kernel.org, Vasily Gorbik <gor@linux.ibm.com>
Subject: Re: [PATCH v6 3/9] s390/crypto: Fix use of mutex in atomic context in PAES
Date: Fri, 21 Aug 2026 11:01:43 +0200	[thread overview]
Message-ID: <5f077680b9797530ea64aef75ff56f8f@linux.ibm.com> (raw)
In-Reply-To: <20260821085635.D6BC61F000E9@smtp.kernel.org>

On 2026-08-21 10:56, sashiko-bot@kernel.org wrote:
> Thank you for your contribution! Sashiko AI review found 1 potential
> issue(s) to consider:
> 
> Pre-existing issues:
> - [High] The `aes_s390.c` module contains the exact same locking bug
> in atomic context that this patch fixes in `paes_s390.c`. The
> `ctr_aes_crypt()` function uses `mutex_trylock(&ctrblk_lock)` and
> subsequently calls `mutex_unlock(&ctrblk_lock)`. As the patch's commit
> message notes, mutexes are not safe to use in atomic or interrupt
> context. Synchronous skcipher algorithms like `ctr-aes-s390` can be
> invoked directly from `softirq` context (e.g., by the IPsec stack).
> Calling `mutex_unlock()` in `softirq` is a strict violation of kernel
> locking rules.
> --
> 
> --- Patch [3]: [PATCH v6 3/9] s390/crypto: Fix use of mutex in atomic
> context in PAES ---
> commit 425e8f1d3532a176433992d286f917e0fd14ff9e
> Author: Harald Freudenberger <freude@linux.ibm.com>
> 
> s390/crypto: Fix use of mutex in atomic context in PAES
> 
> This commit fixes a locking issue in the PAES CTR implementation where 
> a
> mutex was used in atomic or interrupt context. It replaces the mutex 
> with
> a binary semaphore which is safe to use in such environments.
> 
>> diff --git a/arch/s390/crypto/paes_s390.c 
>> b/arch/s390/crypto/paes_s390.c
>> --- a/arch/s390/crypto/paes_s390.c
>> +++ b/arch/s390/crypto/paes_s390.c
> [ ... ]
>> @@ -45,7 +45,7 @@ module_param_named(clrkey, pkey_clrkey_allowed, 
>> bool, 0444);
>>  MODULE_PARM_DESC(clrkey, "Allow clear key material (default N)");
>> 
>>  static u8 *ctrblk;
>> -static DEFINE_MUTEX(ctrblk_lock);
>> +static DEFINE_SEMAPHORE(ctrblk_sem, 1);
> 
> [Severity: High]
> This isn't a bug introduced by this patch, but 
> arch/s390/crypto/aes_s390.c
> appears to have the exact same bug that this patch is fixing here.
> 
> Looking at ctr_aes_crypt() in aes_s390.c:
> 
> 	locked = mutex_trylock(&ctrblk_lock);
> 
> 	ret = skcipher_walk_virt(&walk, req, false);
> 	while ((nbytes = walk.nbytes) >= AES_BLOCK_SIZE) {
> 		...
> 	}
> 	if (locked)
> 		mutex_unlock(&ctrblk_lock);
> 
> Since synchronous skcipher algorithms like ctr-aes-s390 can be invoked 
> from
> softirq context (such as by the IPsec stack), would calling 
> mutex_unlock()
> here trigger a lockdep splat or crash, especially on PREEMPT_RT where
> mutex_unlock() must be called from process context?
> 
> Does aes_s390.c also need to be converted to use a binary semaphore?

Allready addressed and fixed with the aes_s390 patch series.

  reply	other threads:[~2026-08-21  9:01 UTC|newest]

Thread overview: 21+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-08-21  8:46 [PATCH v6 0/9] Fixes and rework for paes_s390 and phmac_s390 Harald Freudenberger
2026-08-21  8:46 ` [PATCH v6 1/9] s390/crypto: Fix return code handling at skcipher_walk_done in PAES algorithms Harald Freudenberger
2026-08-21  8:57   ` sashiko-bot
2026-08-21  8:46 ` [PATCH v6 2/9] s390/crypto: Fix missing scrub of temp buffers with PAES algorithm Harald Freudenberger
2026-08-21  8:58   ` sashiko-bot
2026-08-21  9:04     ` Harald Freudenberger
2026-08-21  8:46 ` [PATCH v6 3/9] s390/crypto: Fix use of mutex in atomic context in PAES Harald Freudenberger
2026-08-21  8:56   ` sashiko-bot
2026-08-21  9:01     ` Harald Freudenberger [this message]
2026-08-21  8:46 ` [PATCH v6 4/9] s390/crypto: Fix missing cra_flags in paes_s390 Harald Freudenberger
2026-08-21  8:52   ` sashiko-bot
2026-08-21  8:46 ` [PATCH v6 5/9] s390/crypto: Fix handling of EBUSY in PAES when req is pushed to crypto engine Harald Freudenberger
2026-08-21 10:08   ` sashiko-bot
2026-08-21  8:46 ` [PATCH v6 6/9] s390/crypto: Fix handling of EBUSY in PHMAC " Harald Freudenberger
2026-08-21  9:00   ` sashiko-bot
2026-08-21  8:46 ` [PATCH v6 7/9] s390/crypto: Fix wrong return code to engine in asynch callbacks Harald Freudenberger
2026-08-21  8:54   ` sashiko-bot
2026-08-21  8:46 ` [PATCH v6 8/9] s390/crypto: Map EBUSY to EIO when key conversion fails repeatedly Harald Freudenberger
2026-08-21  8:59   ` sashiko-bot
2026-08-21  8:46 ` [PATCH v6 9/9] s390/crypto: Enable CONTEXT_ANALYSIS Harald Freudenberger
2026-08-21  8:55   ` sashiko-bot

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=5f077680b9797530ea64aef75ff56f8f@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