From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752572AbcHHWCI (ORCPT ); Mon, 8 Aug 2016 18:02:08 -0400 Received: from out02.mta.xmission.com ([166.70.13.232]:46538 "EHLO out02.mta.xmission.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1750938AbcHHWCH (ORCPT ); Mon, 8 Aug 2016 18:02:07 -0400 From: ebiederm@xmission.com (Eric W. Biederman) To: Dmitry Torokhov Cc: "David S. Miller" , Al Viro , lkml , netdev References: <20160802231926.GA8108@dtor-ws> <8737mfotnj.fsf@x220.int.ebiederm.org> Date: Mon, 08 Aug 2016 16:48:40 -0500 In-Reply-To: (Dmitry Torokhov's message of "Mon, 8 Aug 2016 14:54:45 -0700") Message-ID: <87eg5zlyo7.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-SPF: eid=1bWscK-0004nI-91;;;mid=<87eg5zlyo7.fsf@x220.int.ebiederm.org>;;;hst=in02.mta.xmission.com;;;ip=67.3.204.119;;;frm=ebiederm@xmission.com;;;spf=neutral X-XM-AID: U2FsdGVkX18g/5tKSwXPMuXQEMWwcZPmpuw/VJquAEY= X-SA-Exim-Connect-IP: 67.3.204.119 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 * 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.4994] * -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: ;Dmitry Torokhov X-Spam-Relay-Country: X-Spam-Timing: total 388 ms - load_scoreonly_sql: 0.04 (0.0%), signal_user_changed: 3.5 (0.9%), b_tie_ro: 2.4 (0.6%), parse: 1.16 (0.3%), extract_message_metadata: 19 (5.0%), get_uri_detail_list: 3.0 (0.8%), tests_pri_-1000: 4.2 (1.1%), tests_pri_-950: 1.68 (0.4%), tests_pri_-900: 1.42 (0.4%), tests_pri_-400: 44 (11.2%), check_bayes: 42 (10.8%), b_tokenize: 10 (2.7%), b_tok_get_all: 12 (3.0%), b_comp_prob: 3.4 (0.9%), b_tok_touch_all: 13 (3.4%), b_finish: 0.89 (0.2%), tests_pri_0: 305 (78.7%), check_dkim_signature: 0.54 (0.1%), check_dkim_adsp: 63 (16.3%), tests_pri_500: 3.8 (1.0%), rewrite_mail: 0.00 (0.0%) Subject: Re: [PATCH] net: make net namespace sysctls belong to container's owner 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 in02.mta.xmission.com) Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Dmitry Torokhov writes: > On Mon, Aug 8, 2016 at 2:08 PM, Eric W. Biederman wrote: >> Dmitry Torokhov writes: >> >>> If net namespace is attached to a user namespace let's make container's >>> root owner of sysctls affecting said network namespace instead of global >>> root. >>> >>> This also allows us to clean up net_ctl_permissions() because we do not >>> need to fudge permissions anymore for the container's owner since it now >>> owns the objects in question. >> >> Acked-by: "Eric W. Biederman" >> >> Overall this seems reasonable. However I am not a fan of your error >> handling. >> >>> Signed-off-by: Dmitry Torokhov >>> --- >>> >>> This helps when running Android CTS in a container, but I think it makes >>> sense regardless. >> >>> +static void net_ctl_set_ownership(struct ctl_table_header *head, >>> + struct ctl_table *table, >>> + kuid_t *uid, kgid_t *gid) >>> +{ >>> + struct net *net = container_of(head->set, struct net, sysctls); >>> + >>> + *uid = make_kuid(net->user_ns, 0); >>> + if (!uid_valid(*uid)) >>> + *uid = GLOBAL_ROOT_UID; >>> + >>> + *gid = make_kgid(net->user_ns, 0); >>> + if (!gid_valid(*gid)) >>> + *gid = GLOBAL_ROOT_GID; >> >> This code should eiter be: >> *uid = make_kuid(net->user_ns, 0); >> *gid = make_kgid(net->user_ns, 0); >> >> Or it should be: >> tmp_uid = make_kuid(net->user_ns, 0); >> if (uid_valid(tmp_uid)) >> *uid = tmp_uid; >> >> tmp_gid = make_kgid(net->user_ns, 0); >> if (gid_valid(tmp_gid)) >> *gid = tmp_gid; >> >> It is just very fragile to assume to know what uid and gid >> would be if this code fails. >> >> As of v4.8-rc1 INVALID_UID and INVALID_GID can be set in inode->i_uid >> and inode->i_gid without causing horrible vfs confusion (making the >> first option viable), but I expect with the mention of Android you want >> to backport this so I will ask that you ask to implement the error >> handling that doesn't assume you know better than the generic code. >> >> If you don't have a better value to set something to it really should be >> left alone. > > OK, fair enough. I will adopt the 2nd option and will resubmit. I need > to also test without net namespaces support (my other change blows up > because we are getting half-initialized init_net structure when > namespaces are disabled). No rush. I will be out on vacation for the next couple of weeks. Eric