From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-qk1-f173.google.com (mail-qk1-f173.google.com [209.85.222.173]) (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 AFD3D3CB2D5 for ; Thu, 16 Jul 2026 21:55:18 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.222.173 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1784238920; cv=none; b=dXA2EHn6eBw+y+UaJb6wSmplbxIqJgjR8RpT0c1niIxLkZomx9pqV3djlA/Kc4bf52O9Mv0XFbltVU4gGMQbGaCFrQFRbhrPnFzeHkXgbDf/K7cXJRPGDexZiSoorhG8kjR2eLghuYwswLxq+FKrhfXoqdnCuhj7QIDifUiWDdM= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1784238920; c=relaxed/simple; bh=uWW3GfZkGp+lrAWSyuTcF5Zh9hE2jXE38Cfkjb1RSLU=; h=Date:Message-ID:MIME-Version:Content-Type:From:To:Cc:Subject: References:In-Reply-To; b=Gc9fjwnPfAQHehe53bOS55lIV9drJRyPhQBXYEcwL/ef25L27C4k7BKZ4pFusM8zRkwVhMSjOaIPHsfdk1QEezRpbKx5sXyEqOOmgiR5a8Zeq66ys/7U11Zp6gcbo/eg7w2a9tnrP6xM8VsHR8eO8mwUDNpw0VRXwTQKebnsY94= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=paul-moore.com; spf=pass smtp.mailfrom=paul-moore.com; dkim=pass (2048-bit key) header.d=paul-moore.com header.i=@paul-moore.com header.b=LopdPcmo; arc=none smtp.client-ip=209.85.222.173 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=paul-moore.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=paul-moore.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=paul-moore.com header.i=@paul-moore.com header.b="LopdPcmo" Received: by mail-qk1-f173.google.com with SMTP id af79cd13be357-92c7a0a701aso541077685a.3 for ; Thu, 16 Jul 2026 14:55:18 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=paul-moore.com; s=google; t=1784238917; x=1784843717; darn=vger.kernel.org; h=in-reply-to:references:subject:cc:to:from:content-transfer-encoding :content-type:mime-version:message-id:date:from:to:cc:subject:date :message-id:reply-to:content-type; bh=hamHHJXfASh+6XcrqxU1lBmvfcJaMCZ67kq55CEfGa4=; b=LopdPcmoRurptvM5M2R5CGRt66yyrgl20/08udhEDom6qsvRSZpdY/2KR0Gnf9Kadz 5JGCamoHhCXi57n/rQSVn887IDLcOT01EOnEATWq4Vb98jXXaev1p0R8SKbQzSkEL1Sx 8pV9zwVQXhLzKezJiLvD2yayqlf7sTsjsjdrWC5A3vA5aM1aYiuBNb2IBqdifJzfjM0r WPEvo/dUCr8G+aP0NsFIDdzK6UOFtUu3aIOMMBpNFrWM08NoDVLkPIPOS+Nfa78pqTYu yYnD71U4V0Dxerd2XIRZPek5ZfEDXSvX94Nn4HH3EtIlpqEqoxfyr39QpqjBXaFRUowo KsSw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1784238917; x=1784843717; h=in-reply-to:references:subject:cc:to:from:content-transfer-encoding :content-type:mime-version:message-id:date:x-gm-gg :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to :content-type; bh=hamHHJXfASh+6XcrqxU1lBmvfcJaMCZ67kq55CEfGa4=; b=fvyBBW/Zwzm6+mczpr/rN7HPeioLR24jahJrK0eE47nXKCLK/XU5xGuck22Xy3I297 IWob5tR2yU2RHfrqP5lYbBD6khNsSv1YW9EWI0+QOJCnLYL0sJcKqSU+VgI0PYDzg5CN 3+0zHoQq1+vdFo3Sl42NyOAxcdov6QwC9fF43N5rMYDTumh0NY0tsCddoZeSxEiIc4BM SuNt3u0U6Igt1zAp0bTy9CfoKb07UCUCjQTM66qphf96w8XKrAFxlgfs3SlDMQDHsA68 OxTqtf2S8/8DkMF0SXBbvkVNPLFWbWXrbkJ7fLe7jryE9gvZVxBKZ5OEtJjpeUG2dWDB 01zg== X-Forwarded-Encrypted: i=1; AHgh+Rr4f/p97MGzY2CB/xLeT9X04r6cg/RsYe6VbyWRg8T518urKuTLef0KkXmVCGnmThL8zl9/vuMtX/yzrQ82nlKtUAadvvo=@vger.kernel.org X-Gm-Message-State: AOJu0YypTjn8NYMEAzuhH/nMzILpu+OOiB/0WhqOd+jTJSaQ/norG1xt d/998hkWjLpm9QDJ0gAeSlVXHK3g3tcqzhhTnrxxMIivxG/6w9Gp+mkWVbTT0CSvGQ== X-Gm-Gg: AfdE7ck/VpcKzvU1AHxscuyd+J5ja+HnQSrpxyYHSOzcQwR6C7Gf71BOx6MKq80sOmF xav3UW+59YeYSXjIENsV8CoyH3oR2zCV2sOT8RJjJPZG7aLyIgFfw4lYc4H1R6YUif3twyzS0c8 wAq5syNzfbxQTyLFtqTWk/mkr/vIA0Ve1kU2FlOWcPfMvwn1cmFP4MTGpXgKxMw4EslbAmsKFpL Yr8kgajMnVxtIvGbuXQA1unB2Q7Y61NFef2Wm69MGmmwJvV3JuL1fuh6d+oZF0HLwdyWeyFtfcj vVzpB2fI3OLrKgqwbgAJQCtexHBIqFjvxzs1DmrEHOSuT1ah8aS9JhFVD1oBWu39wd1hcgNiM2u 0drPBSy4WpbgO34P0Y9xg8ut/eWo6IMXknNuXSBOhhHkpY1ofeW4f701t243s1d10V/xggRzGOW mAN65TnenhT6Y69vn6dbWKBymlXpf1o6Lg9Gq7BToFp2L5dd0= X-Received: by 2002:a05:620a:372b:b0:92e:c118:18df with SMTP id af79cd13be357-93083dedef6mr1775888085a.86.1784238917538; Thu, 16 Jul 2026 14:55:17 -0700 (PDT) Received: from localhost (pool-71-126-255-178.bstnma.fios.verizon.net. [71.126.255.178]) by smtp.gmail.com with ESMTPSA id af79cd13be357-92ee5b86276sm2097959785a.11.2026.07.16.14.55.15 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 16 Jul 2026 14:55:15 -0700 (PDT) Date: Thu, 16 Jul 2026 17:55:15 -0400 Message-ID: Precedence: bulk X-Mailing-List: linux-security-module@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-Mailer: pstg-pwork:20260715_1900/pstg-lib:20260715_1853/pstg-pwork:20260715_1900 From: Paul Moore To: David Windsor , Alexei Starovoitov , Daniel Borkmann , Andrii Nakryiko , Martin KaFai Lau , Eduard Zingerman , Song Liu , Yonghong Song , John Fastabend , KP Singh , Jiri Olsa , Kumar Kartikeya Dwivedi , Emil Tsalapatis , Matt Bobrowski , James Morris , "Serge E . Hallyn" , Casey Schaufler , Stephen Smalley , Ondrej Mosnacek , Mimi Zohar , Roberto Sassu , Dmitry Kasatkin , Eric Snowberg , Alexander Viro , Christian Brauner , Jan Kara , Shuah Khan Cc: bpf@vger.kernel.org, linux-security-module@vger.kernel.org, linux-fsdevel@vger.kernel.org, linux-integrity@vger.kernel.org, selinux@vger.kernel.org, linux-kselftest@vger.kernel.org, linux-kernel@vger.kernel.org, David Windsor Subject: Re: [PATCH v5 2/3] bpf: add bpf_init_inode_xattr kfunc for atomic inode labeling References: <20260708000956.46138-3-dwindsor@gmail.com> In-Reply-To: <20260708000956.46138-3-dwindsor@gmail.com> On Jul 7, 2026 David Windsor wrote: > > Add bpf_init_inode_xattr() kfunc for BPF LSM programs to atomically set > xattrs via the inode_init_security hook using security_lsmxattr_add(). > The hook now passes its xattr state as a single struct lsm_xattrs > object, which the kfunc takes directly. > > This kfunc is only callable from inode_init_security; the verifier > rejects attempts to call it elsewhere. > > A previous attempt [1] required a kmalloc string output protocol for > the xattr name. Since commit 6bcdfd2cac55 ("security: Allow all LSMs to > provide xattrs for inode_init_security hook") [2], the xattr name is no > longer allocated; it is a static constant. > > Link: https://kernsec.org/pipermail/linux-security-module-archive/2022-October/034878.html [1] > Link: https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/commit/?id=6bcdfd2cac55 [2] > Suggested-by: Song Liu > Signed-off-by: David Windsor > --- > fs/bpf_fs_kfuncs.c | 36 ++++++++++++++++++++++++++++++++++++ > 1 file changed, 36 insertions(+) > > diff --git a/fs/bpf_fs_kfuncs.c b/fs/bpf_fs_kfuncs.c > index 768aca2dc0f0..ad0025f2264a 100644 > --- a/fs/bpf_fs_kfuncs.c > +++ b/fs/bpf_fs_kfuncs.c > @@ -11,7 +11,9 @@ > #include > #include > #include > +#include > #include > +#include > > __bpf_kfunc_start_defs(); > > @@ -374,6 +376,39 @@ __bpf_kfunc struct inode *bpf_real_inode(struct dentry *dentry) > return d_real_inode(dentry); > } > > +/** > + * bpf_init_inode_xattr - set an xattr on a new inode from inode_init_security > + * @xattrs: inode_init_security xattr state from the hook context > + * @name__str: xattr name (e.g., "bpf.file_label") > + * @value_p: dynptr containing the xattr value > + * > + * Only callable from lsm/inode_init_security programs. > + * > + * Return: 0 on success, negative error on failure. > + */ > +__bpf_kfunc int bpf_init_inode_xattr(struct lsm_xattrs *xattrs, > + const char *name__str, > + const struct bpf_dynptr *value_p) > +{ > + struct bpf_dynptr_kern *value_ptr = (struct bpf_dynptr_kern *)value_p; > + const void *value; > + u32 value_len; > + > + if (!name__str) > + return -EINVAL; > + if (strncmp(name__str, XATTR_BPF_LSM_SUFFIX, > + sizeof(XATTR_BPF_LSM_SUFFIX) - 1)) > + return -EPERM; > + > + value_len = __bpf_dynptr_size(value_ptr); > + value = __bpf_dynptr_data(value_ptr, value_len); > + if (!value) > + return -EINVAL; > + > + return security_lsmxattr_add(xattrs, LSM_ID_BPF, name__str, value, > + value_len); > +} I'm sorry David, now that I'm seeing this function again, especially with the LSM specific bits extracted into a LSM function, this absolutely belongs somewhere under security/. It's only callable from within a BPF LSM callback and all it does outside of some BPF pointer boilerplate is call right back into a LSM helper function. If the BPF maintainers aren't willing to accept that, then we will all need to find another way. > __bpf_kfunc_end_defs(); > > BTF_KFUNCS_START(bpf_fs_kfunc_set_ids) > @@ -385,6 +420,7 @@ BTF_ID_FLAGS(func, bpf_get_file_xattr, KF_SLEEPABLE) > BTF_ID_FLAGS(func, bpf_set_dentry_xattr, KF_SLEEPABLE) > BTF_ID_FLAGS(func, bpf_remove_dentry_xattr, KF_SLEEPABLE) > BTF_ID_FLAGS(func, bpf_real_inode, KF_SLEEPABLE | KF_RET_NULL) > +BTF_ID_FLAGS(func, bpf_init_inode_xattr) > BTF_KFUNCS_END(bpf_fs_kfunc_set_ids) > > static int bpf_fs_kfuncs_filter(const struct bpf_prog *prog, u32 kfunc_id) > -- > 2.53.0 -- paul-moore.com