From: Marcelo Ricardo Leitner <marcelo.leitner@gmail.com>
To: linux-sctp@vger.kernel.org
Subject: Re: SCTP_SOCKOPT_PEELOFF is missing SOCK_CLOEXEC (and SOCK_NONBLOCK)
Date: Tue, 20 Jun 2017 15:41:47 +0000 [thread overview]
Message-ID: <20170620154147.GA18138@localhost.localdomain> (raw)
In-Reply-To: <1497965053.10887.2.camel@domdv.de>
Hi,
On Tue, Jun 20, 2017 at 10:39:51AM -0400, Neil Horman wrote:
> On Tue, Jun 20, 2017 at 03:24:13PM +0200, Andreas Steinmetz wrote:
> > [please CC me, I'm not subscribed]
> >
> > It seems that if one does a getsockopt(SCTP_SOCKOPT_PEELOFF) a.k.a.
> > sctp_peeloff(), even if the socket descriptor from which the
> > association is to be peeled off has SOCK_CLOEXEC/SOCK_NONBLOCK set,
> > the peeled off socket descriptor doesn't have so.
> >
> > It would be advisable to either clone these flags or add an atomic
> > version of SCTP_SOCKOPT_PEELOFF (accept4() style).
> >
> > The missing SOCK_CLOEXEC requires unintentional additional locking
> > which typically is prone to errors and can slow down processing.
> > --
> > Andreas Steinmetz SPAMmers use robotrap@domdv.de
> > --
> > To unsubscribe from this list: send the line "unsubscribe linux-sctp" in
> > the body of a message to majordomo@vger.kernel.org
> > More majordomo info at http://vger.kernel.org/majordomo-info.html
> >
>
>
> Try this patch, and confirm that it fixes the problem please?
>
> Thanks!
> Neil
>
>
> diff --git a/net/sctp/socket.c b/net/sctp/socket.c
> index f16c8d9..a95e3d6 100644
> --- a/net/sctp/socket.c
> +++ b/net/sctp/socket.c
> @@ -4912,7 +4912,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, sk->sk_type, IPPROTO_SCTP, &sock);
I don't think this will work. Syscall socket() filters out these
flags and handle them separetly after calling sock_create() with just
the type, so I don't think this information is preserved in there.
Interesting to note that according to man page dup() syscall also
doesn't duplicate these flags. One has to use dup3() instead in order to
be able to specify them.
Maybe by extending sctp_peeloff_arg_t to have a flags attribute in
there, we can allow the application to specify it and feed into
get_unused_fd_flags() call in sctp_getsockopt_peeloff() instead, or even
just overload the sd, which is currently an output-only value, to
contain flags as the patch below. (We probably should add some sanity
checking in there, though)
Thanks,
Marcelo
---8<---
diff --git a/net/sctp/socket.c b/net/sctp/socket.c
index e1fabf67d4ad..50021a925b16 100644
--- a/net/sctp/socket.c
+++ b/net/sctp/socket.c
@@ -4950,8 +4950,10 @@ static int sctp_getsockopt_peeloff(struct sock *sk, int len, char __user *optval
if (retval < 0)
goto out;
- /* Map the socket to an unused fd that can be returned to the user. */
- retval = get_unused_fd_flags(0);
+ /* Map the socket to an unused fd that can be returned to the user.
+ * peeloff.sd[in] is used to transport flags
+ */
+ retval = get_unused_fd_flags(peeloff.sd);
if (retval < 0) {
sock_release(newsock);
goto out;
next prev parent reply other threads:[~2017-06-20 15:41 UTC|newest]
Thread overview: 18+ messages / expand[flat|nested] mbox.gz Atom feed top
2017-06-20 13:24 SCTP_SOCKOPT_PEELOFF is missing SOCK_CLOEXEC (and SOCK_NONBLOCK) Andreas Steinmetz
2017-06-20 14:39 ` Neil Horman
2017-06-20 15:41 ` Marcelo Ricardo Leitner [this message]
2017-06-20 18:14 ` Neil Horman
2017-06-20 18:56 ` Marcelo Ricardo Leitner
2017-06-20 19:00 ` Neil Horman
2017-06-20 19:21 ` Marcelo Ricardo Leitner
2017-06-21 10:13 ` Andreas Steinmetz
2017-06-21 12:27 ` Neil Horman
2017-06-21 18:53 ` Marcelo Ricardo Leitner
2017-06-22 1:53 ` Neil Horman
2017-06-23 19:14 ` Neil Horman
2017-06-23 19:33 ` Marcelo Ricardo Leitner
2017-06-25 12:06 ` Neil Horman
2017-06-26 9:57 ` Andreas Steinmetz
2017-06-26 17:44 ` Neil Horman
2017-06-28 13:12 ` Neil Horman
2017-06-29 17:33 ` Neil Horman
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=20170620154147.GA18138@localhost.localdomain \
--to=marcelo.leitner@gmail.com \
--cc=linux-sctp@vger.kernel.org \
/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.