Received: by 10.213.65.68 with SMTP id h4csp1884266imn; Mon, 19 Mar 2018 16:19:36 -0700 (PDT) X-Google-Smtp-Source: AG47ELsfNHplysg6txn/H5RO2ntJfrZbNW95AP1adi3EUmV7tF3uBkAV7NlADEyhtQhPu0cVr3jq X-Received: by 2002:a17:902:c6b:: with SMTP id 98-v6mr14047185pls.267.1521501576712; Mon, 19 Mar 2018 16:19:36 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1521501576; cv=none; d=google.com; s=arc-20160816; b=s77JpfuKQY5JaLKfsNoDDGykTZmysmwHT8keWxwRAMY88nD3YKJ88ApGctZ5AQkwgH LqN9MqRViXCx5rEiIT4nMt/xrWFZe7q/uQubWIlSJZpRgXEFEIJJUae8lALNoP7E1B/s 4uqXLPvXAW4h45KO6es5jRhwekIjIEEOITfgYqjoF697c8i135RuRYhc9ZZ8LghxPB1m Z/H8SK+8VAkZ+tq6MQXHwD+QHNKEtRpv98KnrLtMsA1q5vc4craCjeL6+GFIx97m7HR6 JB6nK4duyeTx/aibfZmyBbs6fkn2wExmjuIKjNadfglQZZ/n9px7AC+M/z2oBvpA7E15 99jA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:mime-version:content-transfer-encoding :spamdiagnosticmetadata:spamdiagnosticoutput:content-language :accept-language:in-reply-to:references:message-id:date:thread-index :thread-topic:subject:cc:to:from:dkim-signature :arc-authentication-results; bh=ca6b7BvX9JKkBnIeHyH8ugqpK5cnChcIb2Ll4ccm/C0=; b=w95Nn+MBKUYfM+EkUHh8GlPnGo2ciRJibbZUkZRvb16jY5QHzbXgGYr+XuaTA8lkSk rZE4lFHJKmAqUDvb0ujOdj+oU8bKqt6Ozp2tI5VHnMMGkhQykpH1Ze1XkT/h8WsCN66h 88QEq9IG7wkPurWKUuEqOMij7gCAheElHqHcRG5PrsmZplD6vlhkxpmZ2y+HqjZLROn7 W7WX8DSvO+HuOAieijJ/4tD11qf/u1v9p1ZgHmxuTTBpBtYFSV5EjU3WSjQg2Ykminu1 fWc6x/IL9bGi1XSP9W1u3jwFiWl8imflHHqJnAEYVhMYIxAfsPy5FlQ3ukNxx6AVUN7U Ttng== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@microsoft.com header.s=selector1 header.b=jVxnFnes; 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; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=microsoft.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id n7si230186pfj.58.2018.03.19.16.19.22; Mon, 19 Mar 2018 16:19:36 -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; dkim=pass header.i=@microsoft.com header.s=selector1 header.b=jVxnFnes; 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; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=microsoft.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S966134AbeCSQHR (ORCPT + 99 others); Mon, 19 Mar 2018 12:07:17 -0400 Received: from mail-cys01nam02on0100.outbound.protection.outlook.com ([104.47.37.100]:20505 "EHLO NAM02-CY1-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S966065AbeCSQGu (ORCPT ); Mon, 19 Mar 2018 12:06:50 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=selector1; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version; bh=ca6b7BvX9JKkBnIeHyH8ugqpK5cnChcIb2Ll4ccm/C0=; b=jVxnFnesyYL0APhBUDSHGqaFl1gt+Beu1vSPM7nteHO8uTH6Vh2fFOFzJExgXelGNwfW54JugIvte3XZME85eUcILlQgcfOsSHhMohwdkEBETsYePiA71roIxP1gUHrA3g7hke+AdNE54J2UvFyGH002tmd77Kt3okwsuaoIK/E= Received: from DM5PR2101MB1032.namprd21.prod.outlook.com (52.132.128.13) by DM5PR2101MB1093.namprd21.prod.outlook.com (52.132.130.15) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.631.0; Mon, 19 Mar 2018 16:06:47 +0000 Received: from DM5PR2101MB1032.namprd21.prod.outlook.com ([fe80::3d9b:79e7:94eb:5d62]) by DM5PR2101MB1032.namprd21.prod.outlook.com ([fe80::3d9b:79e7:94eb:5d62%5]) with mapi id 15.20.0631.004; Mon, 19 Mar 2018 16:06:47 +0000 From: Sasha Levin To: "linux-kernel@vger.kernel.org" , "stable@vger.kernel.org" CC: Kirill Tkhai , 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 AUTOSEL for 4.4 016/167] pidns: disable pid allocation if pid_ns_prepare_proc() is failed in alloc_pid() Thread-Topic: [PATCH AUTOSEL for 4.4 016/167] pidns: disable pid allocation if pid_ns_prepare_proc() is failed in alloc_pid() Thread-Index: AQHTv5whIYVhVopSOkGIfL7hAX/InA== Date: Mon, 19 Mar 2018 16:05:41 +0000 Message-ID: <20180319160513.16384-16-alexander.levin@microsoft.com> References: <20180319160513.16384-1-alexander.levin@microsoft.com> In-Reply-To: <20180319160513.16384-1-alexander.levin@microsoft.com> Accept-Language: en-US Content-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: x-originating-ip: [52.168.54.252] x-ms-publictraffictype: Email x-microsoft-exchange-diagnostics: 1;DM5PR2101MB1093;7:3ncTj/KZBe9rl9XOsCV69/4jdXxvFvKAmMxF4DbJUdb/XxE3fEHVfNhA4kz/Op577yyc9j0EBx/jx9+7ZlPo/cSKgMzXSDk2huBsxzUcXyPDnXXxRwduoRCmdm7JmrlMhlkQ5vphj0Tdn2xHjXLZSSsMCoZB6V5UxW0R7ekurGZwUnmZbh4FcNp11VS7Ni7Yu4WUT8EcIi1o64WUCIsOyj50xz1FhXN8sKXpHOeziJp/Zj7sE0OFaau1LaO85AcD;20:GwY2/QMbxibNYdLwrbG7IrCQNHtAOo2EZ8efZKYUcJv3xq0lEwBDxbITtofE0q7tDHKCTHrsMI4PuvD8OYmA+9EBk+PxHmTXZT9LO5pTVvIulx9nSV/A2Ur0al4YScTRSltvEflYQ8s5ixQBSZx1tb7PeX9S7xJOGhSl6zXEjEs= x-ms-office365-filtering-ht: Tenant x-ms-office365-filtering-correlation-id: 256c58ad-4d8d-41fb-365e-08d58db36b05 x-microsoft-antispam: UriScan:;BCL:0;PCL:0;RULEID:(7020095)(4652020)(48565401081)(5600026)(4604075)(3008032)(4534165)(4627221)(201703031133081)(201702281549075)(2017052603328)(7193020);SRVR:DM5PR2101MB1093; x-ms-traffictypediagnostic: DM5PR2101MB1093: authentication-results: spf=none (sender IP is ) smtp.mailfrom=Alexander.Levin@microsoft.com; x-microsoft-antispam-prvs: x-exchange-antispam-report-test: UriScan:(230824228335337)(28532068793085)(89211679590171)(42068640409301)(8415204561270); x-exchange-antispam-report-cfa-test: BCL:0;PCL:0;RULEID:(8211001083)(61425038)(6040522)(2401047)(5005006)(8121501046)(3231221)(944501300)(52105095)(3002001)(93006095)(93001095)(10201501046)(6055026)(61426038)(61427038)(6041310)(201703131423095)(201702281528075)(20161123555045)(201703061421075)(201703061406153)(20161123560045)(20161123562045)(20161123564045)(20161123558120)(6072148)(201708071742011);SRVR:DM5PR2101MB1093;BCL:0;PCL:0;RULEID:;SRVR:DM5PR2101MB1093; x-forefront-prvs: 06167FAD59 x-forefront-antispam-report: SFV:NSPM;SFS:(10019020)(376002)(396003)(39380400002)(366004)(39860400002)(346002)(189003)(199004)(10290500003)(68736007)(478600001)(110136005)(72206003)(36756003)(99286004)(97736004)(10090500001)(305945005)(7736002)(6666003)(76176011)(107886003)(2950100002)(6436002)(86612001)(966005)(6486002)(4326008)(54906003)(186003)(3660700001)(25786009)(26005)(2906002)(53936002)(575784001)(5250100002)(2501003)(81166006)(81156014)(2900100001)(86362001)(5660300001)(8936002)(1076002)(6306002)(8676002)(3846002)(3280700002)(6116002)(7416002)(66066001)(316002)(59450400001)(6506007)(14454004)(106356001)(6512007)(22452003)(105586002)(102836004)(22906009)(217873001);DIR:OUT;SFP:1102;SCL:1;SRVR:DM5PR2101MB1093;H:DM5PR2101MB1032.namprd21.prod.outlook.com;FPR:;SPF:None;LANG:en;PTR:InfoNoRecords;MX:1;A:1; received-spf: None (protection.outlook.com: microsoft.com does not designate permitted sender hosts) x-microsoft-antispam-message-info: cHIpSHExcMYCXg271ID6xJZqH0WjCCw+Rrw2xJ4XnSlbbMtSzsGXYK70qTUz1wYs1kgqRq3U5VGOmT20ne9z7FigOrd46bl4B7RtuoOTcgWqij3mK0nrthUUDFcRMgm0N/iJYZPCHlU77WMKimK0LOevwPiqSNZrD63ds3Gqe2b1cSRJnXc1vlrI5QCnNTGg8WlbUqZT3P9OHbvaactI+ef4nNqRzPPrq7eRmt9Mp1lxVRgkNtd43x5o35rAI8cCRAucd6pwYtjnlNmgTjZWwNHrpiQXw3uH0ABi+D9m1yBAEpOcnQgsABcSMSKzr0Ghw9jANinB3xrocelwUzvqWA== spamdiagnosticoutput: 1:99 spamdiagnosticmetadata: NSPM Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 X-OriginatorOrg: microsoft.com X-MS-Exchange-CrossTenant-Network-Message-Id: 256c58ad-4d8d-41fb-365e-08d58db36b05 X-MS-Exchange-CrossTenant-originalarrivaltime: 19 Mar 2018 16:05:41.9743 (UTC) X-MS-Exchange-CrossTenant-fromentityheader: Hosted X-MS-Exchange-CrossTenant-id: 72f988bf-86f1-41af-91ab-2d7cd011db47 X-MS-Exchange-Transport-CrossTenantHeadersStamped: DM5PR2101MB1093 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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 --- kernel/pid.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/kernel/pid.c b/kernel/pid.c index b17263be9082..5fe7cdb6d05f 100644 --- a/kernel/pid.c +++ b/kernel/pid.c @@ -322,8 +322,10 @@ struct pid *alloc_pid(struct pid_namespace *ns) } =20 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; + } } =20 get_pid_ns(ns); --=20 2.14.1