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 4063D1F1932; Mon, 2 Mar 2026 09:46:41 +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=1772444802; cv=none; b=B6p+db+pHjaL8+Xxau3rQPHPAgFNPrPBXv3F7OVUmclGfXrvpWWNYoHK2rhvOzlA+EQRNrcAzaQjkCFokQq6AKgJHoQIDEHnocSsFlB+vFo+Wy0c1oDgHE3H3AoFmFy+PnTZsbT4QeraEU4yKGD3cQYS+AhCj+EEDXgCGtQQQJ0= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1772444802; c=relaxed/simple; bh=8wFnx3X4NMytZXbi1Mnp6003sE19tT03Vwn1QWGE/uY=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=Q340G3OibYjNJHmRu97BhCbIj65J6Rq4DPqh72VbXkN1h3ovHdLxlI93/I83oVbkLnkuxR23XSyWC/xnHEBA4U28bO3W67Hg9JgkNOxXLYcgi42AfXn0Wek59U1bvKFrt10d1Z7/4imiMJIKGddeM7pNxt/w49ekw3/1a5mLRrY= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=qlHx7zde; 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="qlHx7zde" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 423A6C19423; Mon, 2 Mar 2026 09:46:39 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1772444801; bh=8wFnx3X4NMytZXbi1Mnp6003sE19tT03Vwn1QWGE/uY=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=qlHx7zdeQ/hBJTs6DoMfuclnuE7usfSzVkHN2qMzfRttktKjdSC6uPjYMwVduF9Xb gemQV9HWAfbzfCOwpxYx5urx2++PFZJB1kmrPqWVPTcWl9aVLQI/6CMdyQjdDAvmRz 8X4u2jBKOaNsfttvy5Sd4mh8J8xRW5yTlT5MR6PnbpU9cRv0qNhDBh4NLbU8XereEu 5HUXp4PftYXfpIX6ZnhFYH52qV+LFwb+dq3E9tKcz7wf1iKEgh+GzC7V2TA7c9EmdR P7jFLmAC5aszbn1J0/4Y7Ibh8invYfciKq3qp8Sbr7vIqFP9vk949Mkv5pWjVUUFd4 +HaULYgIpdVjw== Date: Mon, 2 Mar 2026 10:46:36 +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: <20260302-begehbar-kanister-9801d1198abf@brauner> References: <20260220-work-bpf-namespace-v1-0-866207db7b83@kernel.org> <20260220-work-bpf-namespace-v1-1-866207db7b83@kernel.org> <20260227-nullnummer-eisdiele-08db4c8fe99e@brauner> 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: On Fri, Feb 27, 2026 at 08:38:48AM -0800, Song Liu wrote: > On Fri, Feb 27, 2026 at 2:28 AM Christian Brauner wrote: > [...] > > > > > > 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. > > Good point on having ns_common initialized. Besides inum, we > should also pass ns_type and ops into the hook. But why? The struct ns_common is already fully initialized when it is passed to bpf_lsm_namespace_alloc() including ops, inum, ns_type etc. > > OTOH, shall we have the hook before proc_alloc_inum()? With > this change, the hook can block the operation before it causes > any contention on proc_inum_ida. IOW, how about we have: I think that contention is meaningless and I'd rather have struct ns_common fully set up so that all fields can be accessed. > > @@ -71,6 +71,10 @@ int __ns_common_init(struct ns_common *ns, u32 > ns_type, const struct proc_ns_ope > ns_debug(ns, ops); > #endif > > + ret = bpf_lsm_namespace_alloc(ns, inum); > + if (ret) > + return ret; > + > if (inum) > ns->inum = inum; > else > > With this change, ns is already initialized, except the inum. > > WDYT? > > Thanks, > Song > > > The containing namespace my already have to rollback a bunch of stuff > > anyway.