tls: improve lockless access safety of tls_err_abort()
Subsystems (3)
Jakub Kicinski
maintainerPATCH 1/1 tls: improve lockless access safety of tls_err_abort()
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.
--- net/tls/tls_strp.c | 4 +++- net/tls/tls_sw.c | 4 +++- 2 files changed, 6 insertions(+), 2 deletions(-)
net/tls/tls_strp.c +3 -1
@@ -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); }
net/tls/tls_sw.c +3 -1
@@ -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); }
Signature · 1 line
2.40.1
Quoted 9 lines · Jakub Kicinski
Most protos'
poll()methods insert a memory barrier between writes tosk_errandsk_error_report(). This dates back to commita4d258036ed9("tcp: Fix race intcp_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 <[email protected]>
This patch was applied to netdev/net.git (main) by David S. Miller <[email protected]>:
Hello:
This patch was applied to netdev/net.git (main)
by David S. Miller <[email protected]>:
Quoted 8 lines · On Wed, 24 May 2023 22:17:41 -0700 you wrote:
Most protos'
poll()methods insert a memory barrier between writes tosk_errandsk_error_report(). This dates back to commita4d258036ed9("tcp: Fix race intcp_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!
Signature · 2 lines
Deet-doot-dot, I am a bot. https://korg.docs.kernel.org/patchwork/pwbot.html