Received: by 2002:a25:b794:0:0:0:0:0 with SMTP id n20csp5765621ybh; Wed, 7 Aug 2019 11:03:08 -0700 (PDT) X-Google-Smtp-Source: APXvYqxEJrzLj37/q+oGvz6hyzgfxFF3iGKndqW8VjJxF42SizExtjh3ceXRpqAmP8uasc20O2Z9 X-Received: by 2002:a17:902:7782:: with SMTP id o2mr9462321pll.12.1565200987954; Wed, 07 Aug 2019 11:03:07 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1565200987; cv=none; d=google.com; s=arc-20160816; b=nO+1QLEH7ucFELZmY2RjpfqkE0CrNglPbgKhHibn+T0Q709peI9kewp2qyScWksxqG 3LVSZ+AU2WL4A1OtJ8c7C6LkwmoL4lKY8cNz4D5onpmzjlMkSMUBWtJ5Q6ajsWeixR7U 1KpjK/KDJoFpKQpiLLeP6L7qAUmgydC3gFeDb8/r1aMLkUBZPNF9VB/TvoXP5kVS9Wqn ioR3tE0VW3/vKPt+sTTcG43+1MINxS/OiHmriPZ11xCa+M+2O5dcyq6ox+ujga6vjjGn 0K/ceIRQWzg8E/Uok3woG1X0dxR4+n2kwRfoG/i2ODyCv5RsNQn36VBJyTDUOKmqSXNC gqlw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:user-agent:in-reply-to :content-disposition:mime-version:references:message-id:subject:cc :to:from:date; bh=p2Nl3oXhRK0hx85rVxDbyvybhHsKS7ssN8KYjpQdLeQ=; b=SMWEZc9cYuNJ70DqN43HNHnvweYcoum0CkdYeNVbkOxRr/ZH6orQSngiuGXeBpDJhR ONE74lWqh/k6vzZivSgt5IYFjFnHa0dnT+gXpuUMb9C/Nx6DMvD9CEzTze7XP5Enn6iv qs83i3GKbVkp2apbC4+Xv6VAK2iC8+8ekf4hzShl8vPVBdMYxsqq0H0Pk6W+yLk3zpDY bb4WgXAG2LXGOTuQZkFGzyS3ta4pURcJlYRMBjmb/hRfHH91OceCLVkOjK7LwKXJmZ+M prODjOyUZR6vFTSVO+WajR9vHjTPPQsjdFYyLarglC/2tdLRhYoj86yJ/SudZ52h4aCY +QyQ== 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 k193si47349249pge.330.2019.08.07.11.02.50; Wed, 07 Aug 2019 11:03:07 -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 S2388694AbfHGSAu (ORCPT + 99 others); Wed, 7 Aug 2019 14:00:50 -0400 Received: from youngberry.canonical.com ([91.189.89.112]:58680 "EHLO youngberry.canonical.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2387953AbfHGSAu (ORCPT ); Wed, 7 Aug 2019 14:00:50 -0400 Received: from c-67-180-61-213.hsd1.ca.comcast.net ([67.180.61.213] helo=wittgenstein) by youngberry.canonical.com with esmtpsa (TLS1.0:RSA_AES_256_CBC_SHA1:32) (Exim 4.76) (envelope-from ) id 1hvQEp-0007lv-G6; Wed, 07 Aug 2019 18:00:39 +0000 Date: Wed, 7 Aug 2019 20:00:34 +0200 From: Christian Brauner To: Oleg Nesterov Cc: Adrian Reber , Eric Biederman , Pavel Emelianov , Jann Horn , Dmitry Safonov <0x7f454c46@gmail.com>, linux-kernel@vger.kernel.org, Andrei Vagin , Mike Rapoport , Radostin Stoyanov Subject: Re: [PATCH v3 1/2] fork: extend clone3() to support CLONE_SET_TID Message-ID: <20190807180033.lucbhob6wfunp5xf@wittgenstein> References: <20190806191551.22192-1-areber@redhat.com> <20190807142609.GC24112@redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline In-Reply-To: <20190807142609.GC24112@redhat.com> User-Agent: NeoMutt/20180716 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Wed, Aug 07, 2019 at 04:26:10PM +0200, Oleg Nesterov wrote: > On 08/06, Adrian Reber wrote: > > > > +struct pid *alloc_pid(struct pid_namespace *ns, int set_tid) > > { > > struct pid *pid; > > enum pid_type type; > > @@ -186,12 +186,35 @@ struct pid *alloc_pid(struct pid_namespace *ns) > > if (idr_get_cursor(&tmp->idr) > RESERVED_PIDS) > > pid_min = RESERVED_PIDS; > > > > - /* > > - * Store a null pointer so find_pid_ns does not find > > - * a partially initialized PID (see below). > > - */ > > - nr = idr_alloc_cyclic(&tmp->idr, NULL, pid_min, > > - pid_max, GFP_ATOMIC); > > + if (set_tid) { > > + /* > > + * Also fail if a PID != 1 is requested > > + * and no PID 1 exists. > > + */ > > + if ((set_tid >= pid_max) || ((set_tid != 1) && > > + (idr_is_empty(&tmp->idr)))) { > > too many parentheses ;) this is purely cosmetic, up to you, but to me > > if (set_tid >= pid_max || > (set_tid != 1 && idr_is_empty(&tmp->idr))) { > > looks a bit more readable. > > > > + spin_unlock_irq(&pidmap_lock); > > + retval = -EINVAL; > > + goto out_free; > > This doesn't look right, you need idr_preload_end() before goto out_free. > > But I'd suggest to simply do > > nr = -EINVAL; > if (set_tid < pid_max && > (set_tid != 1 || idr_is_empty(&tmp->idr))) > nr = idr_alloc(&tmp->idr, NULL, set_tid, > set_tid + 1, GFP_ATOMIC); > > ... > > this is more robust. That all sounds reasonable to me.