netdev.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: David Miller <davem@davemloft.net>
To: vinay.yadav@chelsio.com
Cc: netdev@vger.kernel.org, kuba@kernel.org, secdev@chelsio.com
Subject: Re: [PATCH net-next,v2] net/tls: fix race condition causing kernel panic
Date: Mon, 25 May 2020 17:42:41 -0700 (PDT)	[thread overview]
Message-ID: <20200525.174241.85970384865891191.davem@davemloft.net> (raw)
In-Reply-To: <20200522201031.32516-1-vinay.yadav@chelsio.com>

From: Vinay Kumar Yadav <vinay.yadav@chelsio.com>
Date: Sat, 23 May 2020 01:40:31 +0530

> tls_sw_recvmsg() and tls_decrypt_done() can be run concurrently.
> // tls_sw_recvmsg()
> 	if (atomic_read(&ctx->decrypt_pending))
> 		crypto_wait_req(-EINPROGRESS, &ctx->async_wait);
> 	else
> 		reinit_completion(&ctx->async_wait.completion);
> 
> //tls_decrypt_done()
>   	pending = atomic_dec_return(&ctx->decrypt_pending);
> 
>   	if (!pending && READ_ONCE(ctx->async_notify))
>   		complete(&ctx->async_wait.completion);
> 
> Consider the scenario tls_decrypt_done() is about to run complete()
> 
> 	if (!pending && READ_ONCE(ctx->async_notify))
> 
> and tls_sw_recvmsg() reads decrypt_pending == 0, does reinit_completion(),
> then tls_decrypt_done() runs complete(). This sequence of execution
> results in wrong completion. Consequently, for next decrypt request,
> it will not wait for completion, eventually on connection close, crypto
> resources freed, there is no way to handle pending decrypt response.
> 
> This race condition can be avoided by having atomic_read() mutually
> exclusive with atomic_dec_return(),complete().Intoduced spin lock to
> ensure the mutual exclution.
> 
> Addressed similar problem in tx direction.
> 
> v1->v2:
> - More readable commit message.
> - Corrected the lock to fix new race scenario.
> - Removed barrier which is not needed now.
> 
> Signed-off-by: Vinay Kumar Yadav <vinay.yadav@chelsio.com>

Applied to 'net' as this is a bug fix, with Fixes tag from Jakub added,
and queued up for -stable.

Thanks.

      parent reply	other threads:[~2020-05-26  0:42 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-05-22 20:10 [PATCH net-next,v2] net/tls: fix race condition causing kernel panic Vinay Kumar Yadav
2020-05-25 20:25 ` Jakub Kicinski
2020-05-26  0:42 ` David Miller [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=20200525.174241.85970384865891191.davem@davemloft.net \
    --to=davem@davemloft.net \
    --cc=kuba@kernel.org \
    --cc=netdev@vger.kernel.org \
    --cc=secdev@chelsio.com \
    --cc=vinay.yadav@chelsio.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).