* [PATCH net] sctp: not bind the socket in sctp_connect
@ 2019-06-26 8:31 ` Xin Long
0 siblings, 0 replies; 10+ messages in thread
From: Xin Long @ 2019-06-26 8:31 UTC (permalink / raw)
To: network dev, linux-sctp
Cc: davem, Marcelo Ricardo Leitner, Neil Horman, syzkaller-bugs
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: 644fbdeacf1d ("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>
---
net/sctp/socket.c | 24 +++---------------------
1 file changed, 3 insertions(+), 21 deletions(-)
diff --git a/net/sctp/socket.c b/net/sctp/socket.c
index 39ea0a3..f33aa9e 100644
--- a/net/sctp/socket.c
+++ b/net/sctp/socket.c
@@ -4816,35 +4816,17 @@ static int sctp_setsockopt(struct sock *sk, int level, int optname,
static int sctp_connect(struct sock *sk, struct sockaddr *addr,
int addr_len, int flags)
{
- struct inet_sock *inet = inet_sk(sk);
struct sctp_af *af;
- int err = 0;
+ int err = -EINVAL;
lock_sock(sk);
-
pr_debug("%s: sk:%p, sockaddr:%p, addr_len:%d\n", __func__, sk,
addr, addr_len);
- /* We may need to bind the socket. */
- if (!inet->inet_num) {
- if (sk->sk_prot->get_port(sk, 0)) {
- release_sock(sk);
- return -EAGAIN;
- }
- inet->inet_sport = htons(inet->inet_num);
- }
-
/* Validate addr_len before calling common connect/connectx routine. */
- af = addr_len < offsetofend(struct sockaddr, sa_family) ? NULL :
- sctp_get_af_specific(addr->sa_family);
- if (!af || addr_len < af->sockaddr_len) {
- err = -EINVAL;
- } else {
- /* Pass correct addr len to common routine (so it knows there
- * is only one address being passed.
- */
+ af = sctp_get_af_specific(addr->sa_family);
+ if (af && addr_len >= af->sockaddr_len)
err = __sctp_connect(sk, addr, af->sockaddr_len, flags, NULL);
- }
release_sock(sk);
return err;
--
2.1.0
^ permalink raw reply related [flat|nested] 10+ messages in thread
* [PATCH net] sctp: not bind the socket in sctp_connect
@ 2019-06-26 8:31 ` Xin Long
0 siblings, 0 replies; 10+ messages in thread
From: Xin Long @ 2019-06-26 8:31 UTC (permalink / raw)
To: network dev, linux-sctp
Cc: davem, Marcelo Ricardo Leitner, Neil Horman, syzkaller-bugs
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: 644fbdeacf1d ("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>
---
net/sctp/socket.c | 24 +++---------------------
1 file changed, 3 insertions(+), 21 deletions(-)
diff --git a/net/sctp/socket.c b/net/sctp/socket.c
index 39ea0a3..f33aa9e 100644
--- a/net/sctp/socket.c
+++ b/net/sctp/socket.c
@@ -4816,35 +4816,17 @@ static int sctp_setsockopt(struct sock *sk, int level, int optname,
static int sctp_connect(struct sock *sk, struct sockaddr *addr,
int addr_len, int flags)
{
- struct inet_sock *inet = inet_sk(sk);
struct sctp_af *af;
- int err = 0;
+ int err = -EINVAL;
lock_sock(sk);
-
pr_debug("%s: sk:%p, sockaddr:%p, addr_len:%d\n", __func__, sk,
addr, addr_len);
- /* We may need to bind the socket. */
- if (!inet->inet_num) {
- if (sk->sk_prot->get_port(sk, 0)) {
- release_sock(sk);
- return -EAGAIN;
- }
- inet->inet_sport = htons(inet->inet_num);
- }
-
/* Validate addr_len before calling common connect/connectx routine. */
- af = addr_len < offsetofend(struct sockaddr, sa_family) ? NULL :
- sctp_get_af_specific(addr->sa_family);
- if (!af || addr_len < af->sockaddr_len) {
- err = -EINVAL;
- } else {
- /* Pass correct addr len to common routine (so it knows there
- * is only one address being passed.
- */
+ af = sctp_get_af_specific(addr->sa_family);
+ if (af && addr_len >= af->sockaddr_len)
err = __sctp_connect(sk, addr, af->sockaddr_len, flags, NULL);
- }
release_sock(sk);
return err;
--
2.1.0
^ permalink raw reply related [flat|nested] 10+ messages in thread
* Re: [PATCH net] sctp: not bind the socket in sctp_connect
2019-06-26 8:31 ` Xin Long
@ 2019-06-27 2:59 ` Marcelo Ricardo Leitner
-1 siblings, 0 replies; 10+ messages in thread
From: Marcelo Ricardo Leitner @ 2019-06-27 2:59 UTC (permalink / raw)
To: Xin Long; +Cc: network dev, linux-sctp, davem, Neil Horman, syzkaller-bugs
On Wed, Jun 26, 2019 at 04:31:39PM +0800, Xin Long wrote:
> 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: 644fbdeacf1d ("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>
Please give me another day to review this one. Thanks.
^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: [PATCH net] sctp: not bind the socket in sctp_connect
@ 2019-06-27 2:59 ` Marcelo Ricardo Leitner
0 siblings, 0 replies; 10+ messages in thread
From: Marcelo Ricardo Leitner @ 2019-06-27 2:59 UTC (permalink / raw)
To: Xin Long; +Cc: network dev, linux-sctp, davem, Neil Horman, syzkaller-bugs
On Wed, Jun 26, 2019 at 04:31:39PM +0800, Xin Long wrote:
> 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: 644fbdeacf1d ("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>
Please give me another day to review this one. Thanks.
^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: [PATCH net] sctp: not bind the socket in sctp_connect
2019-06-27 2:59 ` Marcelo Ricardo Leitner
@ 2019-06-27 16:21 ` David Miller
-1 siblings, 0 replies; 10+ messages in thread
From: David Miller @ 2019-06-27 16:21 UTC (permalink / raw)
To: marcelo.leitner; +Cc: lucien.xin, netdev, linux-sctp, nhorman, syzkaller-bugs
From: Marcelo Ricardo Leitner <marcelo.leitner@gmail.com>
Date: Wed, 26 Jun 2019 23:59:15 -0300
> Please give me another day to review this one. Thanks.
Sure, no problem.
^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: [PATCH net] sctp: not bind the socket in sctp_connect
@ 2019-06-27 16:21 ` David Miller
0 siblings, 0 replies; 10+ messages in thread
From: David Miller @ 2019-06-27 16:21 UTC (permalink / raw)
To: marcelo.leitner; +Cc: lucien.xin, netdev, linux-sctp, nhorman, syzkaller-bugs
From: Marcelo Ricardo Leitner <marcelo.leitner@gmail.com>
Date: Wed, 26 Jun 2019 23:59:15 -0300
> Please give me another day to review this one. Thanks.
Sure, no problem.
^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: [PATCH net] sctp: not bind the socket in sctp_connect
2019-06-26 8:31 ` Xin Long
@ 2019-06-27 22:32 ` Marcelo Ricardo Leitner
-1 siblings, 0 replies; 10+ messages in thread
From: Marcelo Ricardo Leitner @ 2019-06-27 22:32 UTC (permalink / raw)
To: Xin Long; +Cc: network dev, linux-sctp, davem, Neil Horman, syzkaller-bugs
On Wed, Jun 26, 2019 at 04:31:39PM +0800, Xin Long wrote:
> 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: 644fbdeacf1d ("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>
> ---
> net/sctp/socket.c | 24 +++---------------------
> 1 file changed, 3 insertions(+), 21 deletions(-)
>
> diff --git a/net/sctp/socket.c b/net/sctp/socket.c
> index 39ea0a3..f33aa9e 100644
> --- a/net/sctp/socket.c
> +++ b/net/sctp/socket.c
> @@ -4816,35 +4816,17 @@ static int sctp_setsockopt(struct sock *sk, int level, int optname,
> static int sctp_connect(struct sock *sk, struct sockaddr *addr,
> int addr_len, int flags)
> {
> - struct inet_sock *inet = inet_sk(sk);
> struct sctp_af *af;
> - int err = 0;
> + int err = -EINVAL;
>
> lock_sock(sk);
> -
> pr_debug("%s: sk:%p, sockaddr:%p, addr_len:%d\n", __func__, sk,
> addr, addr_len);
>
> - /* We may need to bind the socket. */
> - if (!inet->inet_num) {
> - if (sk->sk_prot->get_port(sk, 0)) {
> - release_sock(sk);
> - return -EAGAIN;
> - }
> - inet->inet_sport = htons(inet->inet_num);
> - }
> -
> /* Validate addr_len before calling common connect/connectx routine. */
> - af = addr_len < offsetofend(struct sockaddr, sa_family) ? NULL :
> - sctp_get_af_specific(addr->sa_family);
> - if (!af || addr_len < af->sockaddr_len) {
> - err = -EINVAL;
> - } else {
> - /* Pass correct addr len to common routine (so it knows there
> - * is only one address being passed.
> - */
> + af = sctp_get_af_specific(addr->sa_family);
> + if (af && addr_len >= af->sockaddr_len)
> err = __sctp_connect(sk, addr, af->sockaddr_len, flags, NULL);
> - }
>
> release_sock(sk);
> return err;
> --
> 2.1.0
>
^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: [PATCH net] sctp: not bind the socket in sctp_connect
@ 2019-06-27 22:32 ` Marcelo Ricardo Leitner
0 siblings, 0 replies; 10+ messages in thread
From: Marcelo Ricardo Leitner @ 2019-06-27 22:32 UTC (permalink / raw)
To: Xin Long; +Cc: network dev, linux-sctp, davem, Neil Horman, syzkaller-bugs
On Wed, Jun 26, 2019 at 04:31:39PM +0800, Xin Long wrote:
> 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: 644fbdeacf1d ("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>
> ---
> net/sctp/socket.c | 24 +++---------------------
> 1 file changed, 3 insertions(+), 21 deletions(-)
>
> diff --git a/net/sctp/socket.c b/net/sctp/socket.c
> index 39ea0a3..f33aa9e 100644
> --- a/net/sctp/socket.c
> +++ b/net/sctp/socket.c
> @@ -4816,35 +4816,17 @@ static int sctp_setsockopt(struct sock *sk, int level, int optname,
> static int sctp_connect(struct sock *sk, struct sockaddr *addr,
> int addr_len, int flags)
> {
> - struct inet_sock *inet = inet_sk(sk);
> struct sctp_af *af;
> - int err = 0;
> + int err = -EINVAL;
>
> lock_sock(sk);
> -
> pr_debug("%s: sk:%p, sockaddr:%p, addr_len:%d\n", __func__, sk,
> addr, addr_len);
>
> - /* We may need to bind the socket. */
> - if (!inet->inet_num) {
> - if (sk->sk_prot->get_port(sk, 0)) {
> - release_sock(sk);
> - return -EAGAIN;
> - }
> - inet->inet_sport = htons(inet->inet_num);
> - }
> -
> /* Validate addr_len before calling common connect/connectx routine. */
> - af = addr_len < offsetofend(struct sockaddr, sa_family) ? NULL :
> - sctp_get_af_specific(addr->sa_family);
> - if (!af || addr_len < af->sockaddr_len) {
> - err = -EINVAL;
> - } else {
> - /* Pass correct addr len to common routine (so it knows there
> - * is only one address being passed.
> - */
> + af = sctp_get_af_specific(addr->sa_family);
> + if (af && addr_len >= af->sockaddr_len)
> err = __sctp_connect(sk, addr, af->sockaddr_len, flags, NULL);
> - }
>
> release_sock(sk);
> return err;
> --
> 2.1.0
>
^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: [PATCH net] sctp: not bind the socket in sctp_connect
2019-06-26 8:31 ` Xin Long
@ 2019-06-29 17:51 ` David Miller
-1 siblings, 0 replies; 10+ messages in thread
From: David Miller @ 2019-06-29 17:51 UTC (permalink / raw)
To: lucien.xin; +Cc: netdev, linux-sctp, marcelo.leitner, nhorman, syzkaller-bugs
From: Xin Long <lucien.xin@gmail.com>
Date: Wed, 26 Jun 2019 16:31:39 +0800
> 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: 644fbdeacf1d ("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>
Applied and queued up for -stable, thanks.
^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: [PATCH net] sctp: not bind the socket in sctp_connect
@ 2019-06-29 17:51 ` David Miller
0 siblings, 0 replies; 10+ messages in thread
From: David Miller @ 2019-06-29 17:51 UTC (permalink / raw)
To: lucien.xin; +Cc: netdev, linux-sctp, marcelo.leitner, nhorman, syzkaller-bugs
From: Xin Long <lucien.xin@gmail.com>
Date: Wed, 26 Jun 2019 16:31:39 +0800
> 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: 644fbdeacf1d ("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>
Applied and queued up for -stable, thanks.
^ permalink raw reply [flat|nested] 10+ messages in thread
end of thread, other threads:[~2019-06-29 17:51 UTC | newest]
Thread overview: 10+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-06-26 8:31 [PATCH net] sctp: not bind the socket in sctp_connect Xin Long
2019-06-26 8:31 ` Xin Long
2019-06-27 2:59 ` Marcelo Ricardo Leitner
2019-06-27 2:59 ` Marcelo Ricardo Leitner
2019-06-27 16:21 ` David Miller
2019-06-27 16:21 ` David Miller
2019-06-27 22:32 ` Marcelo Ricardo Leitner
2019-06-27 22:32 ` Marcelo Ricardo Leitner
2019-06-29 17:51 ` David Miller
2019-06-29 17:51 ` David Miller
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.