From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752617AbcHHVWN (ORCPT ); Mon, 8 Aug 2016 17:22:13 -0400 Received: from out02.mta.xmission.com ([166.70.13.232]:37065 "EHLO out02.mta.xmission.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752208AbcHHVWM (ORCPT ); Mon, 8 Aug 2016 17:22:12 -0400 From: ebiederm@xmission.com (Eric W. Biederman) To: Dmitry Torokhov Cc: "David S. Miller" , Al Viro , linux-kernel@vger.kernel.org, netdev@vger.kernel.org References: <20160802231926.GA8108@dtor-ws> Date: Mon, 08 Aug 2016 16:08:48 -0500 In-Reply-To: <20160802231926.GA8108@dtor-ws> (Dmitry Torokhov's message of "Tue, 2 Aug 2016 16:19:26 -0700") Message-ID: <8737mfotnj.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=1bWrzk-00041H-B4;;;mid=<8737mfotnj.fsf@x220.int.ebiederm.org>;;;hst=in01.mta.xmission.com;;;ip=67.3.204.119;;;frm=ebiederm@xmission.com;;;spf=neutral X-XM-AID: U2FsdGVkX1+Ky7vsJJalSd5UtZzpzyYz+w70h1yjVTA= 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.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: ;Dmitry Torokhov X-Spam-Relay-Country: X-Spam-Timing: total 229 ms - load_scoreonly_sql: 0.03 (0.0%), signal_user_changed: 3.7 (1.6%), b_tie_ro: 2.7 (1.2%), parse: 0.68 (0.3%), extract_message_metadata: 11 (5.0%), get_uri_detail_list: 1.56 (0.7%), tests_pri_-1000: 5 (2.3%), tests_pri_-950: 1.15 (0.5%), tests_pri_-900: 0.98 (0.4%), tests_pri_-400: 20 (8.8%), check_bayes: 19 (8.3%), b_tokenize: 5 (2.4%), b_tok_get_all: 7 (2.9%), b_comp_prob: 1.87 (0.8%), b_tok_touch_all: 3.0 (1.3%), b_finish: 0.64 (0.3%), tests_pri_0: 180 (78.5%), check_dkim_signature: 0.48 (0.2%), check_dkim_adsp: 2.6 (1.1%), tests_pri_500: 3.5 (1.5%), 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 in01.mta.xmission.com) Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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. Eric