Received: by 2002:a25:c205:0:0:0:0:0 with SMTP id s5csp6973936ybf; Fri, 6 Mar 2020 08:01:51 -0800 (PST) X-Google-Smtp-Source: ADFU+vskgInHXAzye06GE6j6W0IObGJDtkfC7m1+hZnZ31yHHKbIZZk7VhNmwwCtBchICjZvJdjL X-Received: by 2002:a9d:336:: with SMTP id 51mr3112940otv.202.1583510511526; Fri, 06 Mar 2020 08:01:51 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1583510511; cv=none; d=google.com; s=arc-20160816; b=cuIXMBlYg4kQ+7jqAxQQGHYev0l98bJZd4P6zfK3MADjaVXmeRpYnQ+oAVdu13BeRE g8qBEYoMuXbvZDZcESde/7LF4fSAZwXpF4GGdBt25LJwQ+pxKpg3TniugGDnC3Kad0tA EwbZ+H25EDVfXnuXcEBg82TTMKeE2fIfrC87LXpfqK6qGWcP3i4clzzZcInNETdNMHCp w6JDz5rEtSJvfnwbWkhegqTiVpl5c/bkmyVenjT/55Sz0I/HfETGOZXmAJZCkdykrHd7 9q0bPmkXDQcRUIAbhyojaDhreWaGV5HLLNwYOMmiawsHMflUMzxH79NzNsre4J3yyj3S a5pw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:in-reply-to:content-disposition :mime-version:references:message-id:subject:cc:to:from:date; bh=FBYgynUimnloq1zJu6gT2ehBKJ16PJRF9uG6mm5axOE=; b=Vl+52rqP7vtnOGsoxONozFus9iDFRyL/RB7quSom+B3K1ubfgZpZ9G2J1Wi6lQ1JmJ kU+hkwDNaI7f7DyUy1UYZ77s1Ym1wtMYyn3Lt9B9aA1mOTX6Y/Rn98GeRWxYGVWU0zYT JrE3tBWYFc3nTJgjQnMJ+Zx4UKDeCueC9kFhfVFNxQW2wdv0Q+nw2xA7QIT6Xb1U0gmy pMz6SG2rVENB0L79wgikBCK4hbGCBRmsOhpcbLPJ3jHRsbGRf8jpso/Q9YAPu68RsGyv SKOZO2KAgMoWYvR0ogt3QqJyN0C8pBz3QZusFpdXnxkZzD8cgCRMdnS9H6dclitwXDJB ldLw== 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 j20si1681568oii.168.2020.03.06.08.01.38; Fri, 06 Mar 2020 08:01:51 -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; 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 S1726866AbgCFQAv (ORCPT + 99 others); Fri, 6 Mar 2020 11:00:51 -0500 Received: from youngberry.canonical.com ([91.189.89.112]:59320 "EHLO youngberry.canonical.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725935AbgCFQAu (ORCPT ); Fri, 6 Mar 2020 11:00:50 -0500 Received: from [88.128.88.76] (helo=wittgenstein) by youngberry.canonical.com with esmtpsa (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.86_2) (envelope-from ) id 1jAFP0-0005xk-KP; Fri, 06 Mar 2020 16:00:47 +0000 Date: Fri, 6 Mar 2020 17:00:20 +0100 From: Christian Brauner To: minyard@acm.org Cc: linux-kernel@vger.kernel.org, Corey Minyard , stable@vger.kernel.org, Adrian Reber , Oleg Nesterov , Dmitry Safonov <0x7f454c46@gmail.com>, Andrei Vagin Subject: Re: [PATCH] pid: Fix error return value in some cases Message-ID: <20200306160020.orvb3frtsu2yvfe3@wittgenstein> References: <20200306152001.30442-1-minyard@acm.org> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline In-Reply-To: <20200306152001.30442-1-minyard@acm.org> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Fri, Mar 06, 2020 at 09:20:01AM -0600, minyard@acm.org wrote: > From: Corey Minyard > > Recent changes to alloc_pid() allow the pid number to be specified on > the command line. If set_tid_size is set, then the code scanning the > levels will hard-set retval to -EPERM, overriding it's previous -ENOMEM > value. > > After the code scanning the levels, there are error returns that do not > set retval, assuming it is still set to -ENOMEM. > > In the first place, pid_ns_prepare_proc() returns its own error, just > use that. > > In the second place: > > if (!(ns->pid_allocated & PIDNS_ADDING)) > goto out_unlock; > > a return value of -ENOMEM is probably wrong, since that means that the > namespace is in deletion while this happened. -EINVAL is probably a > better choice. > > Fixes: 49cb2fc42ce4 "fork: extend clone3() to support setting a PID" > Signed-off-by: Corey Minyard > Cc: # 5.5 > Cc: Adrian Reber > Cc: Christian Brauner > Cc: Oleg Nesterov > Cc: Dmitry Safonov <0x7f454c46@gmail.com> > Cc: Andrei Vagin > Cc: Christian Brauner > --- > kernel/pid.c | 7 +++++-- > 1 file changed, 5 insertions(+), 2 deletions(-) > > diff --git a/kernel/pid.c b/kernel/pid.c > index 0f4ecb57214c..1921f7f4b236 100644 > --- a/kernel/pid.c > +++ b/kernel/pid.c > @@ -248,7 +248,8 @@ struct pid *alloc_pid(struct pid_namespace *ns, pid_t *set_tid, > } > > if (unlikely(is_child_reaper(pid))) { > - if (pid_ns_prepare_proc(ns)) > + retval = pid_ns_prepare_proc(ns); > + if (retval) > goto out_free; > } > > @@ -261,8 +262,10 @@ struct pid *alloc_pid(struct pid_namespace *ns, pid_t *set_tid, > > upid = pid->numbers + ns->level; > spin_lock_irq(&pidmap_lock); > - if (!(ns->pid_allocated & PIDNS_ADDING)) > + if (!(ns->pid_allocated & PIDNS_ADDING)) { > + retval = -EINVAL; > goto out_unlock; > + } > for ( ; upid >= pid->numbers; --upid) { > /* Make the PID visible to find_pid_ns. */ > idr_replace(&upid->ns->idr, pid, upid->nr); Thanks for the patch. We definitely regressed the ENOMEM return value case. But both of the changes here are userspace visible and break assumptions. So I'd rather just ensure that ENOMEM is returned in both cases like it was before. In fact, ENOMEM is documented on the pid_namespace man page so we can't really change it. Btw, this is the same problem as we had with: commit 35f71bc0a09a45924bed268d8ccd0d3407bc476f Author: Michal Hocko Date: Thu Apr 16 12:47:38 2015 -0700 fork: report pid reservation failure properly So please restore just restore the old behavior. Can you add --base to your next commit, please? Makes it easier for me to pick up. Thanks! Christian