Skip to content

Commit 68b54ae

Browse files
Paolo Abenikuba-moo
authored andcommitted
tcp_bpf: properly release resources on error paths
In the blamed commit below, I completely forgot to release the acquired resources before erroring out in the TCP BPF code, as reported by Dan. Address the issues by replacing the bogus return with a jump to the relevant cleanup code. Fixes: 419ce13 ("tcp: allow again tcp_disconnect() when threads are waiting") Reported-by: Dan Carpenter <[email protected]> Signed-off-by: Paolo Abeni <[email protected]> Acked-by: Jakub Sitnicki <[email protected]> Reviewed-by: Eric Dumazet <[email protected]> Reviewed-by: John Fastabend <[email protected]> Link: https://lore.kernel.org/r/8f99194c698bcef12666f0a9a999c58f8b1cb52c.1697557782.git.pabeni@redhat.com Signed-off-by: Jakub Kicinski <[email protected]>
1 parent a13b67c commit 68b54ae

File tree

1 file changed

+12
-4
lines changed

1 file changed

+12
-4
lines changed

net/ipv4/tcp_bpf.c

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -307,8 +307,10 @@ static int tcp_bpf_recvmsg_parser(struct sock *sk,
307307
}
308308

309309
data = tcp_msg_wait_data(sk, psock, timeo);
310-
if (data < 0)
311-
return data;
310+
if (data < 0) {
311+
copied = data;
312+
goto unlock;
313+
}
312314
if (data && !sk_psock_queue_empty(psock))
313315
goto msg_bytes_ready;
314316
copied = -EAGAIN;
@@ -319,6 +321,8 @@ static int tcp_bpf_recvmsg_parser(struct sock *sk,
319321
tcp_rcv_space_adjust(sk);
320322
if (copied > 0)
321323
__tcp_cleanup_rbuf(sk, copied);
324+
325+
unlock:
322326
release_sock(sk);
323327
sk_psock_put(sk, psock);
324328
return copied;
@@ -353,8 +357,10 @@ static int tcp_bpf_recvmsg(struct sock *sk, struct msghdr *msg, size_t len,
353357

354358
timeo = sock_rcvtimeo(sk, flags & MSG_DONTWAIT);
355359
data = tcp_msg_wait_data(sk, psock, timeo);
356-
if (data < 0)
357-
return data;
360+
if (data < 0) {
361+
ret = data;
362+
goto unlock;
363+
}
358364
if (data) {
359365
if (!sk_psock_queue_empty(psock))
360366
goto msg_bytes_ready;
@@ -365,6 +371,8 @@ static int tcp_bpf_recvmsg(struct sock *sk, struct msghdr *msg, size_t len,
365371
copied = -EAGAIN;
366372
}
367373
ret = copied;
374+
375+
unlock:
368376
release_sock(sk);
369377
sk_psock_put(sk, psock);
370378
return ret;

0 commit comments

Comments
 (0)