* [PATCH net] tls: improve lockless access safety of tls_err_abort()
@ 2023-05-25 5:17 Jakub Kicinski
2023-05-26 9:03 ` Simon Horman
2023-05-26 9:40 ` patchwork-bot+netdevbpf
0 siblings, 2 replies; 3+ messages in thread
From: Jakub Kicinski @ 2023-05-25 5:17 UTC (permalink / raw)
To: davem; +Cc: netdev, edumazet, pabeni, borisp, john.fastabend, Jakub Kicinski
Most protos' poll() methods insert a memory barrier between
writes to sk_err and sk_error_report(). This dates back to
commit a4d258036ed9 ("tcp: Fix race in tcp_poll").
I guess we should do the same thing in TLS, tcp_poll() does
not hold the socket lock.
Fixes: 3c4d7559159b ("tls: kernel TLS support")
Signed-off-by: Jakub Kicinski <kuba@kernel.org>
---
net/tls/tls_strp.c | 4 +++-
net/tls/tls_sw.c | 4 +++-
2 files changed, 6 insertions(+), 2 deletions(-)
diff --git a/net/tls/tls_strp.c b/net/tls/tls_strp.c
index 955ac3e0bf4d..1f7696b060d5 100644
--- a/net/tls/tls_strp.c
+++ b/net/tls/tls_strp.c
@@ -20,7 +20,9 @@ static void tls_strp_abort_strp(struct tls_strparser *strp, int err)
strp->stopped = 1;
/* Report an error on the lower socket */
- strp->sk->sk_err = -err;
+ WRITE_ONCE(strp->sk->sk_err, -err);
+ /* Paired with smp_rmb() in tcp_poll() */
+ smp_wmb();
sk_error_report(strp->sk);
}
diff --git a/net/tls/tls_sw.c b/net/tls/tls_sw.c
index 635b8bf6b937..eaf08777abdc 100644
--- a/net/tls/tls_sw.c
+++ b/net/tls/tls_sw.c
@@ -70,7 +70,9 @@ noinline void tls_err_abort(struct sock *sk, int err)
{
WARN_ON_ONCE(err >= 0);
/* sk->sk_err should contain a positive error code. */
- sk->sk_err = -err;
+ WRITE_ONCE(sk->sk_err, -err);
+ /* Paired with smp_rmb() in tcp_poll() */
+ smp_wmb();
sk_error_report(sk);
}
--
2.40.1
^ permalink raw reply related [flat|nested] 3+ messages in thread
* Re: [PATCH net] tls: improve lockless access safety of tls_err_abort()
2023-05-25 5:17 [PATCH net] tls: improve lockless access safety of tls_err_abort() Jakub Kicinski
@ 2023-05-26 9:03 ` Simon Horman
2023-05-26 9:40 ` patchwork-bot+netdevbpf
1 sibling, 0 replies; 3+ messages in thread
From: Simon Horman @ 2023-05-26 9:03 UTC (permalink / raw)
To: Jakub Kicinski; +Cc: davem, netdev, edumazet, pabeni, borisp, john.fastabend
On Wed, May 24, 2023 at 10:17:41PM -0700, Jakub Kicinski wrote:
> Most protos' poll() methods insert a memory barrier between
> writes to sk_err and sk_error_report(). This dates back to
> commit a4d258036ed9 ("tcp: Fix race in tcp_poll").
>
> I guess we should do the same thing in TLS, tcp_poll() does
> not hold the socket lock.
>
> Fixes: 3c4d7559159b ("tls: kernel TLS support")
> Signed-off-by: Jakub Kicinski <kuba@kernel.org>
Reviewed-by: Simon Horman <simon.horman@corigine.com>
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [PATCH net] tls: improve lockless access safety of tls_err_abort()
2023-05-25 5:17 [PATCH net] tls: improve lockless access safety of tls_err_abort() Jakub Kicinski
2023-05-26 9:03 ` Simon Horman
@ 2023-05-26 9:40 ` patchwork-bot+netdevbpf
1 sibling, 0 replies; 3+ messages in thread
From: patchwork-bot+netdevbpf @ 2023-05-26 9:40 UTC (permalink / raw)
To: Jakub Kicinski; +Cc: davem, netdev, edumazet, pabeni, borisp, john.fastabend
Hello:
This patch was applied to netdev/net.git (main)
by David S. Miller <davem@davemloft.net>:
On Wed, 24 May 2023 22:17:41 -0700 you wrote:
> Most protos' poll() methods insert a memory barrier between
> writes to sk_err and sk_error_report(). This dates back to
> commit a4d258036ed9 ("tcp: Fix race in tcp_poll").
>
> I guess we should do the same thing in TLS, tcp_poll() does
> not hold the socket lock.
>
> [...]
Here is the summary with links:
- [net] tls: improve lockless access safety of tls_err_abort()
https://git.kernel.org/netdev/net/c/8a0d57df8938
You are awesome, thank you!
--
Deet-doot-dot, I am a bot.
https://korg.docs.kernel.org/patchwork/pwbot.html
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2023-05-26 9:40 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2023-05-25 5:17 [PATCH net] tls: improve lockless access safety of tls_err_abort() Jakub Kicinski
2023-05-26 9:03 ` Simon Horman
2023-05-26 9:40 ` patchwork-bot+netdevbpf
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).