* [PATCH] padata: Always leave BHs disabled when running ->parallel()
@ 2022-11-17 1:28 Daniel Jordan
2022-11-25 9:45 ` Herbert Xu
0 siblings, 1 reply; 2+ messages in thread
From: Daniel Jordan @ 2022-11-17 1:28 UTC (permalink / raw)
To: Herbert Xu, Steffen Klassert
Cc: Nicolai Stange, Martin Doucha, linux-crypto, linux-kernel, Daniel Jordan
A deadlock can happen when an overloaded system runs ->parallel() in the
context of the current task:
padata_do_parallel
->parallel()
pcrypt_aead_enc/dec
padata_do_serial
spin_lock(&reorder->lock) // BHs still enabled
<interrupt>
...
__do_softirq
...
padata_do_serial
spin_lock(&reorder->lock)
It's a bug for BHs to be on in _do_serial as Steffen points out, so
ensure they're off in the "current task" case like they are in
padata_parallel_worker to avoid this situation.
Reported-by: syzbot+bc05445bc14148d51915@syzkaller.appspotmail.com
Fixes: 4611ce224688 ("padata: allocate work structures for parallel jobs from a pool")
Signed-off-by: Daniel Jordan <daniel.m.jordan@oracle.com>
Acked-by: Steffen Klassert <steffen.klassert@secunet.com>
---
About the potential deadlock in padata_find_next(), I think this fix
covers us there since that function is only called from
padata_do_serial(), where BHs should now always be off, or
invoke_padata_reorder(), where BHs are off as well. The _bh spinlock
variants in padata_reorder() seem redundant.
kernel/padata.c | 8 +++++---
1 file changed, 5 insertions(+), 3 deletions(-)
diff --git a/kernel/padata.c b/kernel/padata.c
index e5819bb8bd1d..97f51e0c1776 100644
--- a/kernel/padata.c
+++ b/kernel/padata.c
@@ -207,14 +207,16 @@ int padata_do_parallel(struct padata_shell *ps,
pw = padata_work_alloc();
spin_unlock(&padata_works_lock);
+ if (!pw) {
+ /* Maximum works limit exceeded, run in the current task. */
+ padata->parallel(padata);
+ }
+
rcu_read_unlock_bh();
if (pw) {
padata_work_init(pw, padata_parallel_worker, padata, 0);
queue_work(pinst->parallel_wq, &pw->pw_work);
- } else {
- /* Maximum works limit exceeded, run in the current task. */
- padata->parallel(padata);
}
return 0;
--
2.38.1
^ permalink raw reply related [flat|nested] 2+ messages in thread
* Re: [PATCH] padata: Always leave BHs disabled when running ->parallel()
2022-11-17 1:28 [PATCH] padata: Always leave BHs disabled when running ->parallel() Daniel Jordan
@ 2022-11-25 9:45 ` Herbert Xu
0 siblings, 0 replies; 2+ messages in thread
From: Herbert Xu @ 2022-11-25 9:45 UTC (permalink / raw)
To: Daniel Jordan
Cc: Steffen Klassert, Nicolai Stange, Martin Doucha, linux-crypto,
linux-kernel
On Wed, Nov 16, 2022 at 08:28:02PM -0500, Daniel Jordan wrote:
> A deadlock can happen when an overloaded system runs ->parallel() in the
> context of the current task:
>
> padata_do_parallel
> ->parallel()
> pcrypt_aead_enc/dec
> padata_do_serial
> spin_lock(&reorder->lock) // BHs still enabled
> <interrupt>
> ...
> __do_softirq
> ...
> padata_do_serial
> spin_lock(&reorder->lock)
>
> It's a bug for BHs to be on in _do_serial as Steffen points out, so
> ensure they're off in the "current task" case like they are in
> padata_parallel_worker to avoid this situation.
>
> Reported-by: syzbot+bc05445bc14148d51915@syzkaller.appspotmail.com
> Fixes: 4611ce224688 ("padata: allocate work structures for parallel jobs from a pool")
> Signed-off-by: Daniel Jordan <daniel.m.jordan@oracle.com>
> Acked-by: Steffen Klassert <steffen.klassert@secunet.com>
> ---
>
> About the potential deadlock in padata_find_next(), I think this fix
> covers us there since that function is only called from
> padata_do_serial(), where BHs should now always be off, or
> invoke_padata_reorder(), where BHs are off as well. The _bh spinlock
> variants in padata_reorder() seem redundant.
>
> kernel/padata.c | 8 +++++---
> 1 file changed, 5 insertions(+), 3 deletions(-)
Patch applied. 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
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2022-11-25 9:47 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-11-17 1:28 [PATCH] padata: Always leave BHs disabled when running ->parallel() Daniel Jordan
2022-11-25 9:45 ` Herbert Xu
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.