From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (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 EF8DC395DB4; Fri, 27 Feb 2026 10:28:50 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1772188131; cv=none; b=GLfBkwx0th86eHjfphq4EdTVxFvMRUlX/2u93OnnD5qqbPegLF8WjDDz1m6vAWGFpUGOb1u2RIKlGaCEkwVnfW+ogk7NXvFr0nSJhcD3okd9EzFNXL45Z3qg+nYvUgE8WmWn/D9EvJYDQbfi8oRHYoKQvBWx49OE6m+1inRLBqs= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1772188131; c=relaxed/simple; bh=/dKIc7p2rllISBSzFmr+GpDUadFf+dhQdPn3a5R3SfA=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=qYemovp554QCK0uv7RibpQWJDjl3Pd82Dk9dPdNCtNjKeUpOs7xQOWDPzSt+MxDfj8AH5Ho5C1jFlsBxVRvyeWPTlXNj7p4glWV86fiCwJaXxzI87wD8URKv/nCa1twh3OEAts+tB3/ScsTUIZcCpcdx9snA6Pv4Ch93xvfi9V4= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=XnN1h7rM; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="XnN1h7rM" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 8A3F5C116C6; Fri, 27 Feb 2026 10:28:47 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1772188130; bh=/dKIc7p2rllISBSzFmr+GpDUadFf+dhQdPn3a5R3SfA=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=XnN1h7rM75DYnJ1YhbgrfUaNWpn3AMnaE7hGYWZV1XkrcFOncfo9nS0DPQaLLMwsJ npDSoeBptsSlvHwWZYQWBZdt/Z+1zZxxphB+bBZrbW9TL9ZGhFopsyrEddGh6o3cOI eYoRUPcQfEn4Hlx+RItqVYNucWje/ol9pwn/hdqAMbPT2SX8Ss4nEfEsN1zxgHbZK+ U0xFH9SxH4ms1YsPlDPtwLLFgt1g0LO4UiiK6ijdQZ5mSUxwBK1tB2D9g6MriHbw+4 uFOw87nA2zJ+HnN50N50zwyxjUp8K1v+URAEy0QtX59jZzI86TFrl3LknUcqm1hweF siqh0lnv5JZkw== Date: Fri, 27 Feb 2026 11:28:44 +0100 From: Christian Brauner To: Song Liu Cc: Alexei Starovoitov , Daniel Borkmann , Andrii Nakryiko , Martin KaFai Lau , Tejun Heo , KP Singh , bpf@vger.kernel.org, linux-kernel@vger.kernel.org, cgroups@vger.kernel.org, Lennart Poettering Subject: Re: [PATCH 1/4] ns: add bpf hooks Message-ID: <20260227-nullnummer-eisdiele-08db4c8fe99e@brauner> References: <20260220-work-bpf-namespace-v1-0-866207db7b83@kernel.org> <20260220-work-bpf-namespace-v1-1-866207db7b83@kernel.org> Precedence: bulk X-Mailing-List: cgroups@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: On Tue, Feb 24, 2026 at 03:04:43PM -0800, Song Liu wrote: > On Thu, Feb 19, 2026 at 4:38 PM Christian Brauner wrote: > [...] > > @@ -1,6 +1,7 @@ > > // SPDX-License-Identifier: GPL-2.0-only > > /* Copyright (c) 2025 Christian Brauner */ > > > > +#include > > #include > > #include > > #include > > @@ -77,6 +78,7 @@ int __ns_common_init(struct ns_common *ns, u32 ns_type, const struct proc_ns_ope > > ret = proc_alloc_inum(&ns->inum); > > if (ret) > > return ret; > > + > > /* > > * Tree ref starts at 0. It's incremented when namespace enters > > * active use (installed in nsproxy) and decremented when all > > @@ -86,11 +88,16 @@ int __ns_common_init(struct ns_common *ns, u32 ns_type, const struct proc_ns_ope > > atomic_set(&ns->__ns_ref_active, 1); > > else > > atomic_set(&ns->__ns_ref_active, 0); > > - return 0; > > + > > + ret = bpf_lsm_namespace_alloc(ns); > > + if (ret && !inum) > > + proc_free_inum(ns->inum); > > + return ret; > > } > > If we change the hook as > > bpf_lsm_namespace_alloc(ns, inum); > > We can move it to the beginning of __ns_common_init(). > This change allows blocking __ns_common_init() before > it makes any changes to the ns. Is this a better approach? I don't think it matters tbh. We have no control when exactly __ns_common_init() is called. That's up to the containing namespace. We can't rely on the namespace to have been correctly set up at this time. My main goal was to have struct ns_common to be fully initialized already so that direct access to it's field already makes sense. The containing namespace my already have to rollback a bunch of stuff anyway.