From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-qk1-f174.google.com (mail-qk1-f174.google.com [209.85.222.174]) (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 B299C3CB2F6 for ; Thu, 16 Jul 2026 21:55:18 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.222.174 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1784238920; cv=none; b=ue+BacMoUAJrv3KkCoBazQVLZAxlR0/+vgf/pQauShSE5raekanK2URTynNNpwpuP+3g5aFJOP0jphmLoWbP0kDfLoqTBXXWqrzrKo/glZNpu+a/RAyH563UOych8wcwfFP7lVuEsGSHc7phEwK7yVf2X6RiNPgvvAs43SnEPIg= 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=PpE/HJaf; arc=none smtp.client-ip=209.85.222.174 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="PpE/HJaf" Received: by mail-qk1-f174.google.com with SMTP id af79cd13be357-92e622cc874so505734185a.0 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=1784238918; x=1784843718; 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=PpE/HJafFiouJHLcU1ZWnrVhQRujkf8IEMy7Lk9nAny7dJ+tkCTicokEo4brKBQoaY MUAdQ7sGI8JnLmbXl0esEJrsmi52jFSWnFszjWh/NbVyudShs7N9gEAPogOc+YgcZd9Q Ljt5XsHyaq2yjAqBqRGfrwN4uX6eT5VWdwP8lX5WrVPGkuyTn4lSPse88fjV99k2OSUb B8WYP7rPyz/EJL4u5vMq2tkkFaCRYE12IEShjKiFnU5tZEVEswy/BS2PdAqLRh6EoG7s Z5L+blRnmZPHFfyT53FXYRNMIUlYIHVusnsC8aaBAZBQoi4dDHRJShK/86zO50mUIItR I9NQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1784238918; x=1784843718; 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=mJqnqI4iftGiWFhEgl6lQzzMDFcr/1uqpOm9s5Q0DEno/AWhM4au/Gu3m9tCnMtrtg FtBLBZcrb2ztweZxL6IRhWxFGY0WPLD1gp7RX5gKGImGUF6kS3wMGjScs9LvM8+HnBYe 7r7uxuJ3DBmu2pRHiYBS5EbXCsQQHZUL8sDDTL8xjHLmNFYlD2sSzcR+wvtc9++MQiR2 zgA6zWf2LGVQ3gn7zrkE7BzcKkkY7XpWOJp61P99wRzp0ROKAtKm5e2olw8YkKH6F7qx 7Czdm8JSItLdax95KhzupxjjHhJqaObskARpyxChew7w6tX0rUklsKCKt2HghIpmucQZ 2HSg== X-Forwarded-Encrypted: i=1; AHgh+RoCAdKGj+O3fQJbtMksWx1bM+5CfieYzIm1RSlAauFJM8rgy6Tvf1GOdqtC1jSwsVbDlI3VuLA3YrFW/I4=@vger.kernel.org X-Gm-Message-State: AOJu0YzBxwaNiqb1cJK2+AuiQRHt1l5sRl7LstKCPe9vPKQ3c59f8xuQ x0aTvuEnm25jLr8KkCRtzOJILzKJPKXHoKn0cMcLNJs6V5DofCYwJlQHCXC31EMQbQ== X-Gm-Gg: AfdE7cmS144TZXzoZWrgWYxKzKigH+XfFEHxLRGsbeCHYRE3fi8IKNqvfEQNku2YzQN x5axYnBWoVAHeP8dVb8mBG8z5JxFtBEvAaB5WNQCvv2J7vHHH388FHMt9ursEiQ1+VW2oFSpZWi 5zsWx7FHle0ugn3Rzn4P9lu4b1gAfqP5yDR+ZKSoJaFXBr3gPdGl5qhPtelzsWzTaxEN6OpUi/N tGmdmT9YrfA3oaDdT+J+Cww+sK8QsaIr9Tu1U7gsEYYl1jU8zYFf8lGkGeyuwU8/lT4IPsb5llg me5rsWs/UX4CUuvpMDv17/6MmAAiYkvmnJ930ahwEklP6GNy24WexEkgWiubNqbFegRoj3s7+AO QfAccr5/k2HTkYErpGDzgM04mxHcFZCbVt89m5EZ+3Kp6RHDs5wI/YfYS0JOfeePH6i6HlWawtx kG67heMf5ALfIOJRsbJaSbiCLuba25cR9f8sAu7BccHFioNlk= 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-kernel@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