From: Sabrina Dubroca <sd@queasysnail.net>
To: Herbert Xu <herbert@gondor.apana.org.au>
Cc: Jakub Kicinski <kuba@kernel.org>,
netdev@vger.kernel.org, Dave Watson <davejwatson@fb.com>,
Vakul Garg <vakul.garg@nxp.com>,
Boris Pismenny <borisp@nvidia.com>,
John Fastabend <john.fastabend@gmail.com>
Subject: Re: [PATCH net 5/5] tls: don't decrypt the next record if it's of a different type
Date: Wed, 13 Sep 2023 15:25:29 +0200 [thread overview]
Message-ID: <ZQG4SXGaJpCtWX_k@hog> (raw)
In-Reply-To: <ZP/rS+NtSbJ3EuWc@gondor.apana.org.au>
2023-09-12, 12:38:35 +0800, Herbert Xu wrote:
> On Fri, Sep 08, 2023 at 05:38:49PM +0200, Sabrina Dubroca wrote:
> >
> > tls_decrypt_done only runs the completion when decrypt_pending drops
> > to 0, so this should be covered.
>
> That doesn't look very safe. What if the first decrypt completes
> before the second decrypt even starts? Wouldn't that cause two
> complete calls on ctx->async_wait?
>
> > I wonder if this situation could happen:
> >
> > tls_sw_recvmsg
> > process first record
> > decrypt_pending = 1
> > CB runs
> > decrypt_pending = 0
> > complete(&ctx->async_wait.completion);
> >
> > process second record
> > decrypt_pending = 1
> > tls_sw_recvmsg reaches "recv_end"
> > decrypt_pending != 0
> > crypto_wait_req sees the first completion of ctx->async_wait and proceeds
> >
> > CB runs
> > decrypt_pending = 0
> > complete(&ctx->async_wait.completion);
>
> Yes that's exactly what I was thinking of.
>
> I think this whole thing needs some rethinking and rewriting.
I'm not sure there's a problem.
In tls_sw_recvmsg, the code waiting for async decrypts does:
/* Wait for all previously submitted records to be decrypted */
spin_lock_bh(&ctx->decrypt_compl_lock);
reinit_completion(&ctx->async_wait.completion);
pending = atomic_read(&ctx->decrypt_pending);
spin_unlock_bh(&ctx->decrypt_compl_lock);
ret = 0;
if (pending)
ret = crypto_wait_req(-EINPROGRESS, &ctx->async_wait);
And the async callback finishes with:
spin_lock_bh(&ctx->decrypt_compl_lock);
if (!atomic_dec_return(&ctx->decrypt_pending))
complete(&ctx->async_wait.completion);
spin_unlock_bh(&ctx->decrypt_compl_lock);
Since we have the reinit_completion call, we'll ignore the previous
complete() (for the first record), and still wait for the 2nd record's
completion.
Does that still look unsafe to you?
--
Sabrina
next prev parent reply other threads:[~2023-09-13 13:25 UTC|newest]
Thread overview: 25+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-09-06 17:08 [PATCH net 0/5] tls: fix some issues with async encryption Sabrina Dubroca
2023-09-06 17:08 ` [PATCH net 1/5] net: tls: handle -EBUSY on async encrypt/decrypt requests Sabrina Dubroca
2023-09-07 1:50 ` Jakub Kicinski
2023-09-07 15:11 ` Simon Horman
2023-09-08 6:10 ` Herbert Xu
2023-09-08 15:55 ` Sabrina Dubroca
2023-09-08 21:26 ` Jakub Kicinski
2023-09-09 0:53 ` Herbert Xu
2023-09-12 4:43 ` Herbert Xu
2023-09-12 15:37 ` Sabrina Dubroca
2023-09-14 9:00 ` Herbert Xu
2023-09-06 17:08 ` [PATCH net 2/5] tls: fix use-after-free with partial reads and async decrypt Sabrina Dubroca
2023-09-07 2:05 ` Jakub Kicinski
2023-09-07 13:56 ` Sabrina Dubroca
2023-09-06 17:08 ` [PATCH net 3/5] tls: fix returned read length with async !zc decrypt Sabrina Dubroca
2023-09-06 17:08 ` [PATCH net 4/5] tls: fix race condition in async decryption of corrupted records Sabrina Dubroca
2023-09-06 17:08 ` [PATCH net 5/5] tls: don't decrypt the next record if it's of a different type Sabrina Dubroca
2023-09-07 3:47 ` Jakub Kicinski
2023-09-07 12:21 ` Sabrina Dubroca
2023-09-07 17:08 ` Jakub Kicinski
2023-09-08 6:06 ` Herbert Xu
2023-09-08 15:38 ` Sabrina Dubroca
2023-09-12 4:38 ` Herbert Xu
2023-09-13 13:25 ` Sabrina Dubroca [this message]
2023-09-14 9:45 ` Herbert Xu
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=ZQG4SXGaJpCtWX_k@hog \
--to=sd@queasysnail.net \
--cc=borisp@nvidia.com \
--cc=davejwatson@fb.com \
--cc=herbert@gondor.apana.org.au \
--cc=john.fastabend@gmail.com \
--cc=kuba@kernel.org \
--cc=netdev@vger.kernel.org \
--cc=vakul.garg@nxp.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).