Skip to content

Commit 9170382

Browse files
author
Herton R. Krzesinski
committed
Merge: net: Return errno in sk->sk_prot->get_port().
MR: https://gitlab.com/redhat/centos-stream/src/kernel/centos-stream-9/-/merge_requests/1997 tcp: fix missing error on listen() failure Bugzilla: https://bugzilla.redhat.com/show_bug.cgi?id=2166482 Tested: vs bz reproducer A recently merged tcp changeset missed a need functional pre-req. As a consequence, the supposedly returned-to-user-space listen() error code is cleared even in case of failure. Address the issue backporting the missing pre-req Signed-off-by: Paolo Abeni <pabeni@redhat.com> Approved-by: Sabrina Dubroca <sdubroca@redhat.com> Approved-by: Antoine Tenart <atenart@redhat.com> Approved-by: Andrea Claudi <aclaudi@redhat.com> Signed-off-by: Herton R. Krzesinski <herton@redhat.com>
2 parents 6bf5d4e + 8912bbc commit 9170382

File tree

5 files changed

+10
-9
lines changed

5 files changed

+10
-9
lines changed

net/ipv4/af_inet.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -525,9 +525,9 @@ int __inet_bind(struct sock *sk, struct sockaddr *uaddr, int addr_len,
525525
/* Make sure we are allowed to bind here. */
526526
if (snum || !(inet->bind_address_no_port ||
527527
(flags & BIND_FORCE_ADDRESS_NO_PORT))) {
528-
if (sk->sk_prot->get_port(sk, snum)) {
528+
err = sk->sk_prot->get_port(sk, snum);
529+
if (err) {
529530
inet->inet_saddr = inet->inet_rcv_saddr = 0;
530-
err = -EADDRINUSE;
531531
goto out_release_sock;
532532
}
533533
if (!(flags & BIND_FROM_BPF)) {

net/ipv4/inet_connection_sock.c

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -367,7 +367,7 @@ int inet_csk_get_port(struct sock *sk, unsigned short snum)
367367
{
368368
bool reuse = sk->sk_reuse && sk->sk_state != TCP_LISTEN;
369369
struct inet_hashinfo *hinfo = sk->sk_prot->h.hashinfo;
370-
int ret = 1, port = snum;
370+
int ret = -EADDRINUSE, port = snum;
371371
struct inet_bind_hashbucket *head;
372372
struct net *net = sock_net(sk);
373373
struct inet_bind_bucket *tb = NULL;
@@ -1054,7 +1054,7 @@ int inet_csk_listen_start(struct sock *sk, int backlog)
10541054
{
10551055
struct inet_connection_sock *icsk = inet_csk(sk);
10561056
struct inet_sock *inet = inet_sk(sk);
1057-
int err = -EADDRINUSE;
1057+
int err;
10581058

10591059
err = inet_ulp_can_listen(sk);
10601060
if (unlikely(err))
@@ -1074,7 +1074,8 @@ int inet_csk_listen_start(struct sock *sk, int backlog)
10741074
* after validation is complete.
10751075
*/
10761076
inet_sk_state_store(sk, TCP_LISTEN);
1077-
if (!sk->sk_prot->get_port(sk, inet->inet_num)) {
1077+
err = sk->sk_prot->get_port(sk, inet->inet_num);
1078+
if (!err) {
10781079
inet->inet_sport = htons(inet->inet_num);
10791080

10801081
sk_dst_reset(sk);

net/ipv4/ping.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -142,7 +142,7 @@ int ping_get_port(struct sock *sk, unsigned short ident)
142142

143143
fail:
144144
spin_unlock(&ping_table.lock);
145-
return 1;
145+
return -EADDRINUSE;
146146
}
147147
EXPORT_SYMBOL_GPL(ping_get_port);
148148

net/ipv4/udp.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -234,8 +234,8 @@ int udp_lib_get_port(struct sock *sk, unsigned short snum,
234234
{
235235
struct udp_hslot *hslot, *hslot2;
236236
struct udp_table *udptable = sk->sk_prot->h.udp_table;
237-
int error = 1;
238237
struct net *net = sock_net(sk);
238+
int error = -EADDRINUSE;
239239

240240
if (!snum) {
241241
int low, high, remaining;

net/ipv6/af_inet6.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -411,10 +411,10 @@ static int __inet6_bind(struct sock *sk, struct sockaddr *uaddr, int addr_len,
411411
/* Make sure we are allowed to bind here. */
412412
if (snum || !(inet->bind_address_no_port ||
413413
(flags & BIND_FORCE_ADDRESS_NO_PORT))) {
414-
if (sk->sk_prot->get_port(sk, snum)) {
414+
err = sk->sk_prot->get_port(sk, snum);
415+
if (err) {
415416
sk->sk_ipv6only = saved_ipv6only;
416417
inet_reset_saddr(sk);
417-
err = -EADDRINUSE;
418418
goto out;
419419
}
420420
if (!(flags & BIND_FROM_BPF)) {

0 commit comments

Comments
 (0)