Commit 68b54aef authored by Paolo Abeni's avatar Paolo Abeni Committed by Jakub Kicinski

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: 419ce133 ("tcp: allow again tcp_disconnect() when threads are waiting")
Reported-by: default avatarDan Carpenter <dan.carpenter@linaro.org>
Signed-off-by: default avatarPaolo Abeni <pabeni@redhat.com>
Acked-by: default avatarJakub Sitnicki <jakub@cloudflare.com>
Reviewed-by: default avatarEric Dumazet <edumazet@google.com>
Reviewed-by: default avatarJohn Fastabend <john.fastabend@gmail.com>
Link: https://lore.kernel.org/r/8f99194c698bcef12666f0a9a999c58f8b1cb52c.1697557782.git.pabeni@redhat.comSigned-off-by: default avatarJakub Kicinski <kuba@kernel.org>
parent a13b67c9
...@@ -307,8 +307,10 @@ static int tcp_bpf_recvmsg_parser(struct sock *sk, ...@@ -307,8 +307,10 @@ static int tcp_bpf_recvmsg_parser(struct sock *sk,
} }
data = tcp_msg_wait_data(sk, psock, timeo); data = tcp_msg_wait_data(sk, psock, timeo);
if (data < 0) if (data < 0) {
return data; copied = data;
goto unlock;
}
if (data && !sk_psock_queue_empty(psock)) if (data && !sk_psock_queue_empty(psock))
goto msg_bytes_ready; goto msg_bytes_ready;
copied = -EAGAIN; copied = -EAGAIN;
...@@ -319,6 +321,8 @@ static int tcp_bpf_recvmsg_parser(struct sock *sk, ...@@ -319,6 +321,8 @@ static int tcp_bpf_recvmsg_parser(struct sock *sk,
tcp_rcv_space_adjust(sk); tcp_rcv_space_adjust(sk);
if (copied > 0) if (copied > 0)
__tcp_cleanup_rbuf(sk, copied); __tcp_cleanup_rbuf(sk, copied);
unlock:
release_sock(sk); release_sock(sk);
sk_psock_put(sk, psock); sk_psock_put(sk, psock);
return copied; return copied;
...@@ -353,8 +357,10 @@ static int tcp_bpf_recvmsg(struct sock *sk, struct msghdr *msg, size_t len, ...@@ -353,8 +357,10 @@ static int tcp_bpf_recvmsg(struct sock *sk, struct msghdr *msg, size_t len,
timeo = sock_rcvtimeo(sk, flags & MSG_DONTWAIT); timeo = sock_rcvtimeo(sk, flags & MSG_DONTWAIT);
data = tcp_msg_wait_data(sk, psock, timeo); data = tcp_msg_wait_data(sk, psock, timeo);
if (data < 0) if (data < 0) {
return data; ret = data;
goto unlock;
}
if (data) { if (data) {
if (!sk_psock_queue_empty(psock)) if (!sk_psock_queue_empty(psock))
goto msg_bytes_ready; goto msg_bytes_ready;
...@@ -365,6 +371,8 @@ static int tcp_bpf_recvmsg(struct sock *sk, struct msghdr *msg, size_t len, ...@@ -365,6 +371,8 @@ static int tcp_bpf_recvmsg(struct sock *sk, struct msghdr *msg, size_t len,
copied = -EAGAIN; copied = -EAGAIN;
} }
ret = copied; ret = copied;
unlock:
release_sock(sk); release_sock(sk);
sk_psock_put(sk, psock); sk_psock_put(sk, psock);
return ret; return ret;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment