All of lore.kernel.org
 help / color / mirror / Atom feed
From: "Leppanen, Jere (Nokia - FI/Espoo)" <jere.leppanen@nokia.com>
To: Xin Long <lucien.xin@gmail.com>,
	network dev <netdev@vger.kernel.org>,
	"linux-sctp@vger.kernel.org" <linux-sctp@vger.kernel.org>
Cc: "davem@davemloft.net" <davem@davemloft.net>,
	Marcelo Ricardo Leitner <marcelo.leitner@gmail.com>,
	Neil Horman <nhorman@tuxdriver.com>,
	"michael.tuexen@lurchi.franken.de"
	<michael.tuexen@lurchi.franken.de>
Subject: RE: [PATCH net] sctp: return a one-to-one type socket when doing peeloff
Date: Tue, 3 Mar 2020 18:38:35 +0000	[thread overview]
Message-ID: <HE1PR0702MB3610BB291019DD7F51DBC906ECE40@HE1PR0702MB3610.eurprd07.prod.outlook.com> (raw)
In-Reply-To: <b3091c0764023bbbb17a26a71e124d0f81349f20.1583132235.git.lucien.xin@gmail.com>

On Mon, 2 Mar 2020, Xin Long wrote:

> As it says in rfc6458#section-9.2:
> 
>   The application uses the sctp_peeloff() call to branch off an
>   association into a separate socket.  (Note that the semantics are
>   somewhat changed from the traditional one-to-one style accept()
>   call.)  Note also that the new socket is a one-to-one style socket.
>   Thus, it will be confined to operations allowed for a one-to-one
>   style socket.
> 
> Prior to this patch, sctp_peeloff() returned a one-to-many type socket,
> on which some operations are not allowed, like shutdown, as Jere
> reported.
> 
> This patch is to change it to return a one-to-one type socket instead.

Thanks for looking into this. I like the patch, and it fixes my simple
test case.

But with this patch, peeled-off sockets are created by copying from a
one-to-many socket to a one-to-one socket. Are you sure that that's
not going to cause any problems? Is it possible that there was a
reason why peeloff wasn't implemented this way in the first place?

With this patch there's no way to create UDP_HIGH_BANDWIDTH style
sockets anymore, so the remaining references should probably be
cleaned up:

./net/sctp/socket.c:1886:       if (!sctp_style(sk, UDP_HIGH_BANDWIDTH) && msg->msg_name) {
./net/sctp/socket.c:8522:       if (sctp_style(sk, UDP_HIGH_BANDWIDTH))
./include/net/sctp/structs.h:144:       SCTP_SOCKET_UDP_HIGH_BANDWIDTH,

This patch disables those checks. The first one ignores a destination
address given to sendmsg() with a peeled-off socket - I don't know
why. The second one prevents listen() on a peeled-off socket.

> 
> Fixes: 1da177e4c3f4 ("Linux-2.6.12-rc2")
> Reported-by: Leppanen, Jere (Nokia - FI/Espoo) <jere.leppanen@nokia.com>

Reported-by: Jere Leppanen <jere.leppanen@nokia.com>

> Signed-off-by: Xin Long <lucien.xin@gmail.com>
> ---
>  net/sctp/socket.c | 15 ++++++---------
>  1 file changed, 6 insertions(+), 9 deletions(-)
> 
> diff --git a/net/sctp/socket.c b/net/sctp/socket.c
> index 1b56fc4..2b55beb 100644
> --- a/net/sctp/socket.c
> +++ b/net/sctp/socket.c
> @@ -88,8 +88,7 @@ static int sctp_send_asconf(struct sctp_association *asoc,
>  static int sctp_do_bind(struct sock *, union sctp_addr *, int);
>  static int sctp_autobind(struct sock *sk);
>  static int sctp_sock_migrate(struct sock *oldsk, struct sock *newsk,
> -			     struct sctp_association *assoc,
> -			     enum sctp_socket_type type);
> +			     struct sctp_association *assoc);
>  
>  static unsigned long sctp_memory_pressure;
>  static atomic_long_t sctp_memory_allocated;
> @@ -4965,7 +4964,7 @@ static struct sock *sctp_accept(struct sock *sk, int flags, int *err, bool kern)
>  	/* Populate the fields of the newsk from the oldsk and migrate the
>  	 * asoc to the newsk.
>  	 */
> -	error = sctp_sock_migrate(sk, newsk, asoc, SCTP_SOCKET_TCP);
> +	error = sctp_sock_migrate(sk, newsk, asoc);
>  	if (error) {
>  		sk_common_release(newsk);
>  		newsk = NULL;
> @@ -5711,7 +5710,7 @@ int sctp_do_peeloff(struct sock *sk, sctp_assoc_t id, struct socket **sockp)
>  		return -EINVAL;
>  
>  	/* Create a new socket.  */
> -	err = sock_create(sk->sk_family, SOCK_SEQPACKET, IPPROTO_SCTP, &sock);
> +	err = sock_create(sk->sk_family, SOCK_STREAM, IPPROTO_SCTP, &sock);
>  	if (err < 0)
>  		return err;
>  
> @@ -5727,8 +5726,7 @@ int sctp_do_peeloff(struct sock *sk, sctp_assoc_t id, struct socket **sockp)
>  	/* Populate the fields of the newsk from the oldsk and migrate the
>  	 * asoc to the newsk.
>  	 */
> -	err = sctp_sock_migrate(sk, sock->sk, asoc,
> -				SCTP_SOCKET_UDP_HIGH_BANDWIDTH);
> +	err = sctp_sock_migrate(sk, sock->sk, asoc);
>  	if (err) {
>  		sock_release(sock);
>  		sock = NULL;
> @@ -9453,8 +9451,7 @@ static inline void sctp_copy_descendant(struct sock *sk_to,
>   * and its messages to the newsk.
>   */
>  static int sctp_sock_migrate(struct sock *oldsk, struct sock *newsk,
> -			     struct sctp_association *assoc,
> -			     enum sctp_socket_type type)
> +			     struct sctp_association *assoc)
>  {
>  	struct sctp_sock *oldsp = sctp_sk(oldsk);
>  	struct sctp_sock *newsp = sctp_sk(newsk);
> @@ -9562,7 +9559,7 @@ static int sctp_sock_migrate(struct sock *oldsk, struct sock *newsk,
>  	 * original UDP-style socket or created with the accept() call on a
>  	 * TCP-style socket..
>  	 */
> -	newsp->type = type;
> +	newsp->type = SCTP_SOCKET_TCP;
>  
>  	/* Mark the new socket "in-use" by the user so that any packets
>  	 * that may arrive on the association after we've moved it are
> -- 
> 2.1.0

WARNING: multiple messages have this Message-ID (diff)
From: "Leppanen, Jere (Nokia - FI/Espoo)" <jere.leppanen@nokia.com>
To: Xin Long <lucien.xin@gmail.com>,
	network dev <netdev@vger.kernel.org>,
	"linux-sctp@vger.kernel.org" <linux-sctp@vger.kernel.org>
Cc: "davem@davemloft.net" <davem@davemloft.net>,
	Marcelo Ricardo Leitner <marcelo.leitner@gmail.com>,
	Neil Horman <nhorman@tuxdriver.com>,
	"michael.tuexen@lurchi.franken.de"
	<michael.tuexen@lurchi.franken.de>
Subject: RE: [PATCH net] sctp: return a one-to-one type socket when doing peeloff
Date: Tue, 03 Mar 2020 18:38:35 +0000	[thread overview]
Message-ID: <HE1PR0702MB3610BB291019DD7F51DBC906ECE40@HE1PR0702MB3610.eurprd07.prod.outlook.com> (raw)
In-Reply-To: <b3091c0764023bbbb17a26a71e124d0f81349f20.1583132235.git.lucien.xin@gmail.com>

On Mon, 2 Mar 2020, Xin Long wrote:

> As it says in rfc6458#section-9.2:
> 
>   The application uses the sctp_peeloff() call to branch off an
>   association into a separate socket.  (Note that the semantics are
>   somewhat changed from the traditional one-to-one style accept()
>   call.)  Note also that the new socket is a one-to-one style socket.
>   Thus, it will be confined to operations allowed for a one-to-one
>   style socket.
> 
> Prior to this patch, sctp_peeloff() returned a one-to-many type socket,
> on which some operations are not allowed, like shutdown, as Jere
> reported.
> 
> This patch is to change it to return a one-to-one type socket instead.

Thanks for looking into this. I like the patch, and it fixes my simple
test case.

But with this patch, peeled-off sockets are created by copying from a
one-to-many socket to a one-to-one socket. Are you sure that that's
not going to cause any problems? Is it possible that there was a
reason why peeloff wasn't implemented this way in the first place?

With this patch there's no way to create UDP_HIGH_BANDWIDTH style
sockets anymore, so the remaining references should probably be
cleaned up:

./net/sctp/socket.c:1886:       if (!sctp_style(sk, UDP_HIGH_BANDWIDTH) && msg->msg_name) {
./net/sctp/socket.c:8522:       if (sctp_style(sk, UDP_HIGH_BANDWIDTH))
./include/net/sctp/structs.h:144:       SCTP_SOCKET_UDP_HIGH_BANDWIDTH,

This patch disables those checks. The first one ignores a destination
address given to sendmsg() with a peeled-off socket - I don't know
why. The second one prevents listen() on a peeled-off socket.

> 
> Fixes: 1da177e4c3f4 ("Linux-2.6.12-rc2")
> Reported-by: Leppanen, Jere (Nokia - FI/Espoo) <jere.leppanen@nokia.com>

Reported-by: Jere Leppanen <jere.leppanen@nokia.com>

> Signed-off-by: Xin Long <lucien.xin@gmail.com>
> ---
>  net/sctp/socket.c | 15 ++++++---------
>  1 file changed, 6 insertions(+), 9 deletions(-)
> 
> diff --git a/net/sctp/socket.c b/net/sctp/socket.c
> index 1b56fc4..2b55beb 100644
> --- a/net/sctp/socket.c
> +++ b/net/sctp/socket.c
> @@ -88,8 +88,7 @@ static int sctp_send_asconf(struct sctp_association *asoc,
>  static int sctp_do_bind(struct sock *, union sctp_addr *, int);
>  static int sctp_autobind(struct sock *sk);
>  static int sctp_sock_migrate(struct sock *oldsk, struct sock *newsk,
> -			     struct sctp_association *assoc,
> -			     enum sctp_socket_type type);
> +			     struct sctp_association *assoc);
>  
>  static unsigned long sctp_memory_pressure;
>  static atomic_long_t sctp_memory_allocated;
> @@ -4965,7 +4964,7 @@ static struct sock *sctp_accept(struct sock *sk, int flags, int *err, bool kern)
>  	/* Populate the fields of the newsk from the oldsk and migrate the
>  	 * asoc to the newsk.
>  	 */
> -	error = sctp_sock_migrate(sk, newsk, asoc, SCTP_SOCKET_TCP);
> +	error = sctp_sock_migrate(sk, newsk, asoc);
>  	if (error) {
>  		sk_common_release(newsk);
>  		newsk = NULL;
> @@ -5711,7 +5710,7 @@ int sctp_do_peeloff(struct sock *sk, sctp_assoc_t id, struct socket **sockp)
>  		return -EINVAL;
>  
>  	/* Create a new socket.  */
> -	err = sock_create(sk->sk_family, SOCK_SEQPACKET, IPPROTO_SCTP, &sock);
> +	err = sock_create(sk->sk_family, SOCK_STREAM, IPPROTO_SCTP, &sock);
>  	if (err < 0)
>  		return err;
>  
> @@ -5727,8 +5726,7 @@ int sctp_do_peeloff(struct sock *sk, sctp_assoc_t id, struct socket **sockp)
>  	/* Populate the fields of the newsk from the oldsk and migrate the
>  	 * asoc to the newsk.
>  	 */
> -	err = sctp_sock_migrate(sk, sock->sk, asoc,
> -				SCTP_SOCKET_UDP_HIGH_BANDWIDTH);
> +	err = sctp_sock_migrate(sk, sock->sk, asoc);
>  	if (err) {
>  		sock_release(sock);
>  		sock = NULL;
> @@ -9453,8 +9451,7 @@ static inline void sctp_copy_descendant(struct sock *sk_to,
>   * and its messages to the newsk.
>   */
>  static int sctp_sock_migrate(struct sock *oldsk, struct sock *newsk,
> -			     struct sctp_association *assoc,
> -			     enum sctp_socket_type type)
> +			     struct sctp_association *assoc)
>  {
>  	struct sctp_sock *oldsp = sctp_sk(oldsk);
>  	struct sctp_sock *newsp = sctp_sk(newsk);
> @@ -9562,7 +9559,7 @@ static int sctp_sock_migrate(struct sock *oldsk, struct sock *newsk,
>  	 * original UDP-style socket or created with the accept() call on a
>  	 * TCP-style socket..
>  	 */
> -	newsp->type = type;
> +	newsp->type = SCTP_SOCKET_TCP;
>  
>  	/* Mark the new socket "in-use" by the user so that any packets
>  	 * that may arrive on the association after we've moved it are
> -- 
> 2.1.0

  reply	other threads:[~2020-03-03 18:38 UTC|newest]

Thread overview: 23+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-03-02  6:57 [PATCH net] sctp: return a one-to-one type socket when doing peeloff Xin Long
2020-03-02  6:57 ` Xin Long
2020-03-03 18:38 ` Leppanen, Jere (Nokia - FI/Espoo) [this message]
2020-03-03 18:38   ` Leppanen, Jere (Nokia - FI/Espoo)
2020-03-04  9:38   ` Xin Long
2020-03-04  9:38     ` Xin Long
2020-03-04 17:13     ` Jere Leppanen
2020-03-04 17:13       ` Jere Leppanen
2020-03-05 14:01       ` David Laight
2020-03-05 14:01         ` David Laight
2020-03-05 17:31         ` Jere Leppanen
2020-03-05 17:31           ` Jere Leppanen
2020-03-11  3:34       ` Marcelo Ricardo Leitner
2020-03-11  3:34         ` Marcelo Ricardo Leitner
2020-03-11 18:41         ` Jere Leppanen
2020-03-11 18:41           ` Jere Leppanen
2020-03-10  1:09 ` David Miller
2020-03-10  1:09   ` David Miller
2020-03-11  3:35   ` Marcelo Ricardo Leitner
2020-03-11  3:35     ` Marcelo Ricardo Leitner
2020-03-13  0:27 ` [sctp] 38ec705901: ltp.test_peeloff.fail kernel test robot
2020-03-13  0:27   ` kernel test robot
2020-03-13  0:27   ` [LTP] " kernel test robot

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=HE1PR0702MB3610BB291019DD7F51DBC906ECE40@HE1PR0702MB3610.eurprd07.prod.outlook.com \
    --to=jere.leppanen@nokia.com \
    --cc=davem@davemloft.net \
    --cc=linux-sctp@vger.kernel.org \
    --cc=lucien.xin@gmail.com \
    --cc=marcelo.leitner@gmail.com \
    --cc=michael.tuexen@lurchi.franken.de \
    --cc=netdev@vger.kernel.org \
    --cc=nhorman@tuxdriver.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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.