mirror of
https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git
synced 2024-10-05 16:37:50 +00:00
net: Return errno in sk->sk_prot->get_port().
[ Upstream commit7a7160edf1
] 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. Fixes:cec37a6e41
("mptcp: Handle MP_CAPABLE options for outgoing connections") Signed-off-by: Kuniyuki Iwashima <kuniyu@amazon.com> Signed-off-by: David S. Miller <davem@davemloft.net> Signed-off-by: Sasha Levin <sashal@kernel.org>
This commit is contained in:
parent
073b50de84
commit
d24fd986ae
5 changed files with 10 additions and 9 deletions
|
@ -522,9 +522,9 @@ int __inet_bind(struct sock *sk, struct sockaddr *uaddr, int addr_len,
|
||||||
/* Make sure we are allowed to bind here. */
|
/* Make sure we are allowed to bind here. */
|
||||||
if (snum || !(inet->bind_address_no_port ||
|
if (snum || !(inet->bind_address_no_port ||
|
||||||
(flags & BIND_FORCE_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;
|
inet->inet_saddr = inet->inet_rcv_saddr = 0;
|
||||||
err = -EADDRINUSE;
|
|
||||||
goto out_release_sock;
|
goto out_release_sock;
|
||||||
}
|
}
|
||||||
if (!(flags & BIND_FROM_BPF)) {
|
if (!(flags & BIND_FROM_BPF)) {
|
||||||
|
|
|
@ -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 reuse = sk->sk_reuse && sk->sk_state != TCP_LISTEN;
|
||||||
bool found_port = false, check_bind_conflict = true;
|
bool found_port = false, check_bind_conflict = true;
|
||||||
bool bhash_created = false, bhash2_created = false;
|
bool bhash_created = false, bhash2_created = false;
|
||||||
|
int ret = -EADDRINUSE, port = snum, l3mdev;
|
||||||
struct inet_bind_hashbucket *head, *head2;
|
struct inet_bind_hashbucket *head, *head2;
|
||||||
struct inet_bind2_bucket *tb2 = NULL;
|
struct inet_bind2_bucket *tb2 = NULL;
|
||||||
struct inet_bind_bucket *tb = NULL;
|
struct inet_bind_bucket *tb = NULL;
|
||||||
bool head2_lock_acquired = false;
|
bool head2_lock_acquired = false;
|
||||||
int ret = 1, port = snum, l3mdev;
|
|
||||||
struct net *net = sock_net(sk);
|
struct net *net = sock_net(sk);
|
||||||
|
|
||||||
l3mdev = inet_sk_bound_l3mdev(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_connection_sock *icsk = inet_csk(sk);
|
||||||
struct inet_sock *inet = inet_sk(sk);
|
struct inet_sock *inet = inet_sk(sk);
|
||||||
int err = -EADDRINUSE;
|
int err;
|
||||||
|
|
||||||
reqsk_queue_alloc(&icsk->icsk_accept_queue);
|
reqsk_queue_alloc(&icsk->icsk_accept_queue);
|
||||||
|
|
||||||
|
@ -1202,7 +1202,8 @@ int inet_csk_listen_start(struct sock *sk)
|
||||||
* after validation is complete.
|
* after validation is complete.
|
||||||
*/
|
*/
|
||||||
inet_sk_state_store(sk, TCP_LISTEN);
|
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);
|
inet->inet_sport = htons(inet->inet_num);
|
||||||
|
|
||||||
sk_dst_reset(sk);
|
sk_dst_reset(sk);
|
||||||
|
|
|
@ -143,7 +143,7 @@ int ping_get_port(struct sock *sk, unsigned short ident)
|
||||||
|
|
||||||
fail:
|
fail:
|
||||||
spin_unlock(&ping_table.lock);
|
spin_unlock(&ping_table.lock);
|
||||||
return 1;
|
return -EADDRINUSE;
|
||||||
}
|
}
|
||||||
EXPORT_SYMBOL_GPL(ping_get_port);
|
EXPORT_SYMBOL_GPL(ping_get_port);
|
||||||
|
|
||||||
|
|
|
@ -235,7 +235,7 @@ int udp_lib_get_port(struct sock *sk, unsigned short snum,
|
||||||
struct udp_table *udptable = sk->sk_prot->h.udp_table;
|
struct udp_table *udptable = sk->sk_prot->h.udp_table;
|
||||||
struct udp_hslot *hslot, *hslot2;
|
struct udp_hslot *hslot, *hslot2;
|
||||||
struct net *net = sock_net(sk);
|
struct net *net = sock_net(sk);
|
||||||
int error = 1;
|
int error = -EADDRINUSE;
|
||||||
|
|
||||||
if (!snum) {
|
if (!snum) {
|
||||||
DECLARE_BITMAP(bitmap, PORTS_PER_CHAIN);
|
DECLARE_BITMAP(bitmap, PORTS_PER_CHAIN);
|
||||||
|
|
|
@ -409,10 +409,10 @@ static int __inet6_bind(struct sock *sk, struct sockaddr *uaddr, int addr_len,
|
||||||
/* Make sure we are allowed to bind here. */
|
/* Make sure we are allowed to bind here. */
|
||||||
if (snum || !(inet->bind_address_no_port ||
|
if (snum || !(inet->bind_address_no_port ||
|
||||||
(flags & BIND_FORCE_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;
|
sk->sk_ipv6only = saved_ipv6only;
|
||||||
inet_reset_saddr(sk);
|
inet_reset_saddr(sk);
|
||||||
err = -EADDRINUSE;
|
|
||||||
goto out;
|
goto out;
|
||||||
}
|
}
|
||||||
if (!(flags & BIND_FROM_BPF)) {
|
if (!(flags & BIND_FROM_BPF)) {
|
||||||
|
|
Loading…
Reference in a new issue