From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from NAM02-SN1-obe.outbound.protection.outlook.com (mail-eopbgr770107.outbound.protection.outlook.com [40.107.77.107]) by sourceware.org (Postfix) with ESMTPS id 9D6BD3858023 for ; Sat, 7 Nov 2020 22:25:58 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.3.2 sourceware.org 9D6BD3858023 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=P0/JgqTysivjs4iWJ9dB6oytnSx58YRMhBVVwPAy7UO1JR/QjzJeIXGvTvQgInQabuQcnW/NY0j031oZtL38+iggF8g6Q09/86F50wuMPdIvl7ksjArdhtXT1UL43RQwmougq3U/TLodZJRvd53PYvjprviJ0ZUv+P5zJSZZtlIX3eGmRyMmt0xM1MifkEyrKCQvUuhJejQVpgDEBlWxcmGlaDYiNJemlGO7OUvoua0lFZh/GjSqerIHE/26+7frqCZa7assuHWeO0KHG0TMdHvVMb+puHO6PFYsCm5fL/PClHkmmEBwHdVGomlxODoHCYlCepBgTrnQN9UF4LNRLw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=OVk9eTWPc/0memS0oLKoqFyxSBZ1/bAm1+G4OqhcshU=; b=HowxJ5epzZllIYQ4iqqxcSyKWYWKDpxcbSr035THLq5nmxEp8s2vRUU8w1vOc4rXr+xIqRqFz5eZAJCWvDlaPN1nkDWE6OBdySHaCtZgG6LM2/pKeoD60fP1QNOJ14FT+09KKRbSeXPaONqRzZCm33XzFltSgNd9Tjt/+wdpn29d3O+rJPtunJ/vLFSBh6eYUOEwavKNthExGcMo5VhdMJrdoAZNV41OHceHhbF9kba/LQQ2XMbMSVZE26Yqw/tX2X69sLe9QyPXzTNoqDLNSeTNr3/0QDzwX076anASDeqoyTvQQjzMfP8yph4D+fqiWGAKlxGe8df10PSpJlEcKw== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=cornell.edu; dmarc=pass action=none header.from=cornell.edu; dkim=pass header.d=cornell.edu; arc=none Received: from MN2PR04MB6176.namprd04.prod.outlook.com (2603:10b6:208:e3::13) by MN2PR04MB6158.namprd04.prod.outlook.com (2603:10b6:208:d9::14) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3541.22; Sat, 7 Nov 2020 22:25:56 +0000 Received: from MN2PR04MB6176.namprd04.prod.outlook.com ([fe80::113e:c874:1207:eca8]) by MN2PR04MB6176.namprd04.prod.outlook.com ([fe80::113e:c874:1207:eca8%6]) with mapi id 15.20.3541.021; Sat, 7 Nov 2020 22:25:55 +0000 Subject: Re: AF_UNIX status report To: cygwin-developers@cygwin.com References: <1d0ea5dc-7e9b-d8fe-5f6e-da7a799a3b13@cornell.edu> <20201027094340.GJ5492@calimero.vinschen.de> <0f945b4c-aa30-e08e-9f86-d4b41279ba10@pismotec.com> <20201030092019.GW5492@calimero.vinschen.de> <38e33f7a-e87d-fea8-ac9e-826f94c189d4@cornell.edu> <20201104120304.GF33165@calimero.vinschen.de> <88b3dfe6-a67d-c597-afe2-4edb13cee5d7@cornell.edu> <20201105172140.GP33165@calimero.vinschen.de> <80cb96b8-065d-b146-b879-170031ba28b5@cornell.edu> <20201106091240.GT33165@calimero.vinschen.de> From: Ken Brown Message-ID: Date: Sat, 7 Nov 2020 17:25:12 -0500 User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:78.0) Gecko/20100101 Thunderbird/78.4.1 In-Reply-To: <20201106091240.GT33165@calimero.vinschen.de> Content-Type: text/plain; charset=windows-1252; format=flowed Content-Language: en-US Content-Transfer-Encoding: 7bit X-Originating-IP: [68.175.129.7] X-ClientProxiedBy: CH2PR02CA0005.namprd02.prod.outlook.com (2603:10b6:610:4e::15) To MN2PR04MB6176.namprd04.prod.outlook.com (2603:10b6:208:e3::13) MIME-Version: 1.0 X-MS-Exchange-MessageSentRepresentingType: 1 Received: from [192.168.0.17] (68.175.129.7) by CH2PR02CA0005.namprd02.prod.outlook.com (2603:10b6:610:4e::15) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3541.21 via Frontend Transport; Sat, 7 Nov 2020 22:25:55 +0000 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: f29171f4-ef9a-455f-b5f3-08d8836c180e X-MS-TrafficTypeDiagnostic: MN2PR04MB6158: X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:8882; X-MS-Exchange-SenderADCheck: 1 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: 1n9Klkd5Oyl8k56NWomwo6f+78eZs2lFHDLZPqVkpaJLyt3K9qM4wVSC1cWq95RtTuKK/95QyYnYbRdGlwvWp5O3P0VRrX6O25zusTPcXuRZVLhW7FGMtb2iH5KkIOuKEIqPYp1aGO7POAItO87F0RT5kK1/d/zgLkRl6bJx/uH0BuNAwRxno0ODq8Qhx6PP9h0CXj4s2gNcwuFLQET/iAgrkImYqNC9p7UuRps8lhJd3s8cIKnzpG0qkcMMhtZPN27I+n4uybIzvf8vxrx4xFKkPAK5/WPi+WWmoGqOQiturnm7p3cQ4mzsf55wtxZ62LlcMOgrXawZR8hParelyc/Ym35EmjedwVHY1oAEW9fUzpuU9hwcKGAt5s9CUqTq X-Forefront-Antispam-Report: CIP:255.255.255.255; CTRY:; LANG:en; SCL:1; SRV:; IPV:NLI; SFV:NSPM; H:MN2PR04MB6176.namprd04.prod.outlook.com; PTR:; CAT:NONE; SFS:(4636009)(39860400002)(136003)(366004)(346002)(376002)(396003)(6666004)(66946007)(52116002)(83380400001)(956004)(2616005)(86362001)(16526019)(186003)(53546011)(75432002)(31686004)(26005)(31696002)(6486002)(8676002)(8936002)(5660300002)(2906002)(786003)(316002)(36756003)(16576012)(7116003)(6916009)(478600001)(66476007)(66556008)(43740500002); DIR:OUT; SFP:1102; X-MS-Exchange-AntiSpam-MessageData: 2PrEQm0EpMDfV5rw81NBOr/1eNgR+E4AwiM39yd/sqUtz//s8t+mFi/LyAEZizmmTdIpSKz0Q2C5s346gPxUvvfUkJyreu/3JFIBINjuPMvd+AnLP2XFnCPZIvuktCyL+EzTpL1JDdQkEPwOlszMIIg0lh28xaXRMJq0588oeAaPWxABMUCsSpl3xnj/7acOaYWF28Ao3cXnR4Mizp9HWo0/nQ7uczc2rG1QA1l840LQoIeWSir8GeDl635iF2qCXPd+8H5mYsmdX4BpLv4cxJVEVgR1Vy5GFvG8Sf8jA5DBmkOvFh2H5ic1ZjHS/0sHR8hXJ+dsrFFEKwwcmDnPA9WQAWZ5teTpUm9emT2NBkZfVpANEszZGz9d4LsX5VlHRVZosTAqGiRZagjqorXQpIwCq2Tw2J3xxZM+CC7RxZUQUjIygKYpV15aYlQjcwVtS2uIXMX3cT4Aej5PLpknoVGotB91CfeauFNZ7y2300RfyDemTanu2V+yUpGu/9P6RcbkIkvYi9KmBV5z8bxVSWaaLn3VhsXDZ2Ha5f5gqWm6E2ZOzxOFBI2Qsr9X3iTXmXXEn/kHYhWw2Jd0NdXQmXjU0zi7pWO1wAcgH1HkJPfCScdgzS3JF5BgwEoHuXMUaNZK6Eb2XnvMdkAyCkn4IA== X-OriginatorOrg: cornell.edu X-MS-Exchange-CrossTenant-Network-Message-Id: f29171f4-ef9a-455f-b5f3-08d8836c180e X-MS-Exchange-CrossTenant-AuthSource: MN2PR04MB6176.namprd04.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 07 Nov 2020 22:25:55.8197 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 5d7e4366-1b9b-45cf-8e79-b14b27df46e1 X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: fy7LcgvJbRufZPqPnZWu6tfJJbzbzFVDmDdGHj7wjFNM7ckw9es0ooZ/eabP7xUWKS1QFATWNjR5iA9OzvA53Q== X-MS-Exchange-Transport-CrossTenantHeadersStamped: MN2PR04MB6158 X-Spam-Status: No, score=-4.7 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, MSGID_FROM_MTA_HEADER, NICE_REPLY_A, RCVD_IN_DNSWL_LOW, RCVD_IN_MSPIKE_H2, SPF_HELO_PASS, SPF_PASS, TXREP autolearn=ham autolearn_force=no version=3.4.2 X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on server2.sourceware.org X-BeenThere: cygwin-developers@cygwin.com X-Mailman-Version: 2.1.29 Precedence: list List-Id: Cygwin core component developers mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sat, 07 Nov 2020 22:26:00 -0000 On 11/6/2020 4:12 AM, Corinna Vinschen wrote: > 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. Good! That way I don't have to get sidetracked learning about impersonation. Here's another issue involving serialization. I'm not sure it's enough to just fiddle with the handles and then send the fhandler. We also need to send the strings that are in the path_conv member of the fhandler. [I just noticed that you added path_conv serialization/deserialization recently, which should help with this.] This increases the size of the data to the point where I think we need to send more than one packet when we're sending SCM_RIGHTS. Alternatively, instead of trying to send the fhandler and string(s) over the socket, we could store a copy of the fhandler, along with the serialized pc, in a named shared memory block. The name could be something like "scm_rights...". Then the sender would only have to send the device and inode, and the receiver could open the shared memory and reconstruct everything. WDYT? Ken