Skip to content

Commit 69135c5

Browse files
Ziyang Xuandavem330
authored andcommitted
net/tls: fix tls_sk_proto_close executed repeatedly
After setting the sock ktls, update ctx->sk_proto to sock->sk_prot by tls_update(), so now ctx->sk_proto->close is tls_sk_proto_close(). When close the sock, tls_sk_proto_close() is called for sock->sk_prot->close is tls_sk_proto_close(). But ctx->sk_proto->close() will be executed later in tls_sk_proto_close(). Thus tls_sk_proto_close() executed repeatedly occurred. That will trigger the following bug. ================================================================= KASAN: null-ptr-deref in range [0x0000000000000010-0x0000000000000017] RIP: 0010:tls_sk_proto_close+0xd8/0xaf0 net/tls/tls_main.c:306 Call Trace: <TASK> tls_sk_proto_close+0x356/0xaf0 net/tls/tls_main.c:329 inet_release+0x12e/0x280 net/ipv4/af_inet.c:428 __sock_release+0xcd/0x280 net/socket.c:650 sock_close+0x18/0x20 net/socket.c:1365 Updating a proto which is same with sock->sk_prot is incorrect. Add proto and sock->sk_prot equality check at the head of tls_update() to fix it. Fixes: 95fa145 ("bpf: sockmap/tls, close can race with map free") Reported-by: [email protected] Signed-off-by: Ziyang Xuan <[email protected]> Signed-off-by: David S. Miller <[email protected]>
1 parent 301bd14 commit 69135c5

File tree

1 file changed

+3
-0
lines changed

1 file changed

+3
-0
lines changed

net/tls/tls_main.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -921,6 +921,9 @@ static void tls_update(struct sock *sk, struct proto *p,
921921
{
922922
struct tls_context *ctx;
923923

924+
if (sk->sk_prot == p)
925+
return;
926+
924927
ctx = tls_get_ctx(sk);
925928
if (likely(ctx)) {
926929
ctx->sk_write_space = write_space;

0 commit comments

Comments
 (0)