public inbox for cygwin-patches@cygwin.com
 help / color / mirror / Atom feed
* [PATCH] Cygwin: Allow to set SO_PEERCRED zero (v2)
@ 2020-12-07 10:29 Mark Geisert
  2020-12-07 15:30 ` Corinna Vinschen
  0 siblings, 1 reply; 6+ messages in thread
From: Mark Geisert @ 2020-12-07 10:29 UTC (permalink / raw)
  To: cygwin-patches

The existing code errors as EINVAL any attempt to set a value for
SO_PEERCRED via setsockopt() on an AF_UNIX/AF_LOCAL socket.  But to
enable the workaround set_no_getpeereid behavior for Python one has
to be able to set SO_PEERCRED to zero.  Ergo, this patch.  Python has
no way to specify a NULL pointer for 'optval'.

This v2 of patch allows the original working (i.e., allow NULL,0 for
optval,optlen to mean turn off SO_PEERCRED) in addition to the new
working described above.  The sense of the 'if' stmt is reversed for
readability.

---
 winsup/cygwin/fhandler_socket_local.cc | 10 +++++++---
 1 file changed, 7 insertions(+), 3 deletions(-)

diff --git a/winsup/cygwin/fhandler_socket_local.cc b/winsup/cygwin/fhandler_socket_local.cc
index c94bf828f..964f3e819 100644
--- a/winsup/cygwin/fhandler_socket_local.cc
+++ b/winsup/cygwin/fhandler_socket_local.cc
@@ -1430,10 +1430,14 @@ fhandler_socket_local::setsockopt (int level, int optname, const void *optval,
 	     FIXME: In the long run we should find a more generic solution
 	     which doesn't require a blocking handshake in accept/connect
 	     to exchange SO_PEERCRED credentials. */
-	  if (optval || optlen)
-	    set_errno (EINVAL);
-	  else
+	  /* Temporary: Allow SO_PEERCRED to only be zeroed. Two ways to
+	     accomplish this: pass NULL,0 for optval,optlen; or pass the
+	     address,length of an '(int) 0' set up by the caller. */
+	  if ((!optval && !optlen) ||
+		(optlen == (socklen_t) sizeof (int) && !*(int *) optval))
 	    ret = af_local_set_no_getpeereid ();
+	  else
+	    set_errno (EINVAL);
 	  return ret;
 
 	case SO_REUSEADDR:
-- 
2.29.2


^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [PATCH] Cygwin: Allow to set SO_PEERCRED zero (v2)
  2020-12-07 10:29 [PATCH] Cygwin: Allow to set SO_PEERCRED zero (v2) Mark Geisert
@ 2020-12-07 15:30 ` Corinna Vinschen
  2020-12-07 15:35   ` Corinna Vinschen
  0 siblings, 1 reply; 6+ messages in thread
From: Corinna Vinschen @ 2020-12-07 15:30 UTC (permalink / raw)
  To: cygwin-patches

On Dec  7 02:29, Mark Geisert wrote:
> The existing code errors as EINVAL any attempt to set a value for
> SO_PEERCRED via setsockopt() on an AF_UNIX/AF_LOCAL socket.  But to
> enable the workaround set_no_getpeereid behavior for Python one has
> to be able to set SO_PEERCRED to zero.  Ergo, this patch.  Python has
> no way to specify a NULL pointer for 'optval'.
> 
> This v2 of patch allows the original working (i.e., allow NULL,0 for
> optval,optlen to mean turn off SO_PEERCRED) in addition to the new
> working described above.  The sense of the 'if' stmt is reversed for
> readability.
> 
> ---
>  winsup/cygwin/fhandler_socket_local.cc | 10 +++++++---
>  1 file changed, 7 insertions(+), 3 deletions(-)
> 
> diff --git a/winsup/cygwin/fhandler_socket_local.cc b/winsup/cygwin/fhandler_socket_local.cc
> index c94bf828f..964f3e819 100644
> --- a/winsup/cygwin/fhandler_socket_local.cc
> +++ b/winsup/cygwin/fhandler_socket_local.cc
> @@ -1430,10 +1430,14 @@ fhandler_socket_local::setsockopt (int level, int optname, const void *optval,
>  	     FIXME: In the long run we should find a more generic solution
>  	     which doesn't require a blocking handshake in accept/connect
>  	     to exchange SO_PEERCRED credentials. */
> -	  if (optval || optlen)
> -	    set_errno (EINVAL);
> -	  else
> +	  /* Temporary: Allow SO_PEERCRED to only be zeroed. Two ways to
> +	     accomplish this: pass NULL,0 for optval,optlen; or pass the
> +	     address,length of an '(int) 0' set up by the caller. */
> +	  if ((!optval && !optlen) ||
> +		(optlen == (socklen_t) sizeof (int) && !*(int *) optval))
>  	    ret = af_local_set_no_getpeereid ();
> +	  else
> +	    set_errno (EINVAL);
>  	  return ret;
>  
>  	case SO_REUSEADDR:
> -- 
> 2.29.2

Pushed


Thanks,
Corinna

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [PATCH] Cygwin: Allow to set SO_PEERCRED zero (v2)
  2020-12-07 15:30 ` Corinna Vinschen
