From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1757385AbdELPDK (ORCPT ); Fri, 12 May 2017 11:03:10 -0400 Received: from out01.mta.xmission.com ([166.70.13.231]:57925 "EHLO out01.mta.xmission.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1756841AbdELPDI (ORCPT ); Fri, 12 May 2017 11:03:08 -0400 From: ebiederm@xmission.com (Eric W. Biederman) To: Kirill Tkhai Cc: , , , , , , , , References: <149459906128.21666.4535332985674353536.stgit@localhost.localdomain> Date: Fri, 12 May 2017 09:56:36 -0500 In-Reply-To: <149459906128.21666.4535332985674353536.stgit@localhost.localdomain> (Kirill Tkhai's message of "Fri, 12 May 2017 17:33:36 +0300") Message-ID: <87a86i2kez.fsf@xmission.com> User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/25.1 (gnu/linux) MIME-Version: 1.0 Content-Type: text/plain X-XM-SPF: eid=1d9C5r-00029I-6m;;;mid=<87a86i2kez.fsf@xmission.com>;;;hst=in01.mta.xmission.com;;;ip=97.121.81.159;;;frm=ebiederm@xmission.com;;;spf=neutral X-XM-AID: U2FsdGVkX18CZP3BrBwzPha81mYZv+BEyGSndNWaAVk= X-SA-Exim-Connect-IP: 97.121.81.159 X-SA-Exim-Mail-From: ebiederm@xmission.com X-Spam-Report: * -1.0 ALL_TRUSTED Passed through trusted hosts only via SMTP * 0.7 XMSubLong Long Subject * 0.0 TVD_RCVD_IP Message was received from an IP address * 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 * [sa02 1397; Body=1 Fuz1=1 Fuz2=1] X-Spam-DCC: XMission; sa02 1397; Body=1 Fuz1=1 Fuz2=1 X-Spam-Combo: ;Kirill Tkhai X-Spam-Relay-Country: X-Spam-Timing: total 8046 ms - load_scoreonly_sql: 0.06 (0.0%), signal_user_changed: 3.4 (0.0%), b_tie_ro: 2.3 (0.0%), parse: 1.25 (0.0%), extract_message_metadata: 738 (9.2%), get_uri_detail_list: 61 (0.8%), tests_pri_-1000: 499 (6.2%), tests_pri_-950: 2.1 (0.0%), tests_pri_-900: 2.3 (0.0%), tests_pri_-400: 397 (4.9%), check_bayes: 395 (4.9%), b_tokenize: 228 (2.8%), b_tok_get_all: 45 (0.6%), b_comp_prob: 53 (0.7%), b_tok_touch_all: 19 (0.2%), b_finish: 4.3 (0.1%), tests_pri_0: 6160 (76.6%), check_dkim_signature: 1.01 (0.0%), check_dkim_adsp: 55 (0.7%), tests_pri_500: 141 (1.8%), rewrite_mail: 0.00 (0.0%) Subject: Re: [PATCH] prctl: Allow local CAP_SYS_ADMIN changing exe_file 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 Kirill Tkhai writes: > During checkpointing and restore of userspace tasks > we bumped into the situation, that it's not possible > to restore the tasks, which user namespace does not > have uid 0 or gid 0 mapped. > > People create user namespace mappings like they want, > and there is no a limitation on obligatory uid and gid > "must be mapped". So, if there is no uid 0 or gid 0 > in the mapping, it's impossible to restore mm->exe_file > of the processes belonging to this user namespace. > > Also, there is no a workaround. It's impossible > to create a temporary uid/gid mapping, because > only one write to /proc/[pid]/uid_map and gid_map > is allowed during a namespace lifetime. > If there is an entry, then no more mapings can't be > written. If there isn't an entry, we can't write > there too, otherwise user task won't be able > to do that in the future. > > The patch changes the check, and looks for CAP_SYS_ADMIN > instead of zero uid and gid. This allows to restore > a task independently of its user namespace mappings. Applied thanks. Testing against 0 in the modern kernel is perhaps the most bizarre permisssion check I have seen lately. Eric > > Signed-off-by: Kirill Tkhai > CC: Andrew Morton > CC: Serge Hallyn > CC: "Eric W. Biederman" > CC: Oleg Nesterov > CC: Michal Hocko > CC: Andrei Vagin > CC: Cyrill Gorcunov > CC: Stanislav Kinsburskiy > CC: Pavel Tikhomirov > --- > kernel/sys.c | 8 ++------ > 1 file changed, 2 insertions(+), 6 deletions(-) > > diff --git a/kernel/sys.c b/kernel/sys.c > index 8a94b4eabcaa..7c6d78148fa0 100644 > --- a/kernel/sys.c > +++ b/kernel/sys.c > @@ -1802,15 +1802,11 @@ static int validate_prctl_map(struct prctl_mm_map *prctl_map) > > /* > * Finally, make sure the caller has the rights to > - * change /proc/pid/exe link: only local root should > + * change /proc/pid/exe link: only local sys admin should > * be allowed to. > */ > if (prctl_map->exe_fd != (u32)-1) { > - struct user_namespace *ns = current_user_ns(); > - const struct cred *cred = current_cred(); > - > - if (!uid_eq(cred->uid, make_kuid(ns, 0)) || > - !gid_eq(cred->gid, make_kgid(ns, 0))) > + if (!ns_capable(current_user_ns(), CAP_SYS_ADMIN)) > goto out; > } >