Received: by 10.192.165.156 with SMTP id m28csp1066661imm; Wed, 11 Apr 2018 11:48:24 -0700 (PDT) X-Google-Smtp-Source: AIpwx4/GA4bA0ZlQomYbC1bSEcQziQeDZck3kiHjtc1Oux101Bkrg+PE9JnfH0LHw0pKAQLBt+TL X-Received: by 2002:a17:902:7008:: with SMTP id y8-v6mr6280309plk.69.1523472503960; Wed, 11 Apr 2018 11:48:23 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1523472503; cv=none; d=google.com; s=arc-20160816; b=uk0d3VRFqcpEXP5w8DuKlXpezkIryxmb0x+hiJz11r5dVvsiOl83T7mzIm0e0GkJAz LjlkLTUtCP0GhcpEoFEgbewMqOleM3vozoOovZJX96QW9Mvz2v3HgtxQhT0moElpKRYc vAMa/c2vocBFCT/Qxtv6zHnNqqsrYd3JGkOJpqrV0uwPXm3/yY5mXNA5CxjAO0ytXr6K oSYu8schty4DVL8mRxRF/X4jZFOlw+jJ3FarvhE8gzhbQPa5oW7ljyTP4LxSWX0dPiDK EN0BUJOi2jc/plAWuhYOHP2XoZO4ZD10jApOuJ9R5wnvInBYed9g92jO5CfMMnDHieDw 0ABw== 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=ywZasimFFLN8SviRYZ09nLiNfigzu0Y5ZqV2Su7bwvE=; b=ldvm82EYZfw8PrEu8iOLO876pmY0wJm7NlJxB8qhxP0oX5+HoMNsVuUhFs5CCU87lj 9riMXJ8aupRmOpKG+RBSJ5wQKR7GSsR4JeAtns/hBLpxkkHWnxVLwipzG6uunskJets/ v5KrMymvD3JxWF1dbzKE8s69KAUB9PyFWArUtd2Q2bcyPoV1mgTUpfzOTMQ/oDZOPe5r JK3RZHh5htDQPndNVNW57+t3bN9f/EAPFbQ/F7DlnEQRPsH/ShCfZ9/FV5IJlScFNR2y 4prcDNfGaPZOVPDypJb/8Cu8xqwOk1TFckKTYudzPK1Kj366hAJ7dsOCcJVnDi4pgO0E maNA== 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 g8si1071863pgq.544.2018.04.11.11.47.47; Wed, 11 Apr 2018 11:48:23 -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 S932166AbeDKSoE (ORCPT + 99 others); Wed, 11 Apr 2018 14:44:04 -0400 Received: from mail.linuxfoundation.org ([140.211.169.12]:57790 "EHLO mail.linuxfoundation.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S932141AbeDKSn7 (ORCPT ); Wed, 11 Apr 2018 14:43:59 -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 A840ED9C; Wed, 11 Apr 2018 18:43:58 +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.4 016/190] pidns: disable pid allocation if pid_ns_prepare_proc() is failed in alloc_pid() Date: Wed, 11 Apr 2018 20:34:22 +0200 Message-Id: <20180411183551.023975758@linuxfoundation.org> X-Mailer: git-send-email 2.17.0 In-Reply-To: <20180411183550.114495991@linuxfoundation.org> References: <20180411183550.114495991@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.4-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);