Received: by 2002:a25:e7d8:0:0:0:0:0 with SMTP id e207csp1679596ybh; Sun, 8 Mar 2020 10:11:13 -0700 (PDT) X-Google-Smtp-Source: ADFU+vsrMRFPfLkw7iBXosCKEjHpkFwQYGVZbMp9i8El+VqfLsenvuGv/GsebOxE2FZA/pPV8SGD X-Received: by 2002:a9d:ed1:: with SMTP id 75mr10957596otj.229.1583687473759; Sun, 08 Mar 2020 10:11:13 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1583687473; cv=none; d=google.com; s=arc-20160816; b=vkt4N1wHg8+ZEh6bTBXdBuDDBQjpccgtaCOYTIpuRwArb5oIkOtAJSq0DM7tR05A7I V5d5bAFQYykMCxWceYXoYe8swZ0sYiFvuu/neX3LMKBkqSJyd1O4vZiyvcAU8PP9/Rbv 0Dgm3aFzWQzfTiGQQErq4lmeLwviZfPQUZf6pGpLPJuddk7uGUJbMw9iGVZWHi0Bh2h9 jNFr+qKGijFqBC5aRj3Df+Mz/GZdVVGWNBtDXmJQafuJz0XkXAmULPG2hawpQm236p0X TtV5fGhShFjSHWTsiyuTdsq29AUDdxnAtiRrqHzF437ylh3drDaY14rB5QLOWwzUpxo3 uW3g== 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 :references:in-reply-to:message-id:date:subject:cc:to:from; bh=mKWyBk2yOkd5R8wK7ef3EW1x9OQLQjLmKSKRbLNICoY=; b=TqU4q0mvDaQtTzzMK8wjOUneLkb6dpWnWf5aZVmvC+Jl3GJhoNiY4lg8tAuElN6dIT wecwzuv9Bx6uNWKZ54hOVsuY4sIKUNfF9TR1NqIZuZyNE1nd9qJdZvkKYJhKLpaaHYqj 22poDd/Rw0bqYsHu+jZ5tmB4920sO8oOA7P25lVMoEE5rQ73U8oIAbWRolo5fTac4qWV lTW5Ih594cb8mlxQMxGIXHIU4UxJ83npIkDUP2chAkOXBw3hTEhcyCs2IVZ+hFlAbGBi LE98c8PTgbhO0yd/AqbpX0hT/sYg6f/p7lact71GkYyjvh9/XP6wFKzaaaKnv7pKxYcb gMaw== 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 i18si5004988otk.245.2020.03.08.10.11.02; Sun, 08 Mar 2020 10:11:13 -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 S1726442AbgCHRKR (ORCPT + 99 others); Sun, 8 Mar 2020 13:10:17 -0400 Received: from youngberry.canonical.com ([91.189.89.112]:56421 "EHLO youngberry.canonical.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726411AbgCHRKQ (ORCPT ); Sun, 8 Mar 2020 13:10:16 -0400 Received: from ip5f5bf7ec.dynamic.kabel-deutschland.de ([95.91.247.236] helo=wittgenstein.fritz.box) by youngberry.canonical.com with esmtpsa (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.86_2) (envelope-from ) id 1jAzRN-0007Bs-6v; Sun, 08 Mar 2020 17:10:13 +0000 From: Christian Brauner To: cminyard@mvista.com Cc: 0x7f454c46@gmail.com, areber@redhat.com, avagin@gmail.com, christian.brauner@ubuntu.com, linux-kernel@vger.kernel.org, minyard@acm.org, oleg@redhat.com Subject: [PATCH] pid: make ENOMEM return value more obvious Date: Sun, 8 Mar 2020 18:10:07 +0100 Message-Id: <20200308171007.3155138-1-christian.brauner@ubuntu.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20200307131136.GD2847@minyard.net> References: <20200307131136.GD2847@minyard.net> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org The alloc_pid() codepath used to be simpler. With the introducation of the ability to choose specific pids in 49cb2fc42ce4 ("fork: extend clone3() to support setting a PID") it got more complex. It hasn't been super obvious that ENOMEM is returned when the pid namespace init process/child subreaper of the pid namespace has died. As can be seen from multiple attempts to improve this see e.g. [1] and most recently [2]. We regressed returning ENOMEM in [3] and [2] restored it. Let's add a comment on top explaining that this is historic and documented behavior and cannot easily be changed. The unconditional initialization of retval when declaring it can be removed since it is initialized on ever failure path in the loop and unconditionaly set to ENOMEM right after it. [1]: 35f71bc0a09a ("fork: report pid reservation failure properly") [2]: b26ebfe12f34 ("pid: Fix error return value in some cases") [3]: 49cb2fc42ce4 ("fork: extend clone3() to support setting a PID") Signed-off-by: Christian Brauner --- kernel/pid.c | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/kernel/pid.c b/kernel/pid.c index 19645b25b77c..be43122eb876 100644 --- a/kernel/pid.c +++ b/kernel/pid.c @@ -165,7 +165,7 @@ struct pid *alloc_pid(struct pid_namespace *ns, pid_t *set_tid, int i, nr; struct pid_namespace *tmp; struct upid *upid; - int retval = -ENOMEM; + int retval; /* * set_tid_size contains the size of the set_tid array. Starting at @@ -247,6 +247,14 @@ struct pid *alloc_pid(struct pid_namespace *ns, pid_t *set_tid, tmp = tmp->parent; } + /* + * ENOMEM is not the most obvious choice especially for the case + * where the child subreaper has already exited and the pid + * namespace denies the creation of any new processes. But ENOMEM + * is what we have exposed to userspace for a long time and it is + * documented behavior for pid namespaces. So we can't easily + * change it even if there were an error code better suited. + */ retval = -ENOMEM; if (unlikely(is_child_reaper(pid))) { base-commit: b26ebfe12f34f372cf041c6f801fa49c3fb382c5 -- 2.25.1