From: Eric Biggers <ebiggers@kernel.org>
To: Herbert Xu <herbert@gondor.apana.org.au>
Cc: Daniel Jordan <daniel.m.jordan@oracle.com>,
Linux Crypto Mailing List <linux-crypto@vger.kernel.org>,
Steffen Klassert <steffen.klassert@secunet.com>
Subject: Re: [v3 PATCH] crypto: pcrypt - Avoid deadlock by using per-instance padata queues
Date: Fri, 29 Nov 2019 11:25:56 -0800 [thread overview]
Message-ID: <20191129192556.GB706@sol.localdomain> (raw)
In-Reply-To: <20191126075845.2v3woc3xqx2fxzqh@gondor.apana.org.au>
On Tue, Nov 26, 2019 at 03:58:45PM +0800, Herbert Xu wrote:
> On Tue, Nov 26, 2019 at 12:32:38AM -0500, Daniel Jordan wrote:
> >
> > I think it's possible for a task in padata_do_parallel() racing with another in
> > padata_replace() to use a pd after free. The synchronize_rcu() comes after the
> > pd_old->refcnt's are dec'd.
>
> Thanks. I've fixed this as well as the CPU mask issue you identified
> earlier.
>
> ---8<---
> If the pcrypt template is used multiple times in an algorithm, then a
> deadlock occurs because all pcrypt instances share the same
> padata_instance, which completes requests in the order submitted. That
> is, the inner pcrypt request waits for the outer pcrypt request while
> the outer request is already waiting for the inner.
>
> This patch fixes this by allocating a set of queues for each pcrypt
> instance instead of using two global queues. In order to maintain
> the existing user-space interface, the pinst structure remains global
> so any sysfs modifications will apply to every pcrypt instance.
>
> Note that when an update occurs we have to allocate memory for
> every pcrypt instance. Should one of the allocations fail we
> will abort the update without rolling back changes already made.
>
> The new per-instance data structure is called padata_shell and is
> essentially a wrapper around parallel_data.
>
> Reproducer:
>
> #include <linux/if_alg.h>
> #include <sys/socket.h>
> #include <unistd.h>
>
> int main()
> {
> struct sockaddr_alg addr = {
> .salg_type = "aead",
> .salg_name = "pcrypt(pcrypt(rfc4106-gcm-aesni))"
> };
> int algfd, reqfd;
> char buf[32] = { 0 };
>
> algfd = socket(AF_ALG, SOCK_SEQPACKET, 0);
> bind(algfd, (void *)&addr, sizeof(addr));
> setsockopt(algfd, SOL_ALG, ALG_SET_KEY, buf, 20);
> reqfd = accept(algfd, 0, 0);
> write(reqfd, buf, 32);
> read(reqfd, buf, 16);
> }
>
> Reported-by: syzbot+56c7151cad94eec37c521f0e47d2eee53f9361c4@syzkaller.appspotmail.com
> Fixes: 5068c7a883d1 ("crypto: pcrypt - Add pcrypt crypto parallelization wrapper")
> Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
>
Tested-by: Eric Biggers <ebiggers@kernel.org>
prev parent reply other threads:[~2019-11-29 19:25 UTC|newest]
Thread overview: 11+ messages / expand[flat|nested] mbox.gz Atom feed top
2019-11-19 13:05 [PATCH] crypto: pcrypt - Avoid deadlock by using per-instance padata queues Herbert Xu
2019-11-19 17:37 ` Eric Biggers
2019-11-19 18:58 ` [v2 PATCH] " Herbert Xu
2019-11-22 16:28 ` Daniel Jordan
2019-11-26 5:32 ` Daniel Jordan
2019-11-26 7:58 ` [v3 " Herbert Xu
2019-11-27 19:14 ` Eric Biggers
2019-11-29 8:40 ` [PATCH] crypto: pcrypt - Do not clear MAY_SLEEP flag in original request Herbert Xu
2019-11-29 19:24 ` Eric Biggers
2019-11-27 23:38 ` [v3 PATCH] crypto: pcrypt - Avoid deadlock by using per-instance padata queues Daniel Jordan
2019-11-29 19:25 ` Eric Biggers [this message]
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=20191129192556.GB706@sol.localdomain \
--to=ebiggers@kernel.org \
--cc=daniel.m.jordan@oracle.com \
--cc=herbert@gondor.apana.org.au \
--cc=linux-crypto@vger.kernel.org \
--cc=steffen.klassert@secunet.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;
as well as URLs for NNTP newsgroup(s).