From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-ed1-f44.google.com (mail-ed1-f44.google.com [209.85.208.44]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 95C7C299A8F for ; Tue, 24 Mar 2026 05:27:38 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.208.44 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1774330060; cv=none; b=Z+ngmXko6aaO+lH/W/i1M18d5En36bEMkpIfPpQhI9SwE5VYpj8xmpkD5lxXU+QwlgqMhMx6nC4aSm18pEgPQh1vj/VcIWKYKUIVSwVZQQ4wAGacOQPFRFgZ6aX6WHFrF9sPnhVWNz6JuOLXsVNTvkoeqdMI2Vudb/BHVpsWlyU= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1774330060; c=relaxed/simple; bh=k9xXt2aJzUPiqvUhimxBVZN49fbykRnjPG0sd1v/0U4=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=ddZrvKF+7fseL1SFFQ8vgHzyBrGxMqJJaHi/CMIBCUAsofXYeyuFbZRXh/YvCoI/zPuj3jVHry3Bhh7O974l2RbzSw6XPb/eRkvzab/0iXAo3ru4v7qkuL/MEc289JpMfHEHXRpySZqpkOeGYCqP0h3Q5tZ/Z2m9z5InUVIZWGA= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com; spf=pass smtp.mailfrom=google.com; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b=P5I5O1ep; arc=none smtp.client-ip=209.85.208.44 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=google.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="P5I5O1ep" Received: by mail-ed1-f44.google.com with SMTP id 4fb4d7f45d1cf-66132b22182so1128014a12.2 for ; Mon, 23 Mar 2026 22:27:38 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20251104; t=1774330057; x=1774934857; darn=vger.kernel.org; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:from:to:cc:subject:date:message-id:reply-to; bh=jiqRu/0YnxP0Ivlp2p8FBB56aP3f+r4HN/z/TyoIUYU=; b=P5I5O1epz1REhqe3wkaraxZCMUzEaduOofdhWKQf/e48d4bM+iINzpqWzG0c+jNy66 BsKxc/HLw1tpVZkXmdb9X/K54Q0WovpJaTzG+si0Ac4MkT3F+to/JGqABFwkRO7n4Roo Y3gYhBcGz8Zvj9XXHtnh9zB+B8rw1T0r7E8Zu71UqCBbgkG7QyoTdg9nv3nLfbahXnP7 CqDXNX5qJAgbuJLprF3O4t2JvPPgY4J3A4pgaqv6bP7OycEMoq1snYmHCCdRZ3WCrrmL YiKJyAcqNKsa9MxeIT5VRqafaQ79xniRuFWF4+q7VoVEM/NRFZ7je2pGs+9JNF5KzNLO K8Zw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1774330057; x=1774934857; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:x-gm-gg:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=jiqRu/0YnxP0Ivlp2p8FBB56aP3f+r4HN/z/TyoIUYU=; b=PK1C1BoudS1U14OGbG2icl3iPhUopIxnUm/mXa0T9XGinpKmf2BoAeCHgSsL7CnvbQ 80w3r0glOgkFQNAexzV7ioFbhOKwGSLFzCfjfZvQXfRSHe9R22SUWUl6GKYmJ2/98XeA A4wnoZrdjCJMNi+ftCX9eCRuymjXwpMImTQfV6RnWGqk6ZEkiFcFpI8vY69xp2lLkrIk HxOSDpwx4KXNf/u6P9Sm6uuCVPx4QwUL3oGknXzctPA2nYMB5W762JlX/pPPY3lgRDnJ Z9z+BGuUtJretRkrriJXJUaZ0uDBWLP12xoQhflkyit01fPU/aRbwkzF4rY74+cFIzYP ueQw== X-Forwarded-Encrypted: i=1; AJvYcCVxlx+2NrMRE1hBx96fE9OdtDLvG9Vs309kk1EPH9o08tkE/1wAkNhsDCcaBWZUh6/Bq3gCoCXEVH2IjYg=@vger.kernel.org X-Gm-Message-State: AOJu0YyP+NRml72fRdwPpQ4BeWYtsryulKW8RbGOMqWvUPVmPn9BJw3i yEQHAx1CbeHrq06SAoOxid1hc24fiul6YhnKNXIqhZqzQkowwTCmeCzD1AHv6N+NRw== X-Gm-Gg: ATEYQzy1oMZG0vC3OOnHRPo1DcQtv8bJ1HEg0Df1ap//Xjow6a/avll1uZrgUa92v29 z5+ySnpQMIieCygU9cbtkk+yf9BNo0JZs9ZvLeHyMrorFjs2Dm/HtIO5gK+/TQQwxCKyxxyABGe k75NtjHIqi/rTMDXVXRHyvPR8cFAvmViKnvZxq/ZOseTb3NSaFtGjZfzcWwWNYawFGHwvUmiQ/Y mHjLCVXwmCA+kNEJ3TUSEXcO0+1FxkZYXhW0FRuUlNaDsyzzSfTiYbP0Rc5+sdeYlR/sM8XCpIN 8EPt2CYbK34Gcaz0BLGkQ9V9xQtQWcrp9nURHvAZExx5j5OQnm1AXookMC1P5nEkt4IIrNKIJlv YGpQugnb2F9ULen8cgwcBfg0VoMulHL+MZb/flfLit39kTeMA8Q4iyfmmcNaS3d7O5G5JOPU6A7 sJhGVCSMf5gan3qL5H0IIsZ5rnvKfMxs7qffeYJzGA2OyoMx8MN4IH9/K1HxNc9xI= X-Received: by 2002:a17:906:782:b0:b95:2b77:75b6 with SMTP id a640c23a62f3a-b982f26ed28mr772701566b.19.1774330056535; Mon, 23 Mar 2026 22:27:36 -0700 (PDT) Received: from google.com (93.50.90.34.bc.googleusercontent.com. [34.90.50.93]) by smtp.gmail.com with ESMTPSA id a640c23a62f3a-b9832f8c177sm592296266b.15.2026.03.23.22.27.35 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 23 Mar 2026 22:27:35 -0700 (PDT) Date: Tue, 24 Mar 2026 05:27:32 +0000 From: Matt Bobrowski To: Christian Brauner 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: References: <20260220-work-bpf-namespace-v1-0-866207db7b83@kernel.org> <20260220-work-bpf-namespace-v1-1-866207db7b83@kernel.org> <20260227-krass-abzug-a2e42720db80@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=us-ascii Content-Disposition: inline In-Reply-To: <20260227-krass-abzug-a2e42720db80@brauner> On Fri, Feb 27, 2026 at 03:33:21PM +0100, Christian Brauner wrote: > On Tue, Feb 24, 2026 at 01:35:11PM +0000, Matt Bobrowski wrote: > > On Fri, Feb 20, 2026 at 01:38:29AM +0100, Christian Brauner wrote: > > > Add the three namespace lifecycle hooks and make them available to bpf > > > lsm program types. This allows bpf to supervise namespace creation. I'm > > > in the process of adding various "universal truth" bpf programs to > > > systemd that will make use of this. This e.g., allows to lock in a > > > program into a given set of namespaces. > > > > > > Signed-off-by: Christian Brauner > > > --- > > > include/linux/bpf_lsm.h | 21 +++++++++++++++++++++ > > > kernel/bpf/bpf_lsm.c | 25 +++++++++++++++++++++++++ > > > kernel/nscommon.c | 9 ++++++++- > > > kernel/nsproxy.c | 7 +++++++ > > > 4 files changed, 61 insertions(+), 1 deletion(-) > > > > > > diff --git a/include/linux/bpf_lsm.h b/include/linux/bpf_lsm.h > > > index 643809cc78c3..5ae438fdf567 100644 > > > --- a/include/linux/bpf_lsm.h > > > +++ b/include/linux/bpf_lsm.h > > > @@ -12,6 +12,9 @@ > > > #include > > > #include > > > > > > +struct ns_common; > > > +struct nsset; > > > + > > > #ifdef CONFIG_BPF_LSM > > > > > > #define LSM_HOOK(RET, DEFAULT, NAME, ...) \ > > > @@ -48,6 +51,11 @@ void bpf_lsm_find_cgroup_shim(const struct bpf_prog *prog, bpf_func_t *bpf_func) > > > > > > int bpf_lsm_get_retval_range(const struct bpf_prog *prog, > > > struct bpf_retval_range *range); > > > + > > > +int bpf_lsm_namespace_alloc(struct ns_common *ns); > > > +void bpf_lsm_namespace_free(struct ns_common *ns); > > > +int bpf_lsm_namespace_install(struct nsset *nsset, struct ns_common *ns); > > > + > > > int bpf_set_dentry_xattr_locked(struct dentry *dentry, const char *name__str, > > > const struct bpf_dynptr *value_p, int flags); > > > int bpf_remove_dentry_xattr_locked(struct dentry *dentry, const char *name__str); > > > @@ -104,6 +112,19 @@ static inline bool bpf_lsm_has_d_inode_locked(const struct bpf_prog *prog) > > > { > > > return false; > > > } > > > + > > > +static inline int bpf_lsm_namespace_alloc(struct ns_common *ns) > > > +{ > > > + return 0; > > > +} > > > +static inline void bpf_lsm_namespace_free(struct ns_common *ns) > > > +{ > > > +} > > > +static inline int bpf_lsm_namespace_install(struct nsset *nsset, > > > + struct ns_common *ns) > > > +{ > > > + return 0; > > > +} > > > #endif /* CONFIG_BPF_LSM */ > > > > > > #endif /* _LINUX_BPF_LSM_H */ > > > diff --git a/kernel/bpf/bpf_lsm.c b/kernel/bpf/bpf_lsm.c > > > index 0c4a0c8e6f70..f6378db46220 100644 > > > --- a/kernel/bpf/bpf_lsm.c > > > +++ b/kernel/bpf/bpf_lsm.c > > > @@ -30,10 +30,32 @@ __weak noinline RET bpf_lsm_##NAME(__VA_ARGS__) \ > > > #include > > > #undef LSM_HOOK > > > > > > +__bpf_hook_start(); > > > + > > > +__weak noinline int bpf_lsm_namespace_alloc(struct ns_common *ns) > > > +{ > > > + return 0; > > > +} > > > + > > > +__weak noinline void bpf_lsm_namespace_free(struct ns_common *ns) > > > +{ > > > +} > > > > I'm wondering how you foresee this hook functioning in a scenario > > where the BPF LSM program is attached to this new hook point, although > > with its attachment type being set to BPF_LSM_CGROUP instead of > > BPF_LSM_MAC? You probably wouldn't want to utilize something like > > BPF_LSM_CGROUP for your specific use case, but as things stand > > currently I don't believe there's anyhthing preventing you from using > > BPF_LSM_CGROUP with a hook like bpf_lsm_namespace_free(). > > Oh, I very much would like this to be attachable to cgroups. > > > Notably, the BPF_LSM_CGROUP infrastructure is designed to execute BPF > > programs based on the cgroup of the currently executing task. There > > could be some surprises if the bpf_lsm_namespace_free() hook were to > > ever be called from a context (e.g, kworker) other than the one > > specified whilst attaching the BPF LSM program with type > > BPF_LSM_CGROUP. > > But isn't this then a generic problem? What about: > > # RCU callbacks > security_cred_free > security_task_free > security_inode_free_security_rcu > security_bpf_prog_free > security_xfrm_policy_free_security > security_msg_queue_free_security > security_shm_free_security > security_sem_free_security > security_audit_rule_free > security_bdev_free_security > security_sk_free_security > > # Workqueues > security_bpf_map_free > security_bpf_token_free > security_sb_free_security > security_file_free_security > security_file_release > security_xfrm_state_free_security > > ignoring sofirq/hardirq for now. I'd need to take a another deep look, but yeah, from what I can tell this is a broader general issue for BPF LSM programs which happen to also make use of the BPF_LSM_CGROUP attachment type. > So the only real problem I can see is that someone wants to do something > from a *_free() hook that isn't actually freeing but actual policy based > on the cgroup of @current? I find that hard to believe tbh. > Fwiw, bpf_lsm_namespace_free() is classified as untrusted because at > that point the outer namespace might already be blown away > partially. Effectively alloc() and free() hooks are mostly > notification mechanisms of creation/destructions. If you want to do > actual policy you might have to defer it until an actual operation > is done.