linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Oleg Nesterov <oleg@redhat.com>
To: Adrian Reber <areber@redhat.com>
Cc: Christian Brauner <christian.brauner@ubuntu.com>,
	Eric Biederman <ebiederm@xmission.com>,
	Pavel Emelyanov <ovzxemul@gmail.com>,
	Jann Horn <jannh@google.com>,
	Dmitry Safonov <0x7f454c46@gmail.com>,
	Rasmus Villemoes <linux@rasmusvillemoes.dk>,
	linux-kernel@vger.kernel.org, Andrei Vagin <avagin@gmail.com>,
	Mike Rapoport <rppt@linux.ibm.com>,
	Radostin Stoyanov <rstoyanov1@gmail.com>
Subject: Re: [PATCH v8 1/2] fork: extend clone3() to support setting a PID
Date: Wed, 13 Nov 2019 14:42:06 +0100	[thread overview]
Message-ID: <20191113134206.GA4320@redhat.com> (raw)
In-Reply-To: <20191113080301.1197762-1-areber@redhat.com>

On 11/13, Adrian Reber wrote:
>
> @@ -175,23 +187,47 @@ struct pid *alloc_pid(struct pid_namespace *ns)
>  
>  	for (i = ns->level; i >= 0; i--) {
>  		int pid_min = 1;

Well, this is really minor but again, pid_min is only used in the "else"
branch below, you can move this declaration there.

> +
> +		if (set_tid_size) {
> +			tid = set_tid[ns->level - i];
> +			if (tid < 1 || tid >= pid_max)
> +				return ERR_PTR(-EINVAL);
> +			/* Also fail if a PID != 1 is requested and no PID 1 exists */
> +			if (tid != 1 && !tmp->child_reaper)
> +				return ERR_PTR(-EINVAL);
> +			if (!ns_capable(tmp->user_ns, CAP_SYS_ADMIN))
> +				return ERR_PTR(-EPERM);
> +		}
>  
>  		idr_preload(GFP_KERNEL);
>  		spin_lock_irq(&pidmap_lock);
>  
> -		/*
> -		 * init really needs pid 1, but after reaching the maximum
> -		 * wrap back to RESERVED_PIDS
> -		 */
> -		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 (tid) {
> +			nr = idr_alloc(&tmp->idr, NULL, tid,
> +				       tid + 1, GFP_ATOMIC);
> +			/*
> +			 * If ENOSPC is returned it means that the PID is
> +			 * alreay in use. Return EEXIST in that case.
> +			 */
> +			if (nr == -ENOSPC)
> +				nr = -EEXIST;
> +			set_tid_size--;
                        ^^^^^^^^^^^^^^^
May I ask you to move this decrement into the "if (set_tid_size)" block above?

Oleg.


      parent reply	other threads:[~2019-11-13 13:42 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-11-13  8:03 [PATCH v8 1/2] fork: extend clone3() to support setting a PID Adrian Reber
2019-11-13  8:03 ` [PATCH v8 2/2] selftests: add tests for clone3() Adrian Reber
2019-11-13 12:35   ` Christian Brauner
2019-11-13 11:50 ` [PATCH v8 1/2] fork: extend clone3() to support setting a PID Christian Brauner
2019-11-13 13:42 ` Oleg Nesterov [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20191113134206.GA4320@redhat.com \
    --to=oleg@redhat.com \
    --cc=0x7f454c46@gmail.com \
    --cc=areber@redhat.com \
    --cc=avagin@gmail.com \
    --cc=christian.brauner@ubuntu.com \
    --cc=ebiederm@xmission.com \
    --cc=jannh@google.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux@rasmusvillemoes.dk \
    --cc=ovzxemul@gmail.com \
    --cc=rppt@linux.ibm.com \
    --cc=rstoyanov1@gmail.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).