All of lore.kernel.org
 help / color / mirror / Atom feed
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: Wed, 21 Jun 2017 18:53:13 +0000	[thread overview]
Message-ID: <20170621185313.GG18138@localhost.localdomain> (raw)
In-Reply-To: <1497965053.10887.2.camel@domdv.de>

On Wed, Jun 21, 2017 at 08:27:14AM -0400, Neil Horman wrote:
> On Tue, Jun 20, 2017 at 04:21:45PM -0300, Marcelo Ricardo Leitner wrote:
> > On Tue, Jun 20, 2017 at 03:00:46PM -0400, Neil Horman wrote:
> > > On Tue, Jun 20, 2017 at 12:41:47PM -0300, Marcelo Ricardo Leitner wrote:
> > ...
> > > > 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)
> > > > 
> > > Thinking about this some more, I'm a bit hesitant to change the
> > > sctp_peeloff_arg_t, since thats exposed to user space.  Instead, what if we use
> > 
> > +1
> > 
> > > the sd value in the peeloff arg to fetch the close_on_exec flag in the new fd?
> > > Something like this (untested) patch:
> > 
> > Yes. :-) That's similar to what I proposed, though you used peeloff.sd
> > to find the old fd and copy the flag from it and I used it as a pure
> > 'flags' field instead.
> > 
> > I'm still not comfortable on hardwiring this copy. What if the
> > application doesn't want to inherit the flag?
> > accept() calls accept4(... , flags=0)
> > dup2() calls dup3(... , flags=0)
> > I don't see this direct inheritance anywhere else.
> > 
> I agree, but this strikes me as something of a unique situation.  In alternate
> cases of creating a new file descriptor within the same process as a clone of an
> existing fd, we have dup/dup2 and dup3, with the former having defined behavior
> of not copying the cloexec and nonblock flags, and the latter allowing them to
> be explicitly specified for the new fd.
> 
> 	In SCTP, we're creating a new fd, but have no express mechanism for
> defining the new flags.  We could, as you say, add a flags field to the
> peeloff_param_arg_t to provide that, but that has userspace ABI ramifications,
> and makes programs less portable.
> 
> 	Perhaps a new socket option SCTP_SOCKOPT_PEELOFF_FLAGS, and
> corresponding lksctp-tools library function sctp_peeloff_flags, which accepts
> the new fd's cloexec and nonblock flags as an argument?  That way at least, we
> could define the origional peeloff behavior as not copying the flags, and allow
> people to opt into the non-standard functions if they need it.  That would be in
> keeping with how dup/dup2/dup3 were developed.
> 
> Thoughts?
> Neil

That works for me.

We can't rely on using peeloff.sd to carry the flags because the
application may not have initialized it. It may be a variable in the
stack on which application simply did peeloff.asoc = X and we would be
working on unitialized data, so it's not safe.

On Andreas' idea to have a sctp_peeloff2_arg_t, it's also complicated
because the application is allowed to use a bigger-than-needed buffer
and in such cases it would lead us to the same situation as above.

So yes, I also think that the new SCTP_SOCKOPT_PEELOFF_FLAGS is the best
way out here.

Cheers,
Marcelo


  parent reply	other threads:[~2017-06-21 18:53 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
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 [this message]
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=20170621185313.GG18138@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.