Skip to content

Commit d91c3e1

Browse files
Ilya Lesokhindavem330
Ilya Lesokhin
authored andcommitted
net/tls: Only attach to sockets in ESTABLISHED state
Calling accept on a TCP socket with a TLS ulp attached results in two sockets that share the same ulp context. The ulp context is freed while a socket is destroyed, so after one of the sockets is released, the second second will trigger a use after free when it tries to access the ulp context attached to it. We restrict the TLS ulp to sockets in ESTABLISHED state to prevent the scenario above. Fixes: 3c4d755 ("tls: kernel TLS support") Reported-by: syzbot+904e7cd6c5c741609228@syzkaller.appspotmail.com Signed-off-by: Ilya Lesokhin <ilyal@mellanox.com> Signed-off-by: David S. Miller <davem@davemloft.net>
1 parent f8b3903 commit d91c3e1

File tree

1 file changed

+9
-0
lines changed

1 file changed

+9
-0
lines changed

net/tls/tls_main.c

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -454,6 +454,15 @@ static int tls_init(struct sock *sk)
454454
struct tls_context *ctx;
455455
int rc = 0;
456456

457+
/* The TLS ulp is currently supported only for TCP sockets
458+
* in ESTABLISHED state.
459+
* Supporting sockets in LISTEN state will require us
460+
* to modify the accept implementation to clone rather then
461+
* share the ulp context.
462+
*/
463+
if (sk->sk_state != TCP_ESTABLISHED)
464+
return -ENOTSUPP;
465+
457466
/* allocate tls context */
458467
ctx = kzalloc(sizeof(*ctx), GFP_KERNEL);
459468
if (!ctx) {

0 commit comments

Comments
 (0)