Skip to content

Commit 8b9088f

Browse files
borkmannAlexei Starovoitov
authored andcommitted
tcp, ulp: enforce sock_owned_by_me upon ulp init and cleanup
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 <[email protected]> Signed-off-by: John Fastabend <[email protected]> Signed-off-by: Alexei Starovoitov <[email protected]>
1 parent 67e89ac commit 8b9088f

File tree

1 file changed

+4
-0
lines changed

1 file changed

+4
-0
lines changed

net/ipv4/tcp_ulp.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -123,6 +123,8 @@ void tcp_cleanup_ulp(struct sock *sk)
123123
{
124124
struct inet_connection_sock *icsk = inet_csk(sk);
125125

126+
sock_owned_by_me(sk);
127+
126128
if (!icsk->icsk_ulp_ops)
127129
return;
128130

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

145+
sock_owned_by_me(sk);
143146
if (icsk->icsk_ulp_ops)
144147
return -EEXIST;
145148

@@ -168,6 +171,7 @@ int tcp_set_ulp_id(struct sock *sk, int ulp)
168171
const struct tcp_ulp_ops *ulp_ops;
169172
int err;
170173

174+
sock_owned_by_me(sk);
171175
if (icsk->icsk_ulp_ops)
172176
return -EEXIST;
173177

0 commit comments

Comments
 (0)