Received: by 10.192.165.156 with SMTP id m28csp1063697imm; Wed, 11 Apr 2018 11:44:50 -0700 (PDT) X-Google-Smtp-Source: AIpwx48ujN+F2s4v1QrN8Cx7KIqwPAKYXry8T9rRO5immvRH3i3QjQ5tMO+B/XTHqzLEdF4wMSCo X-Received: by 2002:a17:902:b081:: with SMTP id p1-v6mr6249859plr.31.1523472290070; Wed, 11 Apr 2018 11:44:50 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1523472290; cv=none; d=google.com; s=arc-20160816; b=c15re8R99ru/rsXaIqw8lq44z0ta+UtV6Xi3d2OGbhe0aN/MSxc+TsHPW7d2Zf6gWR ddik6tjIuZbDYPdDQ5bnhV2iC6morlCAjMnqyNHNPWTl/UtF1BLkli+l0wVAnnaKe5yh AgUaMUZvqnXsIVH1TJnyQmHQ0BMRUQsDnfv3dVDIqYEgWyFpCmZR/PCBiLuGp9+Rx1hm sRYfLPZDuQ38G1495Kpguq3xpsUbydY19v3KFsfCC9xIGE2I3+848+r5A21UfJg2bFlc Xfzgo8xAgrQDJ5aqySReMLkuTkEZIgqVYTUJG2lRaMfVDj2OkYlq6OelqDMbwwfMuZ8n VuWQ== 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=nxIKs3VBgmrId5o5W7CnJ9T0ePyfgj3bS1Z0lpi6PCw=; b=b/6UDl5OwGx6plEr5AgKcK+KmYt7WouQApsj1ueoOc557dVE4nO36Lmk2bbUtivPMh mVuNy9Nw5UW9+UM18A61R3SxbO3I6RDbuFy0Fu25Ybx012fb3mr641/4HY6LTOefRK5u AMLymDjsyAtuYpovou3L81xTh7ixIQAj4GegRguplCkbtpx3Ief6pepdRYpzwjdIxNtr nA317YRiwei7pCrcaw2iLkaxMHErpr0lKc8t1e7SVSTSlfCQ3zcQ5DJQq8OZ6F/O9Zw/ s3ZJmcuPq5Qf7ZP2zIzgxEVgusNvAGnAHezmdkrXHXRkbYwhbMUVqiEV/SKti3mY+vQc qWzw== 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 h3si1291073pfn.158.2018.04.11.11.44.13; Wed, 11 Apr 2018 11:44:50 -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 S1754567AbeDKSkK (ORCPT + 99 others); Wed, 11 Apr 2018 14:40:10 -0400 Received: from mail.linuxfoundation.org ([140.211.169.12]:56296 "EHLO mail.linuxfoundation.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753241AbeDKSkG (ORCPT ); Wed, 11 Apr 2018 14:40:06 -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 5584E407; Wed, 11 Apr 2018 18:40:05 +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 3.18 009/121] pidns: disable pid allocation if pid_ns_prepare_proc() is failed in alloc_pid() Date: Wed, 11 Apr 2018 20:35:12 +0200 Message-Id: <20180411183456.793551983@linuxfoundation.org> X-Mailer: git-send-email 2.17.0 In-Reply-To: <20180411183456.195010921@linuxfoundation.org> References: <20180411183456.195010921@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 3.18-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 @@ -316,8 +316,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);