Skip to content

Commit 8a0d57d

Browse files
kuba-moodavem330
authored andcommitted
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 a4d2580 ("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: 3c4d755 ("tls: kernel TLS support") Signed-off-by: Jakub Kicinski <[email protected]> Reviewed-by: Simon Horman <[email protected]> Signed-off-by: David S. Miller <[email protected]>
1 parent aa866ee commit 8a0d57d

File tree

2 files changed

+6
-2
lines changed

2 files changed

+6
-2
lines changed

net/tls/tls_strp.c

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,9 @@ static void tls_strp_abort_strp(struct tls_strparser *strp, int err)
2020
strp->stopped = 1;
2121

2222
/* Report an error on the lower socket */
23-
strp->sk->sk_err = -err;
23+
WRITE_ONCE(strp->sk->sk_err, -err);
24+
/* Paired with smp_rmb() in tcp_poll() */
25+
smp_wmb();
2426
sk_error_report(strp->sk);
2527
}
2628

net/tls/tls_sw.c

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,9 @@ noinline void tls_err_abort(struct sock *sk, int err)
7070
{
7171
WARN_ON_ONCE(err >= 0);
7272
/* sk->sk_err should contain a positive error code. */
73-
sk->sk_err = -err;
73+
WRITE_ONCE(sk->sk_err, -err);
74+
/* Paired with smp_rmb() in tcp_poll() */
75+
smp_wmb();
7476
sk_error_report(sk);
7577
}
7678

0 commit comments

Comments
 (0)