From: Vinay Kumar Yadav <vinay.yadav@chelsio.com>
To: David Miller <davem@davemloft.net>
Cc: netdev@vger.kernel.org, kuba@kernel.org, secdev@chelsio.com
Subject: Re: [PATCH net-next] net/tls: fix race condition causing kernel panic
Date: Wed, 20 May 2020 22:39:11 +0530 [thread overview]
Message-ID: <99faf485-2f28-0a45-7442-abaaee8744aa@chelsio.com> (raw)
In-Reply-To: <20200519.121641.1552016505379076766.davem@davemloft.net>
David
On 5/20/2020 12:46 AM, David Miller wrote:
> From: Vinay Kumar Yadav <vinay.yadav@chelsio.com>
> Date: Tue, 19 May 2020 13:13:27 +0530
>
>> + spin_lock_bh(&ctx->encrypt_compl_lock);
>> + pending = atomic_read(&ctx->encrypt_pending);
>> + spin_unlock_bh(&ctx->encrypt_compl_lock);
> The sequence:
>
> lock();
> x = p->y;
> unlock();
>
> Does not fix anything, and is superfluous locking.
>
> The value of p->y can change right after the unlock() call, so you
> aren't protecting the atomic'ness of the read and test sequence
> because the test is outside of the lock.
Here, by using lock I want to achieve atomicity of following statements.
pending = atomic_dec_return(&ctx->decrypt_pending);
if (!pending && READ_ONCE(ctx->async_notify))
complete(&ctx->async_wait.completion);
means, don't want to read (atomic_read(&ctx->decrypt_pending))
in middle of two statements
atomic_dec_return(&ctx->decrypt_pending);
and
complete(&ctx->async_wait.completion);
Why am I protecting only read, not test ?
complete() is called only if pending == 0
if we read atomic_read(&ctx->decrypt_pending) = 0
that means complete() is already called and its okay to
initialize completion (reinit_completion(&ctx->async_wait.completion))
if we read atomic_read(&ctx->decrypt_pending) as non zero that means:
1- complete() is going to be called or
2- complete() already called (if we read atomic_read(&ctx->decrypt_pending) == 1, then complete() is called just after unlock())
for both scenario its okay to go into wait (crypto_wait_req(-EINPROGRESS, &ctx->async_wait))
Thanks,
Vinay
next prev parent reply other threads:[~2020-05-20 17:07 UTC|newest]
Thread overview: 9+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-05-19 7:43 [PATCH net-next] net/tls: fix race condition causing kernel panic Vinay Kumar Yadav
2020-05-19 19:16 ` David Miller
2020-05-20 17:09 ` Vinay Kumar Yadav [this message]
2020-05-20 19:58 ` Jakub Kicinski
2020-05-21 8:58 ` Vinay Kumar Yadav
2020-05-21 18:56 ` Jakub Kicinski
2020-05-21 20:32 ` Vinay Kumar Yadav
2020-05-21 21:40 ` Jakub Kicinski
[not found] ` <bbcfb6c7-8e98-63a1-4ff6-d185bdcf4708@chelsio.com>
2020-05-21 21:38 ` David Miller
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=99faf485-2f28-0a45-7442-abaaee8744aa@chelsio.com \
--to=vinay.yadav@chelsio.com \
--cc=davem@davemloft.net \
--cc=kuba@kernel.org \
--cc=netdev@vger.kernel.org \
--cc=secdev@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).