Received: by 2002:ac0:a5a6:0:0:0:0:0 with SMTP id m35-v6csp1772463imm; Thu, 27 Sep 2018 02:12:03 -0700 (PDT) X-Google-Smtp-Source: ACcGV62WkA4s4Mv8FXTD29Z8ZYdT0oAOKf0nETVc9+JJy5Y1EbGidy5BRezpKt+ggc/rOJ/ZkHx/ X-Received: by 2002:a17:902:28a4:: with SMTP id f33-v6mr9902666plb.297.1538039522995; Thu, 27 Sep 2018 02:12:02 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1538039522; cv=none; d=google.com; s=arc-20160816; b=S+2QJTe/nd70UY10UdLCM4mfY3eUtnSPL9d8c0HOCBD33i8rZcQCwsNhQTPN/V01Od fbM9uDX5vkNAWq3ErTlErKHVsQ0H0V+4myGMAN1QMthMD01LRrcy+1K4hOb7omrvZ4VK KDMfvWQPUZIyvB1b5ZUwvEJINvg/jBp0RPwm/1f650rCFS6psK79cCK1p33VXC98zidn zeoxZ1vd4rZTq4SwVrte7N4FXN5b5sOXTASg6BCcYDmP2dgfh185BsLTRdMbYV60rtuL OJGiv6JKjSXDmdrvAemdPwJyAdg75oEl+lAJuTXv24uh3RdsGFse+v0wVfjpVUEGy1i/ YYHQ== 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; bh=kWmhi/1e/Vqu8AopP0eLDu9KEPAsNm5flCctm8C13j4=; b=eFkcCy9f4dCPNMZJQ24fXYAWNCWfBFvny0n/GqcJG1y5MKYQ28giEi0srCfNYZlsjZ PyeB65Q9lA8DWqqsA/TFPpqLUYaWjfg9LMTFUdMELi1HuMG2UxpjLdEPJkLzUZtJdAGM bDWwmbHFf9QGwWU+uAmBnqFgLM9SwEpdNFv8N55IRc64eqY0ag223FkkX8Q4hdBcR5iZ 6b0kOIn9aFkLnQ6mM7GpXsBCFJHhnQUzM7eQoeXBwH19qw+wUiPqtDDH0I6lkuXG2ro3 wqXfihiflnXSX5plSZS3Jp7LNWSB36R6+kjn0zUMmZAtMEov9Q4AMJkGH42LTNILHpJN Ez7Q== 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 t19-v6si1777158pfm.152.2018.09.27.02.11.48; Thu, 27 Sep 2018 02:12:02 -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 S1728486AbeI0P2Q (ORCPT + 99 others); Thu, 27 Sep 2018 11:28:16 -0400 Received: from mail.linuxfoundation.org ([140.211.169.12]:55198 "EHLO mail.linuxfoundation.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727690AbeI0P2Q (ORCPT ); Thu, 27 Sep 2018 11:28:16 -0400 Received: from localhost (ip-213-127-77-73.ip.prioritytelecom.net [213.127.77.73]) by mail.linuxfoundation.org (Postfix) with ESMTPSA id DB2D51117; Thu, 27 Sep 2018 09:10:59 +0000 (UTC) From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, KJ Tsanaktsidis , Andrew Morton , Michal Hocko , Gargi Sharma , Rik van Riel , Oleg Nesterov Subject: [PATCH 4.18 50/88] fork: report pid exhaustion correctly Date: Thu, 27 Sep 2018 11:03:31 +0200 Message-Id: <20180927090306.894709743@linuxfoundation.org> X-Mailer: git-send-email 2.19.0 In-Reply-To: <20180927090300.631426620@linuxfoundation.org> References: <20180927090300.631426620@linuxfoundation.org> User-Agent: quilt/0.65 X-stable: review 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.18-stable review patch. If anyone has any objections, please let me know. ------------------ From: KJ Tsanaktsidis commit f83606f5eb007adc33bc8541ede00590f477bdeb upstream. Make the clone and fork syscalls return EAGAIN when the limit on the number of pids /proc/sys/kernel/pid_max is exceeded. Currently, when the pid_max limit is exceeded, the kernel will return ENOSPC from the fork and clone syscalls. This is contrary to the documented behaviour, which explicitly calls out the pid_max case as one where EAGAIN should be returned. It also leads to really confusing error messages in userspace programs which will complain about a lack of disk space when they fail to create processes/threads for this reason. This error is being returned because alloc_pid() uses the idr api to find a new pid; when there are none available, idr_alloc_cyclic() returns -ENOSPC, and this is being propagated back to userspace. This behaviour has been broken before, and was explicitly fixed in commit 35f71bc0a09a ("fork: report pid reservation failure properly"), so I think -EAGAIN is definitely the right thing to return in this case. The current behaviour change dates from commit 95846ecf9dac ("pid: replace pid bitmap implementation with IDR AIP") and was I believe unintentional. This patch has no impact on the case where allocating a pid fails because the child reaper for the namespace is dead; that case will still return -ENOMEM. Link: http://lkml.kernel.org/r/20180903111016.46461-1-ktsanaktsidis@zendesk.com Fixes: 95846ecf9dac ("pid: replace pid bitmap implementation with IDR AIP") Signed-off-by: KJ Tsanaktsidis Reviewed-by: Andrew Morton Acked-by: Michal Hocko Cc: Gargi Sharma Cc: Rik van Riel Cc: Oleg Nesterov Cc: Signed-off-by: Andrew Morton Signed-off-by: Greg Kroah-Hartman --- kernel/pid.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) --- a/kernel/pid.c +++ b/kernel/pid.c @@ -195,7 +195,7 @@ struct pid *alloc_pid(struct pid_namespa idr_preload_end(); if (nr < 0) { - retval = nr; + retval = (nr == -ENOSPC) ? -EAGAIN : nr; goto out_free; }