From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=209.85.128.50 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796398987; b=LjtWTWb/LhQ9xECvE7I3T4JEGmofF/2KjomHfRUHYkNQFT6HjsXwhkgcUhRnGYViMQO8 dfxOWeTg3z/ksOHdGp1phL6NnvV7PjrfX5/ePw754GKqYuG5ikFKj6iOb45GUdzhw2G/d 46W3RYmsHZvO4Op/fvQ7T3+5TAZelHG8xEafD/mHdpTxawko3c6L6n6AyZJilqTIxmvkc NJS7b1hUotquXbV5ab2dU25L16FstWKVdTvuN4tLeipHxxA8F32dy1P/ysR4c4ZH5mQFu JQfPemHGrunLuc2E/zF/uTCJ4Sw/c6qLWpyAqydLtGpdEaBvjQQfSTVb+25t97yQI+Q== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796398987; h=DMARC-Filter:Received:DKIM-Signature:X-Google-DKIM-Signature: X-Forwarded-Encrypted:X-Gm-Message-State:X-Gm-Gg:X-Received:Received: From:To:Cc:Subject:Date:Message-ID:X-Mailer:In-Reply-To:References: MIME-Version:Content-Transfer-Encoding; bh=s1kytqHyW3NAtOi+ladnDJ0QouNCWDGMny3X8BxdHEg=; b=lWn4T/0+cXsU9FOGuOPGYY5iI1HQtLcn+2l1TaM76fXLrfE6o3WH5RQHqIXPjdnGNi2q GshW8XSdNUdEMOyO86yKMXLitVAfSFwbJOHmEBD+NYcx3ODLoouYFt8QDU0sbCpNuGUtn UT4bo6C+AOPuFFtaHXsycPZIQQvFWOAPjA9dmFleIfNlmh+qGs7RvYHOIVeKtoBn5sUlT gozsMfuesBY5hdf3lcuqFfisld9qtSIs9rZCeia5TKJ/GplSSY7YeNuZn/DpqqKV12kkq brHb+fidBjO6w4JubZnr22nX8FxQgndA/5M7WPcwYztGXQ/obve74kn5VYRjfYaV+Hw== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20260707 header.b=yJkshtzA; arc=none smtp.remote-ip=209.85.128.50 Received: from mail-wm1-f50.google.com (mail-wm1-f50.google.com [209.85.128.50]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits) key-exchange X25519 server-signature ECDSA (prime256v1) server-digest SHA256) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 8916160A260F for ; Fri, 4 Dec 2026 15:43:07 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org 8916160A260F Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20260707 header.b=yJkshtzA Received: by mail-wm1-f50.google.com with SMTP id 5b1f17b1804b1-4a5177d78c7so10806125e9.2 for ; Fri, 04 Dec 2026 07:43:07 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20260707; t=1796398986; x=1797003786; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to:content-type; bh=s1kytqHyW3NAtOi+ladnDJ0QouNCWDGMny3X8BxdHEg=; b=yJkshtzA8rVHwlCQquoTw5gE/H5ExTHdgUM6SntCoytvFFgF6Ot8eUHk7jhAPpdrAd G0m43GBWSthsS3Ih673pgWq9s61OojHCSy2mJCxb//RAHJ7O/r4JH62HO5/4y8JQWfHy CR+MfQuB9bgMbxZJorhJXRdBMI/arUzValruMwDXPzxeLP6uah8cAdxpYKnFP8SrhNV4 jZ73tZ567C23Y7qfDxqhS5Fe492u4sknLIDWr3uj7T8aHJ8sm11PEH4f4mEtcot9P3Lb gjUedG36FVn2GiGN/98vFoHXI47Qwllmcr6VWl9RlTRptKYcGq5Aj4p/dqKu6gAixhte HSyw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20260707; t=1796398986; x=1797003786; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-gg:x-gm-message-state:from :to:cc:subject:date:message-id:reply-to:content-type; bh=s1kytqHyW3NAtOi+ladnDJ0QouNCWDGMny3X8BxdHEg=; b=PiiIZaC/GlrU+fAaRR/guzq0hTTCZsSFtplV/SdWwanXyIgyrazto7uJt2xOam5e5W md+6hGnPLS3L/WEKtMbIxy+zX7fha3T7h5rp2pQ0IfY7VhV+FTzUENfpGGnk8qkZp0eo lgusCoqbbEvn93M08n4VVhRitNUIFqtu1r/HPK8RePPoULUSwIfDTXCXMnd8pIlKtgt3 PHGEKUGolIaRtIVASR5eOXW2lHnylRFU2AbvKGzwJYAldxH1Z9EnQjQCR9y0Rt9uuQCl rIMjG8RRKJGmZU0x4Mdia2KvNOVHKT0rWNOPTphEI8xwaupj+dnburXsztd/iw3C1zER hrtw== X-Forwarded-Encrypted: i=1; AL+hErHrf70vGuqyijCCaxsONfhIrXmFZAtYV7sBafLM/i7mK/ZuaDkTvKStkxDyqz8tU/oQ/fLCBGMC2hnjRB8=@vger.kernel.org X-Gm-Message-State: APuU4Z+YeLEDX9GBkpGMyOgdhgX5coUClP4Jg9Cl4jqCDiKkAwxW11bM fKLHRtaLZRq4J2NL/XFJ+B5BM3YiBPnF0chRpg58AciM5AG7IWs4ZFyC X-Gm-Gg: AZFdTZf0fH38S/bjaXw2sDtTF32tIuaIOwOu/oSvihV505Hk2Eh5zdnOvQx5G1glzkW 1I0dN+nWGNI+7u/RrckukaUCceJlTRESP8n6Xr0a/JFVUwf7l+3ZxZwN68H9S/Ggfjf8JuyRO3L VTcs1oP3ebUrWRvKmMmNRM5WMB/2i9sr+tWw9Kuhs6/bR1s6GAPqk8UDTk8nWPjYAqF4cvAw03a KsmPqan9tIaInrb5Rs2gAyjz3nqjrg1DbPp+URF5NyJlYLmBrbciDqHtXv/Ni7r/znKgqrNERQ3 pOTPY99L1SUI8zb/xVAPaIKItmHnhG6xoyz1GhP/0Q8vK7dOcdAWTyLI296LgyPtWfkL5P+AGo4 MwvA9WkMKbbQB5mwZ4/cs3jzpgSX3cZRQHKzpt2gaYpZBwFVIKtBlcJ4879GCd8v8wXyQCBtvMH 4iY2PiFvm5bbaznFTbBl6vYUB6xZa1uNuup4gwY1VcVlp8EctdG+7OsQ8TUtAnDJoJuQCUkLozk 6PJe7OBI5292+UQLdBwMApd8w7oXcyEpenS4UQCOMiCl9EywjzLQbRKuQEi5JdXUwa7Za9ybnND SCbunDK8+9NbvHr2R/iYn8HdVUDF5m9U36wKdVkaImr7Rhrqq8n4yJvzUaX0PmHW40af X-Received: by 2002:a05:600c:1f92:b0:4a2:c2b:a91b with SMTP id 5b1f17b1804b1-4bbeb850f9cmr48567245e9.10.1796398985966; Fri, 04 Dec 2026 07:43:05 -0800 (PST) Received: from localhost.localdomain ([2a04:ee41:4:b2de:1ac0:4dff:fe0f:3782]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-4bbea25ce51sm63147535e9.5.2026.12.04.07.43.04 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 04 Dec 2026 07:43:05 -0800 (PST) From: Anton Protopopov To: Alexei Starovoitov , Daniel Borkmann , Andrii Nakryiko , Eduard Zingerman , Kumar Kartikeya Dwivedi , Martin KaFai Lau , Song Liu , Yonghong Song , Jiri Olsa , Emil Tsalapatis , Ihor Solodrai , KP Singh , Matt Bobrowski , Alexander Viro , Christian Brauner , Jan Kara , Mimi Zohar , Roberto Sassu , bpf@vger.kernel.org, linux-integrity@vger.kernel.org, linux-fsdevel@vger.kernel.org, linux-kernel@vger.kernel.org Cc: Anton Protopopov Subject: [PATCH v2 bpf-next 5/6] bpf: Add a bpf_get_inode_xattr kfunc Date: Fri, 4 Dec 2026 15:54:35 +0000 Message-ID: <20261204155438.1413411-6-a.s.protopopov@gmail.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20261204155438.1413411-1-a.s.protopopov@gmail.com> References: <20261204155438.1413411-1-a.s.protopopov@gmail.com> X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 Content-Transfer-Encoding: 8bit The inode_create, inode_mkdir, inode_mknod, inode_symlink, inode_link and inode_rename hooks get the parent directory as an inode and the new entry as a dentry. To check a label of the directory, a program needs to read its xattr, but bpf_get_dentry_xattr() takes a dentry. The only dentry of the directory at hand is dentry->d_parent, and the verifier doesn't trust it. Making d_parent trusted would be wrong. It would be trusted on every hook, and many hooks don't hold the lock of the parent directory. For example, inode_getxattr and inode_readlink hold no lock at all. A concurrent rename can then move the dentry to another directory, and the old parent can be freed while a sleepable program still uses it. Add the bpf_get_inode_xattr() kfunc which reads an xattr of an inode through one of its dentries. Xattrs belong to the inode, but some filesystems like cifs build a path from the dentry. So take a hashed dentry with d_find_alias() if there is one. An unlinked file which is still open has none, so take any with d_find_any_alias() then, as inode_doinit_with_dentry() in SELinux does. The kfunc doesn't change xattrs, so the setters still get only the dentries passed to the hook, and d_inode_locked_hooks stays correct for them. Signed-off-by: Anton Protopopov --- fs/bpf_fs_kfuncs.c | 33 +++++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) diff --git a/fs/bpf_fs_kfuncs.c b/fs/bpf_fs_kfuncs.c index 6021e9f60ad2..4e2b371fd0b5 100644 --- a/fs/bpf_fs_kfuncs.c +++ b/fs/bpf_fs_kfuncs.c @@ -169,6 +169,38 @@ __bpf_kfunc int bpf_get_file_xattr(struct file *file, const char *name__str, return bpf_get_dentry_xattr(dentry, name__str, value_p); } +/** + * bpf_get_inode_xattr - get xattr of an inode + * @inode: inode to get xattr from + * @name__str: name of the xattr + * @value_p: output buffer of the xattr value + * + * Get xattr *name__str* of *inode* and store the output in *value_ptr*. + * The xattr is read through a hashed dentry of *inode* if it has one and + * through any dentry otherwise. + * + * For security reasons, only *name__str* with prefixes "user." or + * "security.bpf." are allowed. + * + * Return: length of the xattr value on success, -ENOENT if *inode* has + * no dentry, another negative value on error. + */ +__bpf_kfunc int bpf_get_inode_xattr(struct inode *inode, const char *name__str, + struct bpf_dynptr *value_p) +{ + struct dentry *dentry; + int ret; + + dentry = d_find_alias(inode); + if (!dentry) + dentry = d_find_any_alias(inode); + if (!dentry) + return -ENOENT; + ret = bpf_get_dentry_xattr(dentry, name__str, value_p); + dput(dentry); + return ret; +} + __bpf_kfunc_end_defs(); static int bpf_xattr_write_permission(const char *name, struct inode *inode) @@ -506,6 +538,7 @@ BTF_ID_FLAGS(func, bpf_put_file, KF_RELEASE) BTF_ID_FLAGS(func, bpf_path_d_path) BTF_ID_FLAGS(func, bpf_get_dentry_xattr, KF_SLEEPABLE) BTF_ID_FLAGS(func, bpf_get_file_xattr, KF_SLEEPABLE) +BTF_ID_FLAGS(func, bpf_get_inode_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_data_inode, KF_SLEEPABLE | KF_RET_NULL) -- 2.43.0