AF_UNIX status report

Ken Brown kbrown@cornell.edu
Thu Nov 5 23:41:16 GMT 2020


On 11/5/2020 12:21 PM, Corinna Vinschen wrote:
> On Nov  5 09:23, Ken Brown via Cygwin-developers wrote:
>> OK, here's how I imagine this working:
>>
>> A process wants to send a file descriptor fd, so it creates a msghdr with an
>> SCM_RIGHTS cmsghdr and calls sendmsg.  The latter creates and sends an admin
>> packet A containing the fhandler for fd, and then it sends the original
>> packet P.
>>
>> At the receiving end, recvmsg sees packet A first (recvmsg is always
>> checking for admin packets anyway whenever it's called).  It stores the
>> fhandler somewhere.  When it then reads packet P, it retrieves the stored
>> fhandler, fiddles with it (duplicating handles, etc.), and creates the new
>> file descriptor.
> 
> Actually, this needs to be implemented in a source/dest-independent
> manner.  Only the server of the named pipe can impersonate the client.
> So the server side should do the job of duplicating the handles.  If the
> sever is also the source of SCM_RIGHTS, it should send the fhandler with
> already duplicated handles.

The only example of pipe client impersonation I can find in the Cygwin code is 
in fhandler_pty_master::pty_master_thread.  Is this a good model to follow?  If 
not, can you point me to other examples somewhere?

AFAICT, the only reason for the impersonation is to check that the client has 
appropriate permissions before trying to duplicate handles from the server 
process to the client process.  Is that right?  What would go wrong if we didn't 
check this?  Is the issue that the client process would have handles that it 
can't access?

Ken


More information about the Cygwin-developers mailing list