Skip to content

Commit

Permalink
tcp, ulp: enforce sock_owned_by_me upon ulp init and cleanup
Browse files Browse the repository at this point in the history
Whenever the ULP data on the socket is mangled, enforce that the
caller has the socket lock held as otherwise things may race with
initialization and cleanup callbacks from ulp ops as both would
mangle internal socket state.

Joint work with John.

Signed-off-by: Daniel Borkmann <daniel@iogearbox.net>
Signed-off-by: John Fastabend <john.fastabend@gmail.com>
Signed-off-by: Alexei Starovoitov <ast@kernel.org>
  • Loading branch information
Daniel Borkmann authored and Alexei Starovoitov committed Oct 15, 2018
1 parent 67e89ac commit 8b9088f
Showing 1 changed file with 4 additions and 0 deletions.
4 changes: 4 additions & 0 deletions net/ipv4/tcp_ulp.c
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,8 @@ void tcp_cleanup_ulp(struct sock *sk)
{
struct inet_connection_sock *icsk = inet_csk(sk);

sock_owned_by_me(sk);

if (!icsk->icsk_ulp_ops)
return;

Expand All @@ -140,6 +142,7 @@ int tcp_set_ulp(struct sock *sk, const char *name)
const struct tcp_ulp_ops *ulp_ops;
int err = 0;

sock_owned_by_me(sk);
if (icsk->icsk_ulp_ops)
return -EEXIST;

Expand Down Expand Up @@ -168,6 +171,7 @@ int tcp_set_ulp_id(struct sock *sk, int ulp)
const struct tcp_ulp_ops *ulp_ops;
int err;

sock_owned_by_me(sk);
if (icsk->icsk_ulp_ops)
return -EEXIST;

Expand Down

0 comments on commit 8b9088f

Please sign in to comment.