From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1161374AbcFBQbJ (ORCPT ); Thu, 2 Jun 2016 12:31:09 -0400 Received: from out02.mta.xmission.com ([166.70.13.232]:57333 "EHLO out02.mta.xmission.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753249AbcFBQbE (ORCPT ); Thu, 2 Jun 2016 12:31:04 -0400 From: ebiederm@xmission.com (Eric W. Biederman) To: Nikolay Borisov Cc: john@johnmccutchan.com, eparis@redhat.com, jack@suse.cz, linux-kernel@vger.kernel.org, gorcunov@openvz.org, avagin@openvz.org, netdev@vger.kernel.org, operations@siteground.com, Linux Containers References: <1464767580-22732-1-git-send-email-kernel@kyup.com> <8737ow7vcp.fsf@x220.int.ebiederm.org> <574FD1E4.8090109@kyup.com> Date: Thu, 02 Jun 2016 11:19:23 -0500 In-Reply-To: <574FD1E4.8090109@kyup.com> (Nikolay Borisov's message of "Thu, 2 Jun 2016 09:27:48 +0300") Message-ID: <87y46n36no.fsf@x220.int.ebiederm.org> User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/24.5 (gnu/linux) MIME-Version: 1.0 Content-Type: text/plain X-XM-AID: U2FsdGVkX1/qscnEiQtqSMg0GQVZ2rPiv8JYs5/913E= X-SA-Exim-Connect-IP: 67.3.226.120 X-SA-Exim-Mail-From: ebiederm@xmission.com X-Spam-Report: * -1.0 ALL_TRUSTED Passed through trusted hosts only via SMTP * 0.0 TVD_RCVD_IP Message was received from an IP address * 1.5 XMNoVowels Alpha-numberic number with no vowels * 0.7 XMSubLong Long Subject * 0.0 T_TM2_M_HEADER_IN_MSG BODY: No description available. * 0.8 BAYES_50 BODY: Bayes spam probability is 40 to 60% * [score: 0.5000] * -0.0 DCC_CHECK_NEGATIVE Not listed in DCC * [sa07 1397; Body=1 Fuz1=1 Fuz2=1] X-Spam-DCC: XMission; sa07 1397; Body=1 Fuz1=1 Fuz2=1 X-Spam-Combo: **;Nikolay Borisov X-Spam-Relay-Country: X-Spam-Timing: total 632 ms - load_scoreonly_sql: 0.04 (0.0%), signal_user_changed: 3.3 (0.5%), b_tie_ro: 2.3 (0.4%), parse: 1.12 (0.2%), extract_message_metadata: 20 (3.2%), get_uri_detail_list: 3.3 (0.5%), tests_pri_-1000: 4.9 (0.8%), tests_pri_-950: 1.26 (0.2%), tests_pri_-900: 1.06 (0.2%), tests_pri_-400: 27 (4.3%), check_bayes: 26 (4.1%), b_tokenize: 7 (1.2%), b_tok_get_all: 9 (1.5%), b_comp_prob: 3.2 (0.5%), b_tok_touch_all: 2.9 (0.5%), b_finish: 0.71 (0.1%), tests_pri_0: 563 (89.0%), check_dkim_signature: 1.04 (0.2%), check_dkim_adsp: 176 (27.8%), tests_pri_500: 7 (1.0%), rewrite_mail: 0.00 (0.0%) Subject: Re: [RFC PATCH 0/4] Make inotify instance/watches be accounted per userns X-Spam-Flag: No X-SA-Exim-Version: 4.2.1 (built Thu, 05 May 2016 13:38:54 -0600) X-SA-Exim-Scanned: Yes (on in01.mta.xmission.com) Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Nikolay Borisov writes: > On 06/01/2016 07:00 PM, Eric W. Biederman wrote: >> Cc'd the containers list. >> >> >> Nikolay Borisov writes: >> >>> Currently the inotify instances/watches are being accounted in the >>> user_struct structure. This means that in setups where multiple >>> users in unprivileged containers map to the same underlying >>> real user (e.g. user_struct) the inotify limits are going to be >>> shared as well which can lead to unplesantries. This is a problem >>> since any user inside any of the containers can potentially exhaust >>> the instance/watches limit which in turn might prevent certain >>> services from other containers from starting. >> >> On a high level this is a bit problematic as it appears to escapes the >> current limits and allows anyone creating a user namespace to have their >> own fresh set of limits. Given that anyone should be able to create a >> user namespace whenever they feel like escaping limits is a problem. >> That however is solvable. > > This is indeed a problem and the presented solution is rather dumb in > that regard. I'm happy to work with you on suggestions so that I arrive > at a solution that is upstreamable. The one in kernel solution to hierarchical resource limits that I am aware of is the current include/linux/page_counter.h which evolved from include/linux/res_counter.h >> A practical question. What kind of limits are we looking at here? >> >> Are these loose limits for detecting buggy programs that have gone >> off their rails? > > Loose limits. > >> >> Are these tight limits to ensure multitasking is possible? >> >> >> >> For tight limits where something is actively controlling the limits you >> probably want a cgroup base solution. >> >> For loose limits that are the kind where you set a good default and >> forget about I think a user namespace based solution is reasonable. > > That's exactly the use case I had in mind. > >> >>> The solution I propose is rather simple, instead of accounting the >>> watches/instances per user_struct, start accounting them in a hashtable, >>> where the index used is the hashed pointer of the userns. This way >>> the administrator needn't set the inotify limits very high and also >>> the risk of one container breaching the limits and affecting every >>> other container is alleviated. >> >> I don't think this is the right data structure for a user namespace >> based solution, at least in part because it does not account for users >> escaping. > > Admittedly this is a naive solution, what are you ideas on something > which achieves my initial aim of having limits per users, yet not > allowing them to just create another namespace and escape them. The > current namespace code has a hard-coded limit of 32 for nesting user > namespaces. So currently at the worst case one can escape the limits up > to 32 * current_limits. 32 is the nesting depth not the width of the tree. But see above. Eric