Patch "sctp: ensure sk_state is set to CLOSED if hashing fails in sctp_listen_start" has been added to the 6.6-stable tree

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



This is a note to let you know that I've just added the patch titled

    sctp: ensure sk_state is set to CLOSED if hashing fails in sctp_listen_start

to the 6.6-stable tree which can be found at:
    http://www.kernel.org/git/?p=linux/kernel/git/stable/stable-queue.git;a=summary

The filename of the patch is:
     sctp-ensure-sk_state-is-set-to-closed-if-hashing-fai.patch
and it can be found in the queue-6.6 subdirectory.

If you, or anyone else, feels it should not be added to the stable tree,
please let <stable@xxxxxxxxxxxxxxx> know about it.



commit 57282a32bbe487a1426ad6c68a31d3ba2bbb42da
Author: Xin Long <lucien.xin@xxxxxxxxx>
Date:   Mon Oct 7 12:25:11 2024 -0400

    sctp: ensure sk_state is set to CLOSED if hashing fails in sctp_listen_start
    
    [ Upstream commit 4d5c70e6155d5eae198bade4afeab3c1b15073b6 ]
    
    If hashing fails in sctp_listen_start(), the socket remains in the
    LISTENING state, even though it was not added to the hash table.
    This can lead to a scenario where a socket appears to be listening
    without actually being accessible.
    
    This patch ensures that if the hashing operation fails, the sk_state
    is set back to CLOSED before returning an error.
    
    Note that there is no need to undo the autobind operation if hashing
    fails, as the bind port can still be used for next listen() call on
    the same socket.
    
    Fixes: 76c6d988aeb3 ("sctp: add sock_reuseport for the sock in __sctp_hash_endpoint")
    Reported-by: Marcelo Ricardo Leitner <marcelo.leitner@xxxxxxxxx>
    Signed-off-by: Xin Long <lucien.xin@xxxxxxxxx>
    Acked-by: Marcelo Ricardo Leitner <marcelo.leitner@xxxxxxxxx>
    Signed-off-by: David S. Miller <davem@xxxxxxxxxxxxx>
    Signed-off-by: Sasha Levin <sashal@xxxxxxxxxx>

diff --git a/net/sctp/socket.c b/net/sctp/socket.c
index 4a1ebe46d045d..108a0745c0c3c 100644
--- a/net/sctp/socket.c
+++ b/net/sctp/socket.c
@@ -8525,6 +8525,7 @@ static int sctp_listen_start(struct sock *sk, int backlog)
 	struct sctp_endpoint *ep = sp->ep;
 	struct crypto_shash *tfm = NULL;
 	char alg[32];
+	int err;
 
 	/* Allocate HMAC for generating cookie. */
 	if (!sp->hmac && sp->sctp_hmac_alg) {
@@ -8552,18 +8553,25 @@ static int sctp_listen_start(struct sock *sk, int backlog)
 	inet_sk_set_state(sk, SCTP_SS_LISTENING);
 	if (!ep->base.bind_addr.port) {
 		if (sctp_autobind(sk)) {
-			inet_sk_set_state(sk, SCTP_SS_CLOSED);
-			return -EAGAIN;
+			err = -EAGAIN;
+			goto err;
 		}
 	} else {
 		if (sctp_get_port(sk, inet_sk(sk)->inet_num)) {
-			inet_sk_set_state(sk, SCTP_SS_CLOSED);
-			return -EADDRINUSE;
+			err = -EADDRINUSE;
+			goto err;
 		}
 	}
 
 	WRITE_ONCE(sk->sk_max_ack_backlog, backlog);
-	return sctp_hash_endpoint(ep);
+	err = sctp_hash_endpoint(ep);
+	if (err)
+		goto err;
+
+	return 0;
+err:
+	inet_sk_set_state(sk, SCTP_SS_CLOSED);
+	return err;
 }
 
 /*




[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Index of Archives]     [Linux USB Devel]     [Linux Audio Users]     [Yosemite News]     [Linux Kernel]     [Linux SCSI]

  Powered by Linux