lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [<thread-prev] [day] [month] [year] [list]
Message-ID: <20191113134206.GA4320@redhat.com>
Date:   Wed, 13 Nov 2019 14:42:06 +0100
From:   Oleg Nesterov <oleg@...hat.com>
To:     Adrian Reber <areber@...hat.com>
Cc:     Christian Brauner <christian.brauner@...ntu.com>,
        Eric Biederman <ebiederm@...ssion.com>,
        Pavel Emelyanov <ovzxemul@...il.com>,
        Jann Horn <jannh@...gle.com>,
        Dmitry Safonov <0x7f454c46@...il.com>,
        Rasmus Villemoes <linux@...musvillemoes.dk>,
        linux-kernel@...r.kernel.org, Andrei Vagin <avagin@...il.com>,
        Mike Rapoport <rppt@...ux.ibm.com>,
        Radostin Stoyanov <rstoyanov1@...il.com>
Subject: Re: [PATCH v8 1/2] fork: extend clone3() to support setting a PID

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.

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