net: Return errno in sk->sk_prot->get_port().
Subsystems (5)
PATCH v2 1/1 net: Return errno in sk->sk_prot->get_port().
We assume the correct errno is -EADDRINUSE when sk->sk_prot->get_port() fails, so some ->get_port() functions return just 1 on failure and the callers return -EADDRINUSE instead.
However, mptcp_get_port() can return -EINVAL. Let's not ignore the error.
Note the only exception is inet_autobind(), all of whose callers return -EAGAIN instead.
---
v2:
* Rebase and target net-next
v1: https://lore.kernel.org/netdev/[email protected]/
---
--- net/ipv4/af_inet.c | 4 ++-- net/ipv4/inet_connection_sock.c | 7 ++++--- net/ipv4/ping.c | 2 +- net/ipv4/udp.c | 2 +- net/ipv6/af_inet6.c | 4 ++-- 5 files changed, 10 insertions(+), 9 deletions(-)
net/ipv4/af_inet.c +2 -2
@@ -522,9 +522,9 @@ int __inet_bind(struct sock *sk, struct sockaddr *uaddr, int addr_len,/* Make sure we are allowed to bind here. */ if (snum || !(inet->bind_address_no_port || (flags &BIND_FORCE_ADDRESS_NO_PORT ))) { -if (sk->sk_prot->get_port (sk, snum)) { + err = sk->sk_prot->get_port (sk, snum); +if (err) { inet->inet_saddr = inet->inet_rcv_saddr =0 ; - err = -EADDRINUSE ; goto out_release_sock; }if (!(flags &BIND_FROM_BPF )) {
net/ipv4/inet_connection_sock.c +4 -3
@@ -471,11 +471,11 @@ int inet_csk_get_port(struct sock *sk, unsigned short snum)bool reuse = sk->sk_reuse && sk->sk_state !=TCP_LISTEN ;bool found_port = false, check_bind_conflict = true;bool bhash_created = false, bhash2_created = false; +int ret = -EADDRINUSE , port = snum, l3mdev;struct inet_bind_hashbucket *head, *head2;struct inet_bind2_bucket *tb2 =NULL ;struct inet_bind_bucket *tb =NULL ;bool head2_lock_acquired = false; -int ret =1 , port = snum, l3mdev;struct net *net =sock_net (sk); l3mdev =inet_sk_bound_l3mdev (sk);
@@ -1186,7 +1186,7 @@ int inet_csk_listen_start(struct sock *sk) {struct inet_connection_sock *icsk =inet_csk (sk);struct inet_sock *inet =inet_sk (sk); -int err = -EADDRINUSE ; +int err;reqsk_queue_alloc (&icsk->icsk_accept_queue);
@@ -1202,7 +1202,8 @@ int inet_csk_listen_start(struct sock *sk)* after validation is complete. */ inet_sk_state_store (sk,TCP_LISTEN ); -if (!sk->sk_prot->get_port (sk, inet->inet_num)) { + err = sk->sk_prot->get_port (sk, inet->inet_num); +if (!err) { inet->inet_sport =htons (inet->inet_num);sk_dst_reset (sk);
net/ipv4/ping.c +1 -1
@@ -138,7 +138,7 @@ int ping_get_port(struct sock *sk, unsigned short ident) fail:spin_unlock (&ping_table.lock); -return 1 ; +return -EADDRINUSE ; }EXPORT_SYMBOL_GPL (ping_get_port);
net/ipv4/udp.c +1 -1
@@ -240,7 +240,7 @@ int udp_lib_get_port(struct sock *sk, unsigned short snum,struct udp_table *udptable =udp_get_table_prot (sk);struct udp_hslot *hslot, *hslot2;struct net *net =sock_net (sk); -int error =1 ; +int error = -EADDRINUSE ;if (!snum) {DECLARE_BITMAP (bitmap,PORTS_PER_CHAIN );
net/ipv6/af_inet6.c +2 -2
@@ -410,10 +410,10 @@ static int __inet6_bind(struct sock *sk, struct sockaddr *uaddr, int addr_len,/* Make sure we are allowed to bind here. */ if (snum || !(inet->bind_address_no_port || (flags &BIND_FORCE_ADDRESS_NO_PORT ))) { -if (sk->sk_prot->get_port (sk, snum)) { + err = sk->sk_prot->get_port (sk, snum); +if (err) { sk->sk_ipv6only = saved_ipv6only;inet_reset_saddr (sk); - err = -EADDRINUSE ; goto out; }if (!(flags &BIND_FROM_BPF )) {
Signature · 1 line
2.30.2
Re: net: Return errno in sk->sk_prot->get_port().: Tests Results
Hi Kuniyuki,
Thank you for your modifications, that's great!
Our CI did some validations and here is its report:
- KVM Validation: normal:
- Success! ✅:
- Task: https://cirrus-ci.com/task/6597844069515264
- Summary: https://api.cirrus-ci.com/v1/artifact/task/6597844069515264/summary/summary.txt
- KVM Validation: debug:
- Success! ✅:
- Task: https://cirrus-ci.com/task/5194679124754432
- Summary: https://api.cirrus-ci.com/v1/artifact/task/5194679124754432/summary/summary.txt
Initiator: Patchew Applier
Commits: https://github.com/multipath-tcp/mptcp_net-next/commits/7b46793b7793
If there are some issues, you can reproduce them using the same environment as the one used by the CI thanks to a docker image, e.g.:
$ cd [kernel source code]
$ docker run -v "${PWD}:${PWD}:rw" -w "${PWD}" --privileged --rm -it \
--pull always mptcp/mptcp-upstream-virtme-docker:latest \
auto-debugFor more details:
https://github.com/multipath-tcp/mptcp-upstream-virtme-docker
Please note that despite all the efforts that have been already done to have a stable tests suite when executed on a public CI like here, it is possible some reported issues are not due to your modifications. Still, do not hesitate to help us improve that ;-)
Cheers,
MPTCP GH Action bot
Bot operated by Matthieu Baerts (Tessares)
This patch was applied to netdev/net-next.git (master) by David S. Miller <[email protected]>:
Hello:
This patch was applied to netdev/net-next.git (master) by David S. Miller <[email protected]>:
Quoted 10 lines · On Fri, 18 Nov 2022 10:25:06 -0800 you wrote:
We assume the correct errno is
-EADDRINUSEwhensk->sk_prot->get_port()fails, so some ->get_port() functions return just 1 on failure and the callers return-EADDRINUSEinstead.However,
mptcp_get_port()can return-EINVAL. Let's not ignore the error.Note the only exception is
inet_autobind(), all of whose callers return-EAGAINinstead.[...]
Here is the summary with links:
- [v2,net-next] net: Return errno in sk->sk_prot->get_port().
https://git.kernel.org/netdev/net-next/c/7a7160edf1bf
You are awesome, thank you!
Signature · 2 lines
Deet-doot-dot, I am a bot. https://korg.docs.kernel.org/patchwork/pwbot.html