From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id D88153A6405 for ; Tue, 24 Feb 2026 16:10:14 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=170.10.133.124 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1771949416; cv=none; b=Vd1lQbZS1TZRjsOu47Fsyf5xNdc+nYxmVHpdN7+cKKuRhKoet0lerjqHuXwYvdfWzUHzZYPju6la4Kg919/JD87oHJklUDNPA6ACBhp+qNcQlsGaizHbtS77SUXRNdbTwLUl5sUcoOIuYASI01Ahx9DrxJe1ZtUCEbZ4ZVTauZ0= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1771949416; c=relaxed/simple; bh=oA1X4OjKB0GfvTlrIm3AnrrrJwuKWQdjYIEZey6owkk=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=kVKSKwMGDXIsnIM1SAyJMri9vP867M6aTE1l5FPWzKdH1qFpvrFT9XUuGDVXeNgARp/I8W8KN7vAzOT+SyGRT+VUHIItM6RaT+4pVc93QGq2jgHVGRnSkaLZaoPKAo2C8Cp5f/+s1IRl0Li8Kw52d5arb1v5XEQQ5iYuVVWDVv0= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=redhat.com; spf=pass smtp.mailfrom=redhat.com; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b=Yb+kTu7T; arc=none smtp.client-ip=170.10.133.124 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=redhat.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=redhat.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="Yb+kTu7T" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1771949413; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=oA1X4OjKB0GfvTlrIm3AnrrrJwuKWQdjYIEZey6owkk=; b=Yb+kTu7TqBVN5apHGFMP/dOLpupltZm2p0VVm+txyhtMiKrrnYdNLczfZzqTq1Z0XE4mDx zlVzcGsWNKaGcOk8qfkS2acGdGgHn2sgAA0/1SPwq0LM4pKWUd90fNP0IaWCVmITJY0FhB 3Uh4rRvnK4+2RqDn8vm/4EHqcz/16nk= Received: from mx-prod-mc-08.mail-002.prod.us-west-2.aws.redhat.com (ec2-35-165-154-97.us-west-2.compute.amazonaws.com [35.165.154.97]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-590-NxIo-czBMU2UDEDhw7H02g-1; Tue, 24 Feb 2026 11:10:08 -0500 X-MC-Unique: NxIo-czBMU2UDEDhw7H02g-1 X-Mimecast-MFC-AGG-ID: NxIo-czBMU2UDEDhw7H02g_1771949405 Received: from mx-prod-int-08.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-08.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.111]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mx-prod-mc-08.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id DB74C1800464; Tue, 24 Feb 2026 16:10:04 +0000 (UTC) Received: from fedora (unknown [10.44.32.38]) by mx-prod-int-08.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with SMTP id E12E21800361; Tue, 24 Feb 2026 16:09:57 +0000 (UTC) Received: by fedora (nbSMTP-1.00) for uid 1000 oleg@redhat.com; Tue, 24 Feb 2026 17:10:04 +0100 (CET) Date: Tue, 24 Feb 2026 17:09:56 +0100 From: Oleg Nesterov To: Andrei Vagin Cc: Pavel Tikhomirov , Christian Brauner , Shuah Khan , Kees Cook , Andrew Morton , David Hildenbrand , Ingo Molnar , Peter Zijlstra , Juri Lelli , Vincent Guittot , Jan Kara , Aleksa Sarai , Kirill Tkhai , Alexander Mikhalitsyn , Adrian Reber , linux-kernel@vger.kernel.org, linux-mm@kvack.org, linux-kselftest@vger.kernel.org Subject: Re: [PATCH v2 1/2] pid_namespace: allow opening pid_for_children before init was created Message-ID: References: <20260223200254.4104651-1-ptikhomirov@virtuozzo.com> <20260223200254.4104651-2-ptikhomirov@virtuozzo.com> <4de06792-d8ea-4f2e-848d-0dfccdb64253@virtuozzo.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: X-Scanned-By: MIMEDefang 3.4.1 on 10.30.177.111 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.