@ 2020-12-07 15:35   ` Corinna Vinschen
  2020-12-08  3:25     ` Mark Geisert
  0 siblings, 1 reply; 6+ messages in thread
From: Corinna Vinschen @ 2020-12-07 15:35 UTC (permalink / raw)
  To: cygwin-patches

On Dec  7 16:30, Corinna Vinschen via Cygwin-patches wrote:
> On Dec  7 02:29, Mark Geisert wrote:
> > The existing code errors as EINVAL any attempt to set a value for
> > SO_PEERCRED via setsockopt() on an AF_UNIX/AF_LOCAL socket.  But to
> > enable the workaround set_no_getpeereid behavior for Python one has
> > to be able to set SO_PEERCRED to zero.  Ergo, this patch.  Python has
> > no way to specify a NULL pointer for 'optval'.
> > 
> > This v2 of patch allows the original working (i.e., allow NULL,0 for
> > optval,optlen to mean turn off SO_PEERCRED) in addition to the new
> > working described above.  The sense of the 'if' stmt is reversed for
> > readability.
> > 
> > ---
> >  winsup/cygwin/fhandler_socket_local.cc | 10 +++++++---
> >  1 file changed, 7 insertions(+), 3 deletions(-)
> > 
> > diff --git a/winsup/cygwin/fhandler_socket_local.cc b/winsup/cygwin/fhandler_socket_local.cc
> > index c94bf828f..964f3e819 100644
> > --- a/winsup/cygwin/fhandler_socket_local.cc
> > +++ b/winsup/cygwin/fhandler_socket_local.cc
> > @@ -1430,10 +1430,14 @@ fhandler_socket_local::setsockopt (int level, int optname, const void *optval,
> >  	     FIXME: In the long run we should find a more generic solution
> >  	     which doesn't require a blocking handshake in accept/connect
> >  	     to exchange SO_PEERCRED credentials. */
> > -	  if (optval || optlen)
> > -	    set_errno (EINVAL);
> > -	  else
> > +	  /* Temporary: Allow SO_PEERCRED to only be zeroed. Two ways to
> > +	     accomplish this: pass NULL,0 for optval,optlen; or pass the
> > +	     address,length of an '(int) 0' set up by the caller. */
> > +	  if ((!optval && !optlen) ||
> > +		(optlen == (socklen_t) sizeof (int) && !*(int *) optval))
> >  	    ret = af_local_set_no_getpeereid ();
> > +	  else
> > +	    set_errno (EINVAL);
> >  	  return ret;
> >  
> >  	case SO_REUSEADDR:
> > -- 
> > 2.29.2
> 
> Pushed

I created new developer snapshots for testing.


Corinna

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [PATCH] Cygwin: Allow to set SO_PEERCRED zero (v2)
  2020-12-07 15:35   ` Corinna Vinschen
@ 2020-12-08  3:25     ` Mark Geisert
  2020-12-08  9:47       ` Corinna Vinschen
  0 siblings, 1 reply; 6+ messages in thread
From: Mark Geisert @ 2020-12-08  3:25 UTC (permalink / raw)
  To: cygwin-patches

Hi Corinna,

Corinna Vinschen via Cygwin-patches wrote:
> On Dec  7 16:30, Corinna Vinschen via Cygwin-patches wrote:
>> On Dec  7 02:29, Mark Geisert wrote:
>>> The existing code errors as EINVAL any attempt to set a value for
>>> SO_PEERCRED via setsockopt() on an AF_UNIX/AF_LOCAL socket.  But to
>>> enable the workaround set_no_getpeereid behavior for Python one has
>>> to be able to set SO_PEERCRED to zero.  Ergo, this patch.  Python has
>>> no way to specify a NULL pointer for 'optval'.
>>>
>>> This v2 of patch allows the original working (i.e., allow NULL,0 for
>>> optval,optlen to mean turn off SO_PEERCRED) in addition to the new
>>> working described above.  The sense of the 'if' stmt is reversed for
>>> readability.
>>>
>>> ---
[...]
>>> -- 
>>> 2.29.2
>>
>> Pushed
> 
> I created new developer snapshots for testing.

I didn't phrase my comment somewhere about "future snapshot TBA" as I had 
intended.  I just meant some future snapshot, not that I was requesting one for 
this patch.  But thank you very much anyway.  I'll sort out with Marco whether the 
Python end of the OP's issue patch should go into pythonX.X-test or pythonX.X 
itself, separately.  BTW The whole set of Python tests might serve to test Cygwin 
in a manner we haven't seen|used yet...
Cheers,

..mark

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [PATCH] Cygwin: Allow to set SO_PEERCRED zero (v2)
  2020-12-08  3:25     ` Mark Geisert
@ 2020-12-08  9:47       ` Corinna Vinschen
  2020-12-08  9:53         ` Corinna Vinschen
  0 siblings, 1 reply; 6+ messages in thread
From: Corinna Vinschen @ 2020-12-08  9:47 UTC (permalink / raw)
  To: cygwin-patches

Hi Mark,

On Dec  7 19:25, Mark Geisert wrote:
> Hi Corinna,
> 
> Corinna Vinschen via Cygwin-patches wrote:
> > On Dec  7 16:30, Corinna Vinschen via Cygwin-patches wrote:
> > > On Dec  7 02:29, Mark Geisert wrote:
> > > > The existing code errors as EINVAL any attempt to set a value for
> > > > SO_PEERCRED via setsockopt() on an AF_UNIX/AF_LOCAL socket.  But to
> > > > enable the workaround set_no_getpeereid behavior for Python one has
> > > > to be able to set SO_PEERCRED to zero.  Ergo, this patch.  Python has
> > > > no way to specify a NULL pointer for 'optval'.
> > > > 
> > > > This v2 of patch allows the original working (i.e., allow NULL,0 for
> > > > optval,optlen to mean turn off SO_PEERCRED) in addition to the new
> > > > working described above.  The sense of the 'if' stmt is reversed for
> > > > readability.
> > > > 
> > > > ---
> [...]
> > > > -- 
> > > > 2.29.2
> > > 
> > > Pushed
> > 
> > I created new developer snapshots for testing.
> 
> I didn't phrase my comment somewhere about "future snapshot TBA" as I had
> intended.  I just meant some future snapshot, not that I was requesting one
> for this patch.  But thank you very much anyway.

I freely admit I didn't actually read your comment :}

I just created this snapshot because it seemed useful, so all is well :)


Corinna

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [PATCH] Cygwin: Allow to set SO_PEERCRED zero (v2)
  2020-12-08  9:47       ` Corinna Vinschen
@ 2020-12-08  9:53         ` Corinna Vinschen
  0 siblings, 0 replies; 6+ messages in thread
From: Corinna Vinschen @ 2020-12-08  9:53 UTC (permalink / raw)
  To: cygwin-patches

On Dec  8 10:47, Corinna Vinschen via Cygwin-patches wrote:
> Hi Mark,
> 
> On Dec  7 19:25, Mark Geisert wrote:
> > Hi Corinna,
> > 
> > Corinna Vinschen via Cygwin-patches wrote:
> > > On Dec  7 16:30, Corinna Vinschen via Cygwin-patches wrote:
> > > > On Dec  7 02:29, Mark Geisert wrote:
> > > > > The existing code errors as EINVAL any attempt to set a value for
> > > > > SO_PEERCRED via setsockopt() on an AF_UNIX/AF_LOCAL socket.  But to
> > > > > enable the workaround set_no_getpeereid behavior for Python one has
> > > > > to be able to set SO_PEERCRED to zero.  Ergo, this patch.  Python has
> > > > > no way to specify a NULL pointer for 'optval'.
> > > > > 
> > > > > This v2 of patch allows the original working (i.e., allow NULL,0 for
> > > > > optval,optlen to mean turn off SO_PEERCRED) in addition to the new
> > > > > working described above.  The sense of the 'if' stmt is reversed for
> > > > > readability.
> > > > > 
> > > > > ---
> > [...]
> > > > > -- 
> > > > > 2.29.2
> > > > 
> > > > Pushed
> > > 
> > > I created new developer snapshots for testing.
> > 
> > I didn't phrase my comment somewhere about "future snapshot TBA" as I had
> > intended.  I just meant some future snapshot, not that I was requesting one
> > for this patch.  But thank you very much anyway.
> 
> I freely admit I didn't actually read your comment :}

...the part talking about a future snapshot, that is...

> 
> I just created this snapshot because it seemed useful, so all is well :)
> 
> 
> Corinna

^ permalink raw reply	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2020-12-08  9:53 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-12-07 10:29 [PATCH] Cygwin: Allow to set SO_PEERCRED zero (v2) Mark Geisert
2020-12-07 15:30 ` Corinna Vinschen
2020-12-07 15:35   ` Corinna Vinschen
2020-12-08  3:25     ` Mark Geisert
2020-12-08  9:47       ` Corinna Vinschen
2020-12-08  9:53         ` Corinna Vinschen

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).