Skip to content

Commit

Permalink
net/tls: Only attach to sockets in ESTABLISHED state
Browse files Browse the repository at this point in the history
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: [email protected]
Signed-off-by: Ilya Lesokhin <[email protected]>
Signed-off-by: David S. Miller <[email protected]>
  • Loading branch information
Ilya Lesokhin authored and davem330 committed Jan 17, 2018
1 parent f8b3903 commit d91c3e1
Showing 1 changed file with 9 additions and 0 deletions.
9 changes: 9 additions & 0 deletions net/tls/tls_main.c
Original file line number Diff line number Diff line change
Expand Up @@ -454,6 +454,15 @@ static int tls_init(struct sock *sk)
struct tls_context *ctx;
int rc = 0;

/* The TLS ulp is currently supported only for TCP sockets
* in ESTABLISHED state.
* Supporting sockets in LISTEN state will require us
* to modify the accept implementation to clone rather then
* share the ulp context.
*/
if (sk->sk_state != TCP_ESTABLISHED)
return -ENOTSUPP;

/* allocate tls context */
ctx = kzalloc(sizeof(*ctx), GFP_KERNEL);
if (!ctx) {
Expand Down

0 comments on commit d91c3e1

Please sign in to comment.