Skip to content

Commit 9b6c088

Browse files
lxindavem330
authored andcommitted
sctp: not bind the socket in sctp_connect
Now when sctp_connect() is called with a wrong sa_family, it binds to a port but doesn't set bp->port, then sctp_get_af_specific will return NULL and sctp_connect() returns -EINVAL. Then if sctp_bind() is called to bind to another port, the last port it has bound will leak due to bp->port is NULL by then. sctp_connect() doesn't need to bind ports, as later __sctp_connect will do it if bp->port is NULL. So remove it from sctp_connect(). While at it, remove the unnecessary sockaddr.sa_family len check as it's already done in sctp_inet_connect. Fixes: 644fbde ("sctp: fix the issue that flags are ignored when using kernel_connect") Reported-by: syzbot+079bf326b38072f849d9@syzkaller.appspotmail.com Signed-off-by: Xin Long <lucien.xin@gmail.com> Acked-by: Marcelo Ricardo Leitner <marcelo.leitner@gmail.com> Signed-off-by: David S. Miller <davem@davemloft.net>
1 parent 8ec3ede commit 9b6c088

1 file changed

Lines changed: 3 additions & 21 deletions

File tree

‎net/sctp/socket.c‎

Lines changed: 3 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -4816,35 +4816,17 @@ static int sctp_setsockopt(struct sock *sk, int level, int optname,
48164816
static int sctp_connect(struct sock *sk, struct sockaddr *addr,
48174817
int addr_len, int flags)
48184818
{
4819-
struct inet_sock *inet = inet_sk(sk);
48204819
struct sctp_af *af;
4821-
int err = 0;
4820+
int err = -EINVAL;
48224821

48234822
lock_sock(sk);
4824-
48254823
pr_debug("%s: sk:%p, sockaddr:%p, addr_len:%d\n", __func__, sk,
48264824
addr, addr_len);
48274825

4828-
/* We may need to bind the socket. */
4829-
if (!inet->inet_num) {
4830-
if (sk->sk_prot->get_port(sk, 0)) {
4831-
release_sock(sk);
4832-
return -EAGAIN;
4833-
}
4834-
inet->inet_sport = htons(inet->inet_num);
4835-
}
4836-
48374826
/* Validate addr_len before calling common connect/connectx routine. */
4838-
af = addr_len < offsetofend(struct sockaddr, sa_family) ? NULL :
4839-
sctp_get_af_specific(addr->sa_family);
4840-
if (!af || addr_len < af->sockaddr_len) {
4841-
err = -EINVAL;
4842-
} else {
4843-
/* Pass correct addr len to common routine (so it knows there
4844-
* is only one address being passed.
4845-
*/
4827+
af = sctp_get_af_specific(addr->sa_family);
4828+
if (af && addr_len >= af->sockaddr_len)
48464829
err = __sctp_connect(sk, addr, af->sockaddr_len, flags, NULL);
4847-
}
48484830

48494831
release_sock(sk);
48504832
return err;

0 commit comments

Comments
 (0)