Received: by 10.192.165.156 with SMTP id m28csp1150537imm; Wed, 11 Apr 2018 13:23:37 -0700 (PDT) X-Google-Smtp-Source: AIpwx4+0gbAZT9tzEACjYNb5iIlRDDy3PQN/kcJgzBGvjlUTWp+5QNdq1XHhXXSPYWt4odJytCON X-Received: by 10.98.66.203 with SMTP id h72mr5205008pfd.156.1523478217228; Wed, 11 Apr 2018 13:23:37 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1523478217; cv=none; d=google.com; s=arc-20160816; b=unvAUNDBPgv9z5IeUI2Yi3W0AfE000BCdL+rhAt85s1XHNSmQp8q4pPw1ialXVSQ1N 3O4/bHrPrJOGwMRcckFtZKH94reLyALaQ7tC1Kxyi2OqtC5B3IXOujsDxxORx7+bWX5o tCkEC18pbZy0rpQuuhnnbOUiOosIL2/y++r03vljRDSdk2FTWlIQM9Ck2AclGc7Ima7g 8aUqeM0J8ALp2UtU7/ws33xMmYhPJUwg6rln/1IWY48v+6ObRdX1ZKHZ4okj8OK6Ncao nAswaE66AlXWgMGV1U72UNK5AWyFDj3d+rUMocxQUhgQsVkZVV2CBW3HMltmPcvhap7M ujvw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:mime-version:user-agent:references :in-reply-to:message-id:date:subject:cc:to:from :arc-authentication-results; bh=zftvxMogSVHAuWnsa6LXC7h6vPQlbAMKE/htGsM8wB4=; b=sCQadwoLKNbgg6c3dEG3N6qku9JHWiRxGLnebpqVuzxQw4BNxmx2GumYrm7ZW2XIzL VdM65jnFnSuVeJogfb0AhEE7LHG2zo0hB9md2Ri9iLtD8tp+UpGmuK/DRj6ZXqet4Xag /ibquIGpfsqZ/Eq7cW1zuqzUEalJLuL57PwkjAbMAts7Zjg0nd8Da0g6pQsxt2fIK7c7 IGregWO+nFmYD3LQTXBUgfj8DVlmRHMlczpw8ZFZnlmFrbrBQpkeN4pudXQE6Zj9uWT0 f7/xycFF6yyTo1SaQZUtfgGwFklmkQTGnKDOqjVVKdZ8pBv+GyEL5vKRc9CoAvmXWQNK WorQ== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id p21si1216969pgc.40.2018.04.11.13.23.00; Wed, 11 Apr 2018 13:23:37 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S933099AbeDKUPD (ORCPT + 99 others); Wed, 11 Apr 2018 16:15:03 -0400 Received: from mail.linuxfoundation.org ([140.211.169.12]:33752 "EHLO mail.linuxfoundation.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S933264AbeDKSxZ (ORCPT ); Wed, 11 Apr 2018 14:53:25 -0400 Received: from localhost (LFbn-1-12247-202.w90-92.abo.wanadoo.fr [90.92.61.202]) by mail.linuxfoundation.org (Postfix) with ESMTPSA id 1CB2CEA5; Wed, 11 Apr 2018 18:53:24 +0000 (UTC) From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Kirill Tkhai , Cyrill Gorcunov , Andrei Vagin , Andreas Gruenbacher , Kees Cook , Michael Kerrisk , Al Viro , Oleg Nesterov , Paul Moore , Eric Biederman , Andy Lutomirski , Ingo Molnar , Serge Hallyn , Andrew Morton , Linus Torvalds , Sasha Levin Subject: [PATCH 4.9 022/310] pidns: disable pid allocation if pid_ns_prepare_proc() is failed in alloc_pid() Date: Wed, 11 Apr 2018 20:32:41 +0200 Message-Id: <20180411183623.247331431@linuxfoundation.org> X-Mailer: git-send-email 2.17.0 In-Reply-To: <20180411183622.305902791@linuxfoundation.org> References: <20180411183622.305902791@linuxfoundation.org> User-Agent: quilt/0.65 X-stable: review MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 4.9-stable review patch. If anyone has any objections, please let me know. ------------------ From: Kirill Tkhai [ Upstream commit 8896c23d2ef803f1883fea73117a435925c2b4c4 ] alloc_pidmap() advances pid_namespace::last_pid. When first pid allocation fails, then next created process will have pid 2 and pid_ns_prepare_proc() won't be called. So, pid_namespace::proc_mnt will never be initialized (not to mention that there won't be a child reaper). I saw crash stack of such case on kernel 3.10: BUG: unable to handle kernel NULL pointer dereference at (null) IP: proc_flush_task+0x8f/0x1b0 Call Trace: release_task+0x3f/0x490 wait_consider_task.part.10+0x7ff/0xb00 do_wait+0x11f/0x280 SyS_wait4+0x7d/0x110 We may fix this by restore of last_pid in 0 or by prohibiting of futher allocations. Since there was a similar issue in Oleg Nesterov's commit 314a8ad0f18a ("pidns: fix free_pid() to handle the first fork failure"). and it was fixed via prohibiting allocation, let's follow this way, and do the same. Link: http://lkml.kernel.org/r/149201021004.4863.6762095011554287922.stgit@localhost.localdomain Signed-off-by: Kirill Tkhai Acked-by: Cyrill Gorcunov Cc: Andrei Vagin Cc: Andreas Gruenbacher Cc: Kees Cook Cc: Michael Kerrisk Cc: Al Viro Cc: Oleg Nesterov Cc: Paul Moore Cc: Eric Biederman Cc: Andy Lutomirski Cc: Ingo Molnar Cc: Serge Hallyn Signed-off-by: Andrew Morton Signed-off-by: Linus Torvalds Signed-off-by: Sasha Levin Signed-off-by: Greg Kroah-Hartman --- kernel/pid.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) --- a/kernel/pid.c +++ b/kernel/pid.c @@ -322,8 +322,10 @@ struct pid *alloc_pid(struct pid_namespa } if (unlikely(is_child_reaper(pid))) { - if (pid_ns_prepare_proc(ns)) + if (pid_ns_prepare_proc(ns)) { + disable_pid_allocation(ns); goto out_free; + } } get_pid_ns(ns);