From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=209.85.128.45 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796304761; b=un5PJLUkmmxUUrIDASQL2K9TURhH1Sn0ago9k95W4qxQEBh+X1syQLrOMMrWT4bZ4i8F 6QiLAtIiVyBMM6kLrsctMT+o90QWleEOD/S6HnHgCv6d4MFS0USY13GegUDds2SbQDWHc oKzQ2qQOeyZXA4boG7ySw+GAdgxxv9Qi6QaJFB1452GRlzAtRia+NL1wn1Me0rLG2j3T/ nlULRyGqzt93d+JQP2AF6/XiEaO0UeM+wOzYIkyOAg2Z5C1QXABMfoEXw5HCvBM1rgu/2 yvnF9CeT+bB1TbZQpASw3XcrwRd8SRYllRGoJsTkLfInaRhaOcUozfTl9II06luPFCw== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796304761; 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=Xa+m8A7isflfvYbLnJIolGWzC3rdejwio6mnBLXgVrM=; b=sUGbdxiLjNKW1PFdjvuGE4H6U6fJUkYqNlEX5k3BU1EE+r4Yu28IVSMx60QTuhXWAcPM 2QM77R9r3tv+wgsitJdCRmex0/y6cAL36aMWCSoFTqXUJ/G3lR8MepRaX18nXBkrz0n+Z kL750hmRr4lJ2Fo3RCXU4FgOcY8GMUGvTWKKsZ1uarcL/jq+o889GQpvT/fihbnkWAec4 1PnkfqjQ2tY90hh3Yq0CQeyLg6RcBqkD2iy4UmEhJIjBoAnhTKX2T+lTMjtMliHPSV6pc HQ9jS7ACItf6QL6WMo2SK64lCxApYwV7+VrnRY5eY45xWj5Gay8AIe/f7mLrhq0oxVA== 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=ebOofKYt; arc=none smtp.remote-ip=209.85.128.45 Received: from mail-wm1-f45.google.com (mail-wm1-f45.google.com [209.85.128.45]) (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 B2124606A322 for ; Thu, 3 Dec 2026 13:32:40 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org B2124606A322 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=ebOofKYt Received: by mail-wm1-f45.google.com with SMTP id 5b1f17b1804b1-4a35a60499eso111500535e9.0 for ; Thu, 03 Dec 2026 05:32:40 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20260707; t=1796304759; x=1796909559; 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=Xa+m8A7isflfvYbLnJIolGWzC3rdejwio6mnBLXgVrM=; b=ebOofKYtELp+uSZszfXQT7LRJN4CvimgNsb6jJ4twhbpa5/2Nrj7TwGHxLyrk55jvm fakp371HUQ+85Ou99N3DuJcikkKSbuTiJmI04bbqtVXn5BwpGJtv18a0zaXSvtBJj5ZO PVo77PXJJLENQw2T7cywfLdeCa3Tz7I72kaD560D34dpDZ3GwW6zvJg1sCXyVdoT536e JKFILxQqNs4rdF45KUPpdryncMLDt5onzP9gGQpgjnWZRMH09qSsLC8QERcYa3pFYZ9U HaDmIriog66GK8FOA7Ng9f8ZseOJVOd03W+paoTpkvWalTnFRKXa8PCCbQh1mOnn8wie 96PQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20260707; t=1796304759; x=1796909559; 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=Xa+m8A7isflfvYbLnJIolGWzC3rdejwio6mnBLXgVrM=; b=dSzfRgBc0IXc2ySahHgtpCDW9U0hBQE2g6YLciOw8UhZ5S36ni6NX39urpmdlgnOLa ajXN3MiPOFZtlKv9tB1zfm4DUP+DtjzIoveQd03RXnKN/NJztoGpbRlnH1zJhhZtBE07 7kvyBRm0c4G+IMffZsLUDJZpIaJHkGOJveU7eDQdXjZLMd1ZZFNGBljNGb9+731iJfX5 ZZUYhV6NTwUgUqs5loPNM/8K496gicjcdIFSCKP46rvjAA5JjJfHzdoY/8CIIvkxvbl5 gtDjjlVjn6uPoBYrs7ukNbK+ptg5ALUfMDOTWts+floqxQwENlF4MrqGbnbPLP5csAVK Xahg== X-Forwarded-Encrypted: i=1; AL+hErEBdxierGqWAGQbv9EfJ+OeHHZ+T7mD7UiodEYdM9hgp+nFhJyMZsfQK6VpFJor0yv8D0NcbN7WsKmBfSU=@vger.kernel.org X-Gm-Message-State: APuU4Z+SdqnNjbhsoYYmKgkYzRDJrc11myROp51QiiTwnQ5dM6n1mvAY /g4BkThlp4DY+K6Dlrf9MSfkxw8178sdyChjnhNHza0co1a2MU+XwURR X-Gm-Gg: AZFdTZfkkjoSf5KeoTVBYLp6xuR4yPIEzLw6y16sK4TjQAVRZ9uAF6K7oErGueSNMU+ Q3nDx4P7D2HOejTqmrnSS/BBgTAKZ6et4zwryKXHb/qE3kXCALQfC4CbVDL5WuST06MqwmuZPOk cTo4AQ78S2+PpEov6H+M8/Cz+9sey9C5GghGs5KafbiN1l+RBpvFiLAYo6dKVHtpHDtaVUXyisM gNOgPjw+0Lo3L9SWh7mNhQA0lihsqDThKYICPcNerRBS6aGNBuIDXeMrv999+sTOg7ryiqN4Zac l2++j1OfZcCw+v93MWyqzopAcCR1aGBWEfhShuMNRzuOWWIKJbOsDZjJbB79nu4MpFkWfNRNnnu 0pyflpEbwiRz2nrpqLM+U0WaRvrQJQAM9zTrN4F5TL6GZH2UL4o62+naBFIXH3fFWId805OSBLL 72kYAlXkb0bopqSoA5EouOXDFKTgGd2b2vD4aMD0m5gMkuToi6iFdcwtJLSv7cvL9NHm1PzHW+G d8YwmLaeN4uAmsWB1jrhH3LnQ026zrh+K7hC5DfKn4gUEpV4YaQtXxDeTv/eAeft99w5nhp2cvJ a0r1CkZCBRSx1i2nPYVbMg77yfNPzimpAjcTuW0E7/jj428= X-Received: by 2002:a05:600c:b8a:b0:4bb:7007:4a5a with SMTP id 5b1f17b1804b1-4bb88817772mr882270215e9.23.1796304759031; Thu, 03 Dec 2026 05:32:39 -0800 (PST) Received: from localhost.localdomain ([2a04:ee41:4:b2de:1ac0:4dff:fe0f:3782]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-4bbe00792besm74326105e9.4.2026.12.03.05.32.38 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 03 Dec 2026 05:32:38 -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 , bpf@vger.kernel.org, linux-fsdevel@vger.kernel.org, linux-kernel@vger.kernel.org Cc: Anton Protopopov Subject: [PATCH v1 bpf-next 2/3] bpf: Add a bpf_get_inode_xattr kfunc Date: Thu, 3 Dec 2026 13:44:06 +0000 Message-ID: <20261203134411.1092433-3-a.s.protopopov@gmail.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20261203134411.1092433-1-a.s.protopopov@gmail.com> References: <20261203134411.1092433-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 any of its dentries, found with d_find_any_alias(). Xattrs belong to the inode, so any dentry will do. d_find_alias() would not: it skips the unhashed dentry of an unlinked file which is still open. 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 | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) diff --git a/fs/bpf_fs_kfuncs.c b/fs/bpf_fs_kfuncs.c index 1b973bd4e535..654340a0bc70 100644 --- a/fs/bpf_fs_kfuncs.c +++ b/fs/bpf_fs_kfuncs.c @@ -169,6 +169,35 @@ __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 any dentry of *inode*. + * + * 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_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 +535,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