Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751788AbdFFTMR (ORCPT ); Tue, 6 Jun 2017 15:12:17 -0400 Received: from out03.mta.xmission.com ([166.70.13.233]:57583 "EHLO out03.mta.xmission.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751526AbdFFTMO (ORCPT ); Tue, 6 Jun 2017 15:12:14 -0400 From: "Eric W. Biederman" To: linux-kernel@vger.kernel.org Cc: linux-api@vger.kernel.org, Linus Torvalds , Oleg Nesterov , Ingo Molnar , Thomas Gleixner , Kees Cook , Roland McGrath , Al Viro , David Howells , "Michael Kerrisk (man-pages)" , "Eric W. Biederman" Date: Tue, 6 Jun 2017 14:03:19 -0500 Message-Id: <20170606190338.28347-7-ebiederm@xmission.com> X-Mailer: git-send-email 2.10.1 In-Reply-To: <20170606190338.28347-1-ebiederm@xmission.com> References: <877f0pym71.fsf@xmission.com> <20170606190338.28347-1-ebiederm@xmission.com> X-XM-SPF: eid=1dIJtZ-0006wd-NG;;;mid=<20170606190338.28347-7-ebiederm@xmission.com>;;;hst=in02.mta.xmission.com;;;ip=97.121.81.159;;;frm=ebiederm@xmission.com;;;spf=neutral X-XM-AID: U2FsdGVkX18MEogA9X4wjgI6p/zFKMZ9nmD8k1jX394= 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 * 1.5 XMNoVowels Alpha-numberic number with no vowels * 0.7 XMSubLong Long Subject * 0.0 TVD_RCVD_IP Message was received from an IP address * 0.8 BAYES_50 BODY: Bayes spam probability is 40 to 60% * [score: 0.5000] * -0.0 DCC_CHECK_NEGATIVE Not listed in DCC * [sa06 1397; Body=1 Fuz1=1 Fuz2=1] * 0.0 T_TooManySym_01 4+ unique symbols in subject X-Spam-DCC: XMission; sa06 1397; Body=1 Fuz1=1 Fuz2=1 X-Spam-Combo: **;linux-kernel@vger.kernel.org X-Spam-Relay-Country: X-Spam-Timing: total 5538 ms - load_scoreonly_sql: 0.05 (0.0%), signal_user_changed: 2.4 (0.0%), b_tie_ro: 1.58 (0.0%), parse: 0.76 (0.0%), extract_message_metadata: 11 (0.2%), get_uri_detail_list: 0.83 (0.0%), tests_pri_-1000: 6 (0.1%), tests_pri_-950: 1.21 (0.0%), tests_pri_-900: 1.01 (0.0%), tests_pri_-400: 18 (0.3%), check_bayes: 16 (0.3%), b_tokenize: 5 (0.1%), b_tok_get_all: 5 (0.1%), b_comp_prob: 1.91 (0.0%), b_tok_touch_all: 1.83 (0.0%), b_finish: 0.64 (0.0%), tests_pri_0: 136 (2.4%), check_dkim_signature: 0.50 (0.0%), check_dkim_adsp: 2.5 (0.0%), tests_pri_500: 5359 (96.8%), poll_dns_idle: 5354 (96.7%), rewrite_mail: 0.00 (0.0%) Subject: [PATCH 07/26] pidns: Improve the error handling in alloc_pid 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 Content-Length: 1061 Lines: 40 Cause any failure to allocate pid 1 to permanently disable pid allocations for the pid namespace. Before the pid becomes pid 1 there ns->last_pid and other state remains unchanged so it is safe to try again... Signed-off-by: "Eric W. Biederman" --- kernel/pid.c | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/kernel/pid.c b/kernel/pid.c index fd1cde1e4576..f4fb1a84109b 100644 --- a/kernel/pid.c +++ b/kernel/pid.c @@ -321,10 +321,8 @@ struct pid *alloc_pid(struct pid_namespace *ns) } if (unlikely(is_child_reaper(pid))) { - if (pid_ns_prepare_proc(ns)) { - disable_pid_allocation(ns); + if (pid_ns_prepare_proc(ns)) goto out_free; - } } get_pid_ns(ns); @@ -350,6 +348,10 @@ struct pid *alloc_pid(struct pid_namespace *ns) put_pid_ns(ns); out_free: + /* Ensure everything stops if allocation of pid 1 failed */ + if ((i < ns->level) && (pid->numbers[ns->level].nr == 1)) + disable_pid_allocation(ns); + while (++i <= ns->level) free_pidmap(pid->numbers + i); -- 2.10.1