On 02/24, Andrei Vagin wrote:
>
> On Tue, Feb 24, 2026 at 5:38 AM Pavel Tikhomirov
> >
> > This check here is more for the concurrent alloc_pid() case. When one 
> > process
> > in alloc_pid() successfully allocated the pid and than, for instance, hit 
> > the
> > pidfs_add_pid() error and is going to free_pid(), but the pid 1 is remains 
> > yet
> > allocated from idr and the cursor is on 2 at the moment. At the same time 
> > the
> > concurrent process may get to alloc_pid(), and will see cursor on 2, it 
> > should
> > not be able to create a process as this process will get pid 2 and will be
> > created before init.
> >
> > And in general (non concurrent case) it makes sense to only allow 
> > allocating 1,
> > for the first process.
>
> In this case, there is likely a race condition. Two alloc_pid() calls
> can run concurrently,
> where idr_get_cursor() returns 0 in both instances.

This code runs with pidmap_lock held.

But,

> I think this
> check needs to
> be moved after idr_alloc_cyclic() to verify the actual value that was 
> allocated.

Agreed, see other emails in this thread.

Oleg.


Reply via email to