Skip to content

Commit

Permalink
bpf: sockmap, duplicates release calls may NULL sk_prot
Browse files Browse the repository at this point in the history
It is possible to have multiple ULP tcp_release call paths in flight
if a sock is closed and simultaneously being removed from the sockmap
control path. The result would be setting the sk_prot to the saved
values on the first iteration and then on the second iteration setting
the value to NULL.

This patch resolves this by ensuring we only reset the sk_prot pointer
if we have a valid saved state to set.

Fixes: 4f738ad ("bpf: create tcp_bpf_ulp allowing BPF to monitor socket TX/RX data")
Signed-off-by: John Fastabend <[email protected]>
Signed-off-by: Daniel Borkmann <[email protected]>
  • Loading branch information
jrfastab authored and borkmann committed Apr 4, 2018
1 parent 820ed3f commit 0e94d87
Showing 1 changed file with 4 additions and 2 deletions.
6 changes: 4 additions & 2 deletions kernel/bpf/sockmap.c
Original file line number Diff line number Diff line change
Expand Up @@ -182,8 +182,10 @@ static void bpf_tcp_release(struct sock *sk)
psock->cork = NULL;
}

sk->sk_prot = psock->sk_proto;
psock->sk_proto = NULL;
if (psock->sk_proto) {
sk->sk_prot = psock->sk_proto;
psock->sk_proto = NULL;
}
out:
rcu_read_unlock();
}
Expand Down

0 comments on commit 0e94d87

Please sign in to comment.