Received: by 2002:ad5:474a:0:0:0:0:0 with SMTP id i10csp651554imu; Fri, 11 Jan 2019 06:50:22 -0800 (PST) X-Google-Smtp-Source: ALg8bN5uDItbZ4GUUH/f38RUL8ffFAfg7V8qiII7R8I3EWU87NjUBjbZzQaAjMt6r5luyve6aONe X-Received: by 2002:a63:5664:: with SMTP id g36mr11292206pgm.313.1547218222757; Fri, 11 Jan 2019 06:50:22 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1547218222; cv=none; d=google.com; s=arc-20160816; b=XwB1x6bFGuXutitdhsj2666ntHvl0rb3nxNsl5Z0dwFrwuPk3fYQKYpJJlMn0FrdoI KZ49RQq7VvEUTzADC8ppzLWgT/a6yS9MK+HOPp7dsrMw/qqNLJBrIaUJDTgIHc9Xuix2 4EjOfWzHY53t9jGacb1iHwE9aFKAsMT1z+gTLnJQ1Ga/5i55Z7OhrqHMtKMVHfiLM4WJ tck8u4eo43GS3PrRHWKmk+vZIxwEz5s2bRryMF9ItFFC9O/txGzRYGd8a2YBtxStrqJ2 8maY4EzXRenWStS6roVLJPhOq8Y2uolTDEBQ+5rhoy1J5crwQlS2fjX8NeCgJnwPT+/g Jw4A== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=8jFF9nZfWZHAy4RfMk4hTd9eHNOq06HLKyAXudDB5FA=; b=FIve4LExwL8zt2bclA8fLF3xteFxkm0JzqjBpQEBV/EqHkTjvpc0yFC9wDnUlRXrwj UZHG8p/nbxSNb5HFZv2N7cWfMy750AuWd5OF8pKtMGHhwqw02S13yMmStKSwU36Guntu 8GuVVKtTXKOMWHJjS54KsV5Qfxhi/qcbFkBOWYlNwZAXoqufZTtN7yxY01A+UWM5IkPG 9YNLXd1ZnmDIjETXU4NMgfO9wRDEDqtYVN1nlFH01oVmtKtdlWyKguS1m/Ec8Wi96Mt0 Q/pf0/MutphAMirb2HlzGKkH8x3n5Ow1LqzWcmE6VF4b1Nm3lVBhTZe+SoBojgFt5Wzw 3JgA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b="U0zWScB/"; 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 e4si8419694pgl.570.2019.01.11.06.50.07; Fri, 11 Jan 2019 06:50:22 -0800 (PST) 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=@kernel.org header.s=default header.b="U0zWScB/"; 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 S2404165AbfAKOm2 (ORCPT + 99 others); Fri, 11 Jan 2019 09:42:28 -0500 Received: from mail.kernel.org ([198.145.29.99]:35186 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2404157AbfAKOm0 (ORCPT ); Fri, 11 Jan 2019 09:42:26 -0500 Received: from localhost (5356596B.cm-6-7b.dynamic.ziggo.nl [83.86.89.107]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 0FAA520872; Fri, 11 Jan 2019 14:42:24 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1547217745; bh=XywuONYUbvnpLPhto4LEM6fqvo8oSzWFxY/v/QPWoPA=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=U0zWScB/H1cd+Qv2ouZBjHcQ8E553G7NHZ4ajRqpDMC0bl/7uAsTKjQIwjYycZkP8 anxfMEpjYsPbhYhls+HIyDS4Pqets5AnsOASVsgwDs5rqxkmOg2Z6Bv9nxyc/YtEtg anz/3JAnNyLg36pNYmMb0pgO7Q38BKCFsiWN21hk= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Matthew Wilcox , "Eric W. Biederman" , Oleg Nesterov , Linus Torvalds Subject: [PATCH 4.20 25/65] Fix failure path in alloc_pid() Date: Fri, 11 Jan 2019 15:15:11 +0100 Message-Id: <20190111131059.825870605@linuxfoundation.org> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20190111131055.331350141@linuxfoundation.org> References: <20190111131055.331350141@linuxfoundation.org> User-Agent: quilt/0.65 X-stable: review X-Patchwork-Hint: ignore MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 4.20-stable review patch. If anyone has any objections, please let me know. ------------------ From: Matthew Wilcox commit 1a80dade010c7a7f4885a4c4c2a7ac22cc7b34df upstream. The failure path removes the allocated PIDs from the wrong namespace. This could lead to us inadvertently reusing PIDs in the leaf namespace and leaking PIDs in parent namespaces. Fixes: 95846ecf9dac ("pid: replace pid bitmap implementation with IDR API") Cc: Signed-off-by: Matthew Wilcox Acked-by: "Eric W. Biederman" Reviewed-by: Oleg Nesterov Signed-off-by: Linus Torvalds Signed-off-by: Greg Kroah-Hartman --- kernel/pid.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) --- a/kernel/pid.c +++ b/kernel/pid.c @@ -233,8 +233,10 @@ out_unlock: out_free: spin_lock_irq(&pidmap_lock); - while (++i <= ns->level) - idr_remove(&ns->idr, (pid->numbers + i)->nr); + while (++i <= ns->level) { + upid = pid->numbers + i; + idr_remove(&upid->ns->idr, upid->nr); + } /* On failure to allocate the first pid, reset the state */ if (ns->pid_allocated == PIDNS_ADDING)