From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1750854AbdE0Rpr (ORCPT ); Sat, 27 May 2017 13:45:47 -0400 Received: from us-smtp-delivery-194.mimecast.com ([63.128.21.194]:54748 "EHLO us-smtp-delivery-194.mimecast.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1750745AbdE0Rpo (ORCPT ); Sat, 27 May 2017 13:45:44 -0400 From: Trond Myklebust To: "ebiederm@xmission.com" , "dhowells@redhat.com" CC: "linux-kernel@vger.kernel.org" , "jlayton@redhat.com" , "cgroups@vger.kernel.org" , "mszeredi@redhat.com" , "linux-nfs@vger.kernel.org" , "linux-fsdevel@vger.kernel.org" , "viro@zeniv.linux.org.uk" Subject: Re: [RFC][PATCH 0/9] Make containers kernel objects Thread-Topic: [RFC][PATCH 0/9] Make containers kernel objects Thread-Index: AQHS0xefosWwyWuedkyrB5HH23hhZqIAuAmIgAfD2gA= Date: Sat, 27 May 2017 17:45:35 +0000 Message-ID: <1495907132.4591.3.camel@primarydata.com> References: <149547014649.10599.12025037906646164347.stgit@warthog.procyon.org.uk> <87lgpoww67.fsf@xmission.com> In-Reply-To: <87lgpoww67.fsf@xmission.com> Accept-Language: en-US Content-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: x-originating-ip: [68.49.162.121] x-ms-publictraffictype: Email x-microsoft-exchange-diagnostics: 1;MWHPR11MB1357;7:vUbglgsiObR4qI+8DrSQdfZqgPxIzLFFAiCZfarl5y+2OMLnFrKhpVyLX/ORnSMnKpnLPyTw/xcx0Lw+IuwcSicq0qyRrT+GdLgJq82yXnFG5nawwBXD1bSZNiJJj/KZCzKF6wNwCZlJF4JZQ3lyOuJZWLo/r7lTgQTXLz5FpqWEDY+sIRzRvZeQ5dC5G74T78oMubxrR4M6qp1m7qI2eWIlFW6emiBJzVVl0Re51I6YWpAvdSjKBVYKcGu+mPQ/uCf5FQr4ghhupizmjNIKyCQUCjEwG+rJLFgtLvSuB+vu/CreVI30XY5B7ziWLtuQYrSC547YASPn7FaEMumbFw==;20:EtRTG7VlVVIts5k21DUbRbkOnKXIUsmi74nSvBaN7kkXvRZkZ2yQ7D4Ugi1Fik0obFvPzjMVAFzMLizhQ30K7w2/Y6NQYVK9P5IEONx7JmFIje5ZewbTz07fH9L6lrknLQX1iaDpLu4s1uako9b+wC6FNN20HkzGEFNG6dNeCiQ= x-ms-traffictypediagnostic: MWHPR11MB1357: x-ms-office365-filtering-correlation-id: 64610476-d193-4795-60d9-08d4a5282e48 x-microsoft-antispam: UriScan:;BCL:0;PCL:0;RULEID:(22001)(2017030254075)(201703131423075);SRVR:MWHPR11MB1357; x-microsoft-antispam-prvs: x-exchange-antispam-report-test: UriScan:(192374486261705)(17755550239193); x-exchange-antispam-report-cfa-test: BCL:0;PCL:0;RULEID:(6040450)(601004)(2401047)(8121501046)(5005006)(10201501046)(93006095)(93001095)(3002001)(6041248)(20161123558100)(20161123560025)(20161123555025)(201703131423075)(201702281528075)(201703061421075)(201703061406153)(20161123564025)(2016111802025)(20161123562025)(6043046)(6072148);SRVR:MWHPR11MB1357;BCL:0;PCL:0;RULEID:;SRVR:MWHPR11MB1357; x-forefront-prvs: 0320B28BE1 x-forefront-antispam-report: SFV:NSPM;SFS:(10019020)(6009001)(39410400002)(39400400002)(39450400003)(39830400002)(24454002)(15404003)(377424004)(33646002)(25786009)(6246003)(54906002)(53936002)(6512007)(36756003)(8936002)(2906002)(14454004)(122556002)(81166006)(8676002)(4326008)(50986999)(76176999)(54356999)(3660700001)(3280700002)(2900100001)(6436002)(5660300001)(86362001)(478600001)(2501003)(66066001)(6486002)(102836003)(3846002)(6116002)(305945005)(99286003)(7736002)(189998001)(2950100002)(77096006)(103116003)(6506006)(229853002)(38730400002);DIR:OUT;SFP:1102;SCL:1;SRVR:MWHPR11MB1357;H:MWHPR11MB1359.namprd11.prod.outlook.com;FPR:;SPF:None;MLV:sfv;LANG:en; spamdiagnosticoutput: 1:99 spamdiagnosticmetadata: NSPM Content-ID: <8457A65D62DDFD4787F9A4EB3152F736@namprd11.prod.outlook.com> MIME-Version: 1.0 X-OriginatorOrg: primarydata.com X-MS-Exchange-CrossTenant-originalarrivaltime: 27 May 2017 17:45:35.7665 (UTC) X-MS-Exchange-CrossTenant-fromentityheader: Hosted X-MS-Exchange-CrossTenant-id: 03193ed6-8726-4bb3-a832-18ab0d28adb7 X-MS-Exchange-Transport-CrossTenantHeadersStamped: MWHPR11MB1357 X-MC-Unique: -9SmiXMNOzqITI54sDzeFA-1 Content-Type: text/plain; charset=UTF-8 Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Transfer-Encoding: 8bit X-MIME-Autoconverted: from base64 to 8bit by mail.home.local id v4RHk1Gq007038 On Mon, 2017-05-22 at 14:04 -0500, Eric W. Biederman wrote: > David Howells writes: > > > Here are a set of patches to define a container object for the > > kernel and > > to provide some methods to create and manipulate them. > > > > The reason I think this is necessary is that the kernel has no idea > > how to > > direct upcalls to what userspace considers to be a container - > > current > > Linux practice appears to make a "container" just an arbitrarily > > chosen > > junction of namespaces, control groups and files, which may be > > changed > > individually within the "container". > > > > I think this might possibly be a useful abstraction for solving the > keyring upcalls if it was something created implicitly. > > fork_into_container for use by keyring upcalls is currently a > security > vulnerability as it allows escaping all of a containers cgroups.  But > you have that on your list of things to fix.  However you don't have > seccomp and a few other things. > > Before we had kthreadd in the kernel upcalls always had issues > because > the code to reset all of the userspace bits and make the forked > task suitable for running upcalls was always missing some detail.  It > is > a very bug-prone kind of idiom that you are talking about.  It is > doubly > bug-prone because the wrongness is visible to userspace and as such > might get become a frozen KABI guarantee. > > Let me suggest a concrete alternative: > > - At the time of mount observer the mounters user namespace. > - Find the mounters pid namespace. > - If the mounters pid namespace is owned by the mounters user > namespace >   walk up the pid namespace tree to the first pid namespace owned by >   that user namespace. > - If the mounters pid namespace is not owned by the mounters user >   namespace fail the mount it is going to need to make upcalls as >   will not be possible. > - Hold a reference to the pid namespace that was found. > > Then when an upcall needs to be made fork a child of the init process > of the specified pid namespace.  Or fail if the init process of the > pid namespace has died. > > That should always work and it does not require keeping expensive > state > where we did not have it previously.  Further because the semantics > are > fork a child of a particular pid namespace's init as features get > added > to the kernel this code remains well defined. > > For ordinary request-key upcalls we should be able to use the same > rules > and just not save/restore things in the kernel. > > A huge advantage of my alternative (other than not being a bit-rot > magnet) is that it should drop into existing container infrastructure > without problems.  The rule for container implementors is simple to > use > security key infrastructure you need to have created a pid namespace > in > your user namespace. > While this may be part of a solution, I don't see how it can deal with issues such as the need to set up an RPCSEC_GSS session on behalf of the user. The issue there is that while the mount may have been created in a parent namespace, the actual call to kinit to set up a kerberos context is likely to have been made inside the container. It may even have been done using a completely separate net namespace. So in order to set up my RPCSEC_GSS session, I may need to do so from inside the user container. In that kind of environment, might it perhaps make sense to just allow an upcall executable running in the root init namespace to tunnel through (using setns()) so it can actually execute in the context of the child container? That would keep security policy with the init namespace, but would also ensure that the container environment rules may be applied if and when appropriate. In addition to today's upcall mechanism, we would need the ability to pass in the nsproxy (and root directory) for the confined process that triggered the upcall and/or the namespace for the mountpoint. I'm assuming that could be done by passing in a file descriptor to the appropriate /proc entries? The downside of an approach like this is that it requires container awareness in the upcall executables themselves. If the executables don't know what they are doing, they could end up leaking information from the init namespace to the process running in the container via the keyring. Cheers Trond -- Trond Myklebust Linux NFS client maintainer, PrimaryData trond.myklebust@primarydata.com