AF_UNIX status report

Corinna Vinschen corinna-cygwin@cygwin.com
Fri Nov 6 09:12:40 GMT 2020


On Nov  5 18:41, Ken Brown via Cygwin-developers wrote:
> 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?

Maybe I'm overthinking this.  A typical scenario for SCM_RIGHTS
involves a privileged and an unprivileged process.  The privileged
process sends an fd to the unprivileged process.  In this case the
sending process has admin rights anyway and can duplicate the handles
into the receiving process without having to impersonate.

Either way, if both processes are running under the same user, or at
least one of the processes has admin rights, no impersonation is
required.  But since we don't know if the admin process is the sender or
the receiver, both sides must be capable of duplicating the handles.

So, only if both processes are unprivileged, we would need to
impersonate.  This will almost always fail, unless both processes have
been started from (for instance) the same ssh session or one of the user
accounts has the SeImpersonatePrivilege privilege.

Maybe we should just skip the latter scenario for a start.


Corinna


More information about the Cygwin-developers mailing list