Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:96827 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 81149 invoked from network); 11 Nov 2016 07:31:10 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 11 Nov 2016 07:31:10 -0000 Authentication-Results: pb1.pair.com header.from=dmitry@zend.com; sender-id=pass Authentication-Results: pb1.pair.com smtp.mail=dmitry@zend.com; spf=pass; sender-id=pass Received-SPF: pass (pb1.pair.com: domain zend.com designates 104.47.33.108 as permitted sender) X-PHP-List-Original-Sender: dmitry@zend.com X-Host-Fingerprint: 104.47.33.108 mail-bn3nam01on0108.outbound.protection.outlook.com Received: from [104.47.33.108] ([104.47.33.108:6080] helo=NAM01-BN3-obe.outbound.protection.outlook.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id 7F/75-35596-CB375285 for ; Fri, 11 Nov 2016 02:31:09 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=RWSoftware.onmicrosoft.com; s=selector1-zend-com; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version; bh=wsqwTcHI7WdVQHS866Km4K6JF4jU0JavUbM5xWwCPzE=; b=iy8w4wKfGMy1uFf2rZ6TIFLS3Luzfmgx/KA0GiarA0TSVaREF5vrrSRNMabobPbWLjuNX3tNxGtQM1m0awdyZ5dAOBy7+d2Dx4FtRIPbRfzLI/7i+rgR4GaZjBIq7NRhyxvHjZN75LM2Eun8QWwETV0/ocCeGZOVbHUQ4qyNc5k= Received: from MWHPR02MB2477.namprd02.prod.outlook.com (10.168.204.147) by MWHPR02MB2478.namprd02.prod.outlook.com (10.168.204.148) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384_P384) id 15.1.659.11; Fri, 11 Nov 2016 07:31:03 +0000 Received: from MWHPR02MB2477.namprd02.prod.outlook.com ([10.168.204.147]) by MWHPR02MB2477.namprd02.prod.outlook.com ([10.168.204.147]) with mapi id 15.01.0659.035; Fri, 11 Nov 2016 07:31:03 +0000 To: "php-dev@coydogsoftware.net" CC: Dmitry Stogov , "rasmus@lerdorf.com" , "internals@lists.php.net" , "Anatol Belski (ab@php.net)" , Zeev Suraski Thread-Topic: [PATCH] opcache bug #69090, prepend user identifier to keys Thread-Index: AQHSO+UMD4h3upkAiEqzeDgxtnu8Qg== Date: Fri, 11 Nov 2016 07:31:03 +0000 Message-ID: Accept-Language: en-US Content-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: authentication-results: spf=none (sender IP is ) smtp.mailfrom=dmitry@zend.com; x-originating-ip: [92.62.57.172] x-microsoft-exchange-diagnostics: 1;MWHPR02MB2478;6:WJBBUyXF0AVbiDQO84Y0Yt+wA6ttelxU9n46I9xwx1bTJl5RsIxosvWbPjiUag/L4qHu8jt1oZVkLB+5Kml3aV9Omb3Lb8mluWaJIFMYTnxB8BrbQpxNzBI8ad3xvgTr29jCGltYHUFvqQzJ2NIhx6eBab6GPWn/IGKkGto54qLJ3XtL9Rstp11QCHtc/d7uDJ+Ve8NYIHCKbT/55w/eO66tH3kJCLUDDKojryh01nzF0OUqNSHDNNODvZArU3Jlm11t+fCdaO+/1gsE5lgaIdXNkx3Z9mFPpghkbbwyIEEWDAwO/2Pbftl6+y0yfJJn;5:zGgu3IZxMZmfFtwkP5jspyao2CxbHTs18ARW1QXz8QnVPasuo6hxNz7wKx51hjkxlpEiuzNJfCqoCknZKO7LdSFBb1dPLi3P69vpqVL4EOjNAVYZh6O4KiIysl0P5sIyEXhPr8uM7/8YmDVczNnv2A==;24:P7ajkmivefqz8Sslj9ekUd0W2R6IQmcuGih7EJhmWy0inl3wiKtx/iXqZvL2Ze5y1+CYAAUUesdxJffjMy70BOgMyi4Qg7g1/CWWQWtF3D8=;7:8EHRHbcQu8WHSvJPl8yqx+E6RkEb8J3L7ui2Qyas/yF2W1DC8MWeUy1X+hxZvaxUc+MrLv90jmA8NsvBtDiacXjAZ8bj1A8j9ZVaCccyPbRF3D5OtYydGI67XD7hmv/g/zbMrLUzn7ealyx3iLfevfbKuO/schPI4apw0a2rX01m0MH8F6OFv8jlGXSZjkJBN1w4dReDmPlYvrpOiXjNPDU4jpV4Q8CZ8E1DvvcGaFBnpA/YYTP7YGrQsDtCdh8lLVKLwfCNxqHb6hjQnF/VvZSBPJbGfJyN7omc8YTVxhYdS2hI9/k4iiTHI6gen7FtYuK+JQvyrei9zh3GdFTxb7bqdGjUDzLr4yjujKUxOAo= x-ms-office365-filtering-correlation-id: 79241a70-2867-4ca4-c7eb-08d40a04b16e x-microsoft-antispam: UriScan:;BCL:0;PCL:0;RULEID:(22001);SRVR:MWHPR02MB2478; x-microsoft-antispam-prvs: x-exchange-antispam-report-test: UriScan:(192374486261705); x-exchange-antispam-report-cfa-test: BCL:0;PCL:0;RULEID:(6040176)(601004)(2401047)(8121501046)(5005006)(3002001)(10201501046);SRVR:MWHPR02MB2478;BCL:0;PCL:0;RULEID:;SRVR:MWHPR02MB2478; x-forefront-prvs: 012349AD1C x-forefront-antispam-report: SFV:NSPM;SFS:(10019020)(6009001)(7916002)(189002)(377454003)(199003)(51414003)(24454002)(92566002)(106356001)(77096005)(68736007)(99286002)(74316002)(106116001)(5660300001)(3660700001)(105586002)(6116002)(9686002)(3280700002)(101416001)(102836003)(586003)(3846002)(86362001)(4326007)(81156014)(2906002)(2351001)(81166006)(345774005)(8676002)(110136003)(33656002)(4001430100002)(7736002)(305945005)(5640700001)(7696004)(7846002)(107886002)(87936001)(2501003)(189998001)(8936002)(6916009)(122556002)(66066001)(229853002)(76576001)(97736004)(2900100001)(50986999)(54356999);DIR:OUT;SFP:1102;SCL:1;SRVR:MWHPR02MB2478;H:MWHPR02MB2477.namprd02.prod.outlook.com;FPR:;SPF:None;PTR:InfoNoRecords;MX:1;A:1;LANG:en; received-spf: None (protection.outlook.com: zend.com does not designate permitted sender hosts) spamdiagnosticoutput: 1:99 spamdiagnosticmetadata: NSPM Content-Type: multipart/alternative; boundary="_000_MWHPR02MB247797DCC52957382A6E120BBFBB0MWHPR02MB2477namp_" MIME-Version: 1.0 X-OriginatorOrg: zend.com X-MS-Exchange-CrossTenant-originalarrivaltime: 11 Nov 2016 07:31:03.5674 (UTC) X-MS-Exchange-CrossTenant-fromentityheader: Hosted X-MS-Exchange-CrossTenant-id: 32210298-c08b-4829-8097-6b12c025a892 X-MS-Exchange-Transport-CrossTenantHeadersStamped: MWHPR02MB2478 Subject: Re: [PATCH] opcache bug #69090, prepend user identifier to keys From: dmitry@zend.com (Dmitry Stogov) --_000_MWHPR02MB247797DCC52957382A6E120BBFBB0MWHPR02MB2477namp_ Content-Type: text/plain; charset="koi8-r" Content-Transfer-Encoding: quoted-printable Hi, On Nov 10, 2016 5:10 PM, php-dev@coydogsoftware.net wrote: > > Hello, > > Thank you for the response. Replies inline: > > On Thu, Nov 10, 2016 at 08:51:58AM +0000, Dmitry Stogov wrote: > > > > I see the problem(s) and I took a look into the patch. > > Can you confirm that you see the permissions bypass problem? I've seen > the chroot filename collision problem acknowledged in the bugtracker and > in old php-internals posts, but I've seen nobody from the PHP Project > explicitly acknowledge the permissions bypass vulnerability. If my > meaning isn't clear I can provide proof of concept off-list. The > permissions bypass affects both apache2handler (even with mod_ruid2) and > FPM (even with user pools). I didn't see the problem in real life, but it's clear, that serving of few = chroot environments using the same cache may lead to duplicate keys. FPM wi= th separate pools shouldn't be affected. > > They're separate problems both stemming from the simple filename design > of the cache keys. > > > From the first look, I don't like the proposed solution. > > > > It makes things a bit better, but can't solve shared-hosting > > configuration problems. > > I'll be the first to agree it's not perfect; it's a band-aid from > someone with no prior familiarity with the codebase. I was just > surprised a trivially exploitable security hole like this was unpatched > for 2+ years and thought I would take a stab at a quick solution. Can > you elaborate on what shared-hosting problems it doesn't solve (aside > from chroot name collisions)? Serving different users by the same process opens a lot of ways to stole da= ta (sessions, persistent caches, persistent conections, dirty memory, etc). They should be served by different FPM pools or separate Apache processes. > > > It doesn't solve even the simple chroot file resolution problem in > > general (one user ma have few chroot environments with conflicting > > file names). > > Agreed. Putting device+inode in the key would properly fix the chroot > scenario, but wouldn't the inode be readable if the parent directory is > readable? This could result in unexpected behaviour; ie a script > belonging to user alice, readable only by alice, can be run by user bob > if the parent directory is readable. > > Plus there's the performance considerations of stat(); I know better > than to put the stat() call in the hot function. Apparently APC used a > stat struct passed from the SAPI? But how did this work with > included/required scripts which the SAPI wasn't aware of; were they all > cached under the parent script's key? I've skimmed that code in APC but > didn't have time for proper analysis. I admit ignorance here and thus I > preferred to leave dev+inode keying to the experts. Yeah, inode is not an exelent solution as well. > I still strongly believe a user identifier is needed in addition to > dev+inode due to the permissions bypass issue. Opcache just wasn't designed to solve permission problems in shared hosting= evvironment. "user id prefix", looks for me like a quick hack, that doesn't solve the wh= ole problem anyway. > > > I'm not sure, if it's possible to make chroot on Windows, so why we > > need to add windows user names? > > Frankly I don't know if any Windows configurations are vulnerable. I > have no experience with the Windows SAPI's. I didn't want to break the > Windows build, and wanted to keep the functionality analagous between > Windows and other platforms rather than leaving a possibly exploitable > design on Windows. > > But again I should stress that *chroot filename collisions are not the > only bad behavior here.* They're not the bug I'm most concerned with. Do you talk about executing "unreadable" PHP scripts of different users? I think, the proper way to fix this, whould executing access() check on eac= h cached script access (this might be enabled/disabled through php.ini) > > > The patch introduces syscall in the hot function (this may be > > optimized). > > Agreed. That isn't ideal. But the geteuid() call shouldn't be done > during opcache initialization when the SHM object is initialized, > because EUID might change afterwards. I didn't want to get EUID too > early so I erred on the side of caution, getting it at the last possible > moment. This is slower but safer because it prevents trivial cross-user > cache access from PHP userland. I'm open to suggestion if there's a more > "local" initialization function outside of key generation, which is > guaranteed to run after EUID changes in both FPM user pool, and > mod_ruid2/mod_php. RINIT > > > I'm open for discussion and may change my mind. I'll also try to find > > a better solution. Any suggestions are welcome. > > Frankly I think the better solution for FPM, would be to avoid doing > OPCache SHM object initialization in the FPM master before user pools > have forked and set EUID. That would fix both the permissions bypass and > probably key collisions in chroots. Let me check this. >. mod_fcgid didn't have these problems > because PHP parent processes were started independently for each vhost. > > I'm not familiar enough with FPM code (yet) to be more specific, and I > don't like the fact that this doesn't doesn't address permissions bypass > with mod_php/mod_ruid2 which is a popular configuration which people > *think* is safe for shared hosting. > > Ideally I'd like to see OPCache keys fixed with a user identifier and > dev+inode, *and* FPM fixed as described above :). > > Thank you again for taking time to comment. I look forward to your > thoughts. Shall I send proof of concept for the permissions bypass, > off-list? Let methink a bit more. Thanks. Dmitry. > -- > - php-dev@coydogsoftware.net --_000_MWHPR02MB247797DCC52957382A6E120BBFBB0MWHPR02MB2477namp_--