From nobody Sat Oct 11 00:35:49 2025 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 3F51C22331E; Wed, 11 Jun 2025 22:02:30 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1749679351; cv=none; b=H0S3rNMLmPfYzw4cYkEutfTCf697UH22U/ZjGGsGFuK8Npy9Pl1A5g9mNtJHccFDtMR48oVxlnFgyFT7qcWSsYaaTVsFXufheNlCf1KPl9PFTKyL8fIYcLf5JSJAvpaJlc76mt8EiKg8IsXjINwT0H8Xx5umKi8uePSTsA90js4= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1749679351; c=relaxed/simple; bh=I1E1/88ouy4jlOHjaJMujlro8u00FJXobC+CmNEcaCM=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=elo31X5xKYaAEkqTiE/jr3AH6YYZWtwuegNZsOe1Jl3TD1dwvS1FG2YZyIRjxTsuFidcbXsjZ/UXE1jZcv3aKU6kDayCzU6O7s1KiqulHA5c5VXztHZTikUoy0lkUr+zhxD4cY7cB2EFue2L+0KNOqx3yK/ty4axWxQbHQEVFuo= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=oMrRIyq+; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="oMrRIyq+" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 13BF7C4CEE3; Wed, 11 Jun 2025 22:02:29 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1749679350; bh=I1E1/88ouy4jlOHjaJMujlro8u00FJXobC+CmNEcaCM=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=oMrRIyq+qkj/dZq7tuFHdi4DidWUVn8ep31aFjVfUeY5qJEot525F8AetBcYB+cgQ /zLAxAXFz+GPF2UIhiRywWujiPB2ADihIHcv2enJM02HpJNoMY3JmngCYqLutWZGtf IDCmhTPbeK51fJ1ax06sMxEPOQLlvyOSVLh3IN+fVKISKmuePucR6K6D4Cm3rxJFVl smnmlG3ezzVSik/AHWKSq6zKm4QFjgJqOLMEkhMgIwm9aUFnm9RzJHGMUvyrikcgPl Z1T9MNDM25Kv1fuSHKsbEQeNWXWBl2ROmJzRbdT5a+RlzA525JPGaseeEGAq41QNhX JjBzIhvkOwHpg== From: Song Liu To: bpf@vger.kernel.org, linux-fsdevel@vger.kernel.org, linux-kernel@vger.kernel.org, linux-security-module@vger.kernel.org Cc: kernel-team@meta.com, andrii@kernel.org, eddyz87@gmail.com, ast@kernel.org, daniel@iogearbox.net, martin.lau@linux.dev, viro@zeniv.linux.org.uk, brauner@kernel.org, jack@suse.cz, kpsingh@kernel.org, mattbobrowski@google.com, amir73il@gmail.com, repnop@google.com, jlayton@kernel.org, josef@toxicpanda.com, mic@digikod.net, gnoack@google.com, m@maowtm.org, neil@brown.name, Song Liu Subject: [PATCH v4 bpf-next 1/5] namei: Introduce new helper function path_walk_parent() Date: Wed, 11 Jun 2025 15:02:16 -0700 Message-ID: <20250611220220.3681382-2-song@kernel.org> X-Mailer: git-send-email 2.47.1 In-Reply-To: <20250611220220.3681382-1-song@kernel.org> References: <20250611220220.3681382-1-song@kernel.org> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" This helper walks an input path to its parent. Logic are added to handle walking across mount tree. This will be used by landlock, and BPF LSM. Suggested-by: Neil Brown Signed-off-by: Song Liu --- fs/namei.c | 99 +++++++++++++++++++++++++++++++++++++------ include/linux/namei.h | 2 + 2 files changed, 87 insertions(+), 14 deletions(-) diff --git a/fs/namei.c b/fs/namei.c index 4bb889fc980b..bc65361c5d13 100644 --- a/fs/namei.c +++ b/fs/namei.c @@ -2048,36 +2048,107 @@ static struct dentry *follow_dotdot_rcu(struct nam= eidata *nd) return nd->path.dentry; } =20 -static struct dentry *follow_dotdot(struct nameidata *nd) +/** + * __path_walk_parent - Find the parent of the given struct path + * @path - The struct path to start from + * @root - A struct path which serves as a boundary not to be crosses. + * - If @root is zero'ed, walk all the way to global root. + * @flags - Some LOOKUP_ flags. + * + * Find and return the dentry for the parent of the given path + * (mount/dentry). If the given path is the root of a mounted tree, it + * is first updated to the mount point on which that tree is mounted. + * + * If %LOOKUP_NO_XDEV is given, then *after* the path is updated to a new + * mount, the error EXDEV is returned. + * + * If no parent can be found, either because the tree is not mounted or + * because the @path matches the @root, then @path->dentry is returned + * unless @flags contains %LOOKUP_BENEATH, in which case -EXDEV is returne= d. + * + * Returns: either an ERR_PTR() or the chosen parent which will have had + * the refcount incremented. + */ +static struct dentry *__path_walk_parent(struct path *path, const struct p= ath *root, int flags) { struct dentry *parent; =20 - if (path_equal(&nd->path, &nd->root)) + if (path_equal(path, root)) goto in_root; - if (unlikely(nd->path.dentry =3D=3D nd->path.mnt->mnt_root)) { - struct path path; + if (unlikely(path->dentry =3D=3D path->mnt->mnt_root)) { + struct path new_path; =20 - if (!choose_mountpoint(real_mount(nd->path.mnt), - &nd->root, &path)) + if (!choose_mountpoint(real_mount(path->mnt), + root, &new_path)) goto in_root; - path_put(&nd->path); - nd->path =3D path; - nd->inode =3D path.dentry->d_inode; - if (unlikely(nd->flags & LOOKUP_NO_XDEV)) + path_put(path); + *path =3D new_path; + if (unlikely(flags & LOOKUP_NO_XDEV)) return ERR_PTR(-EXDEV); } /* rare case of legitimate dget_parent()... */ - parent =3D dget_parent(nd->path.dentry); - if (unlikely(!path_connected(nd->path.mnt, parent))) { + parent =3D dget_parent(path->dentry); + if (unlikely(!path_connected(path->mnt, parent))) { dput(parent); return ERR_PTR(-ENOENT); } return parent; =20 in_root: - if (unlikely(nd->flags & LOOKUP_BENEATH)) + if (unlikely(flags & LOOKUP_BENEATH)) return ERR_PTR(-EXDEV); - return dget(nd->path.dentry); + return dget(path->dentry); +} + +/** + * path_walk_parent - Walk to the parent of path + * @path: input and output path. + * @root: root of the path walk, do not go beyond this root. If @root is + * zero'ed, walk all the way to real root. + * + * Given a path, find the parent path. Replace @path with the parent path. + * If we were already at the real root or a disconnected root, @path is + * released and zero'ed. + * + * Returns: + * true - if @path is updated to its parent. + * false - if @path is already the root (real root or @root). + */ +bool path_walk_parent(struct path *path, const struct path *root) +{ + struct dentry *parent; + + parent =3D __path_walk_parent(path, root, LOOKUP_BENEATH); + + if (IS_ERR(parent)) + goto false_out; + + if (parent =3D=3D path->dentry) { + dput(parent); + goto false_out; + } + dput(path->dentry); + path->dentry =3D parent; + return true; + +false_out: + path_put(path); + memset(path, 0, sizeof(*path)); + return false; +} + +static struct dentry *follow_dotdot(struct nameidata *nd) +{ + struct dentry *parent =3D __path_walk_parent(&nd->path, &nd->root, nd->fl= ags); + + if (IS_ERR(parent)) + return parent; + if (unlikely(!path_connected(nd->path.mnt, parent))) { + dput(parent); + return ERR_PTR(-ENOENT); + } + nd->inode =3D nd->path.dentry->d_inode; + return parent; } =20 static const char *handle_dots(struct nameidata *nd, int type) diff --git a/include/linux/namei.h b/include/linux/namei.h index 5d085428e471..cba5373ecf86 100644 --- a/include/linux/namei.h +++ b/include/linux/namei.h @@ -85,6 +85,8 @@ extern int follow_down_one(struct path *); extern int follow_down(struct path *path, unsigned int flags); extern int follow_up(struct path *); =20 +bool path_walk_parent(struct path *path, const struct path *root); + extern struct dentry *lock_rename(struct dentry *, struct dentry *); extern struct dentry *lock_rename_child(struct dentry *, struct dentry *); extern void unlock_rename(struct dentry *, struct dentry *); --=20 2.47.1 From nobody Sat Oct 11 00:35:49 2025 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 4CBDD248F4C; Wed, 11 Jun 2025 22:02:36 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1749679356; cv=none; b=qUE6ChdE6Z3eev7PtCBZvrEy3blzHoqqVR2ChL/rqmGv3quEHHJ0ZJO5dpV0wbNJ64TmPIkHKdmG+bUk55zDkKsoEnLfrZ8LCJAsjXHtaH/dCvl74sDeG2KbnBTuN+Z81jQRe1MFuOGLD9oDshoIyDG3MCUvTcZ4En6uRsHfCWE= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1749679356; c=relaxed/simple; bh=jlqrddGkspQ/7KMHo/Q8pc7a80dvA5q3PcdnFIQGNwQ=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=euvsK4Xfe67DHD3qMlHH6ymGdEWkGvsoR4ANvkbmJIpkZLtO+1QT169dAWTbUG9UdetnN6fZPgVIoVxG02FbTfuiY5O52eAJ20eChIMozku69XgaN/KgVLqGiiixRZ0FAtww4Wu72ySoRL0EHHfOjLE42yGTri0wRqyOLYCQR70= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=N1iWFD6Q; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="N1iWFD6Q" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 6CD39C4CEEF; Wed, 11 Jun 2025 22:02:34 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1749679356; bh=jlqrddGkspQ/7KMHo/Q8pc7a80dvA5q3PcdnFIQGNwQ=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=N1iWFD6QV1u5zV9y/1ie6RG96+psPGnPn5mWQOveO/FaKkZygKZ5YD+yU05DLwgTb XeuaHOaVFF0dvv64/LTyoPHD9WsgRfv3XVh0GyIRvCCcKiOvyVmQnu57mlM2IkSnM5 t8X2aHLKPJ+92wpe5Zr3jOdsqwBCDxOWEpnttOcaIgmFcbFJgeCC5Jrtef/RfBJrpR fBMHGVQaYLWKrTJ1rqukTQF+m4Zvb1lieT4GGv1pm7KuDHhJ4YAZd5SSIQR3yEg/Ti HEUaBV1rsamDH1uFJseyEGPe3eyuWb5tatYyPCAwhtCa3pPO1jLwH69dMXMMqU8Tzc fBkmeF4B3yNZg== From: Song Liu To: bpf@vger.kernel.org, linux-fsdevel@vger.kernel.org, linux-kernel@vger.kernel.org, linux-security-module@vger.kernel.org Cc: kernel-team@meta.com, andrii@kernel.org, eddyz87@gmail.com, ast@kernel.org, daniel@iogearbox.net, martin.lau@linux.dev, viro@zeniv.linux.org.uk, brauner@kernel.org, jack@suse.cz, kpsingh@kernel.org, mattbobrowski@google.com, amir73il@gmail.com, repnop@google.com, jlayton@kernel.org, josef@toxicpanda.com, mic@digikod.net, gnoack@google.com, m@maowtm.org, neil@brown.name, Song Liu Subject: [PATCH v4 bpf-next 2/5] landlock: Use path_walk_parent() Date: Wed, 11 Jun 2025 15:02:17 -0700 Message-ID: <20250611220220.3681382-3-song@kernel.org> X-Mailer: git-send-email 2.47.1 In-Reply-To: <20250611220220.3681382-1-song@kernel.org> References: <20250611220220.3681382-1-song@kernel.org> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Use path_walk_parent() to walk a path up to its parent. No functional changes intended. Signed-off-by: Song Liu --- security/landlock/fs.c | 28 ++++++++-------------------- 1 file changed, 8 insertions(+), 20 deletions(-) diff --git a/security/landlock/fs.c b/security/landlock/fs.c index 6fee7c20f64d..63232199ce23 100644 --- a/security/landlock/fs.c +++ b/security/landlock/fs.c @@ -837,8 +837,8 @@ static bool is_access_to_paths_allowed( * restriction. */ while (true) { - struct dentry *parent_dentry; const struct landlock_rule *rule; + struct path root =3D {}; =20 /* * If at least all accesses allowed on the destination are @@ -895,35 +895,23 @@ static bool is_access_to_paths_allowed( /* Stops when a rule from each layer grants access. */ if (allowed_parent1 && allowed_parent2) break; -jump_up: - if (walker_path.dentry =3D=3D walker_path.mnt->mnt_root) { - if (follow_up(&walker_path)) { - /* Ignores hidden mount points. */ - goto jump_up; - } else { - /* - * Stops at the real root. Denies access - * because not all layers have granted access. - */ - break; - } - } - if (unlikely(IS_ROOT(walker_path.dentry))) { + + if (unlikely(IS_ROOT(walker_path.dentry)) && + (walker_path.mnt->mnt_flags & MNT_INTERNAL)) { /* * Stops at disconnected root directories. Only allows * access to internal filesystems (e.g. nsfs, which is * reachable through /proc//ns/). */ - if (walker_path.mnt->mnt_flags & MNT_INTERNAL) { allowed_parent1 =3D true; allowed_parent2 =3D true; - } break; } - parent_dentry =3D dget_parent(walker_path.dentry); - dput(walker_path.dentry); - walker_path.dentry =3D parent_dentry; + if (!path_walk_parent(&walker_path, &root)) + break; } + + if (walker_path.dentry) path_put(&walker_path); =20 if (!allowed_parent1) { --=20 2.47.1 From nobody Sat Oct 11 00:35:49 2025 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 0C72B248F7E; Wed, 11 Jun 2025 22:02:41 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1749679363; cv=none; b=IAbE1n4ITMLRjGTDoO6G49laKNXIjSRlo8exeU02WFDu/Z7OK88U1VJwRRWshkGjgHxK/NEfoMRF7ln4LBUUNlMcTOggCGXvxAazoNiYDSgWOy366iQSNzPbfXpmWDqMMsSa6BZ9fqrSFQ+GtC9/apYvoBiE2YOREsGWEziKvsk= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1749679363; c=relaxed/simple; bh=Hi02oc76+p86JeL/rDSImZf3mMqCUePyQLkgUn3sGQU=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=t5xhDc0p3u1If/gtQNkK2ASyn7ytVVV5iqk5qh/b/vD50RklzAi21bkEXsq9cV6s2Tp8yfcO205IkBNmehAOkaLDwCYMlVkt+u5RQVl1/yf59K+e4WADa82lHM1s/lrUPpoHh2nTaeSyxpMaJKFKqiJPGRA59UObZjvYYnGhavM= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=Wp26ieqD; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="Wp26ieqD" Received: by smtp.kernel.org (Postfix) with ESMTPSA id DEAF5C4CEE3; Wed, 11 Jun 2025 22:02:39 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1749679361; bh=Hi02oc76+p86JeL/rDSImZf3mMqCUePyQLkgUn3sGQU=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=Wp26ieqD9VUyimtQwBWZmI8RaAQ6usfI6e/iICqXd7QEpz8x34IzNJBsTtLEvGgIL uF/zTfj/WQ92JKyAUTPRuXdYJ6mmMGPwRl+n/B6zRFn7yhXhA7QePqtm3EzH3M6MBd 4FI21Rm4A59OBZUi34lU6KzAnYTxdztsiW0KjTOBKRWOVQJaQ/0N8M1znKJO1FBlbQ 5ZHMd4qabbSjfoGPhmBDW2F79eXGJHwiTgsC/nd+fu1XfvxX8kKMBRHUEKhoQpf/nK dgRSZqbwmXjtxjeKEZWFrTTBpLFdcne+vddwxTh7WxrZOO3P/x34EL2zK3NL/b5tKz 7TypHbT0BLR4g== From: Song Liu To: bpf@vger.kernel.org, linux-fsdevel@vger.kernel.org, linux-kernel@vger.kernel.org, linux-security-module@vger.kernel.org Cc: kernel-team@meta.com, andrii@kernel.org, eddyz87@gmail.com, ast@kernel.org, daniel@iogearbox.net, martin.lau@linux.dev, viro@zeniv.linux.org.uk, brauner@kernel.org, jack@suse.cz, kpsingh@kernel.org, mattbobrowski@google.com, amir73il@gmail.com, repnop@google.com, jlayton@kernel.org, josef@toxicpanda.com, mic@digikod.net, gnoack@google.com, m@maowtm.org, neil@brown.name, Song Liu Subject: [PATCH v4 bpf-next 3/5] bpf: Introduce path iterator Date: Wed, 11 Jun 2025 15:02:18 -0700 Message-ID: <20250611220220.3681382-4-song@kernel.org> X-Mailer: git-send-email 2.47.1 In-Reply-To: <20250611220220.3681382-1-song@kernel.org> References: <20250611220220.3681382-1-song@kernel.org> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Introduce a path iterator, which walks a struct path toward the root. This path iterator is based on path_walk_parent. A fixed zero'ed root is passed to path_walk_parent(). Therefore, unless the user terminates it earlier, the iterator will terminate at the real root. Signed-off-by: Song Liu Acked-by: Andrii Nakryiko --- fs/bpf_fs_kfuncs.c | 72 +++++++++++++++++++++++++++++++++++++++++++ kernel/bpf/verifier.c | 5 +++ 2 files changed, 77 insertions(+) diff --git a/fs/bpf_fs_kfuncs.c b/fs/bpf_fs_kfuncs.c index 08412532db1b..1e7e94738c2b 100644 --- a/fs/bpf_fs_kfuncs.c +++ b/fs/bpf_fs_kfuncs.c @@ -10,6 +10,7 @@ #include #include #include +#include #include =20 __bpf_kfunc_start_defs(); @@ -324,6 +325,74 @@ __bpf_kfunc int bpf_remove_dentry_xattr(struct dentry = *dentry, const char *name_ =20 __bpf_kfunc_end_defs(); =20 +/* open-coded path iterator */ +struct bpf_iter_path { + __u64 __opaque[2]; +} __aligned(8); + +struct bpf_iter_path_kern { + struct path path; +} __aligned(8); + +__bpf_kfunc_start_defs(); + +__bpf_kfunc int bpf_iter_path_new(struct bpf_iter_path *it, + struct path *start, + __u64 flags) +{ + struct bpf_iter_path_kern *kit =3D (void *)it; + + BUILD_BUG_ON(sizeof(*kit) > sizeof(*it)); + BUILD_BUG_ON(__alignof__(*kit) !=3D __alignof__(*it)); + + if (flags) { + /* + * _destroy() is still called when _new() fails. Zero + * kit->path so that it be passed to path_put() safely. + * Note: path_put() is no-op for zero'ed path. + */ + memset(&kit->path, 0, sizeof(struct path)); + return -EINVAL; + } + + kit->path =3D *start; + path_get(&kit->path); + + return 0; +} + +__bpf_kfunc struct path *bpf_iter_path_next(struct bpf_iter_path *it) +{ + struct bpf_iter_path_kern *kit =3D (void *)it; + struct path root =3D {}; + + /* + * "root" is zero'ed. Therefore, unless the loop is explicitly + * terminated, bpf_iter_path_next() will continue looping until + * we've reached the global root of the VFS. + * + * If a root of walk is needed, the user can check "path" against + * that root on each iteration. + */ + if (!path_walk_parent(&kit->path, &root)) + return NULL; + + return &kit->path; +} + +__bpf_kfunc void bpf_iter_path_destroy(struct bpf_iter_path *it) +{ + struct bpf_iter_path_kern *kit =3D (void *)it; + + /* + * kit->path might be zero'ed, but this is OK because path_put() + * is no-op for zero'ed struct path + */ + path_put(&kit->path); +} + +__bpf_kfunc_end_defs(); + BTF_KFUNCS_START(bpf_fs_kfunc_set_ids) BTF_ID_FLAGS(func, bpf_get_task_exe_file, KF_ACQUIRE | KF_TRUSTED_ARGS | KF_RET_NULL) @@ -333,6 +402,9 @@ BTF_ID_FLAGS(func, bpf_get_dentry_xattr, KF_SLEEPABLE |= KF_TRUSTED_ARGS) BTF_ID_FLAGS(func, bpf_get_file_xattr, KF_SLEEPABLE | KF_TRUSTED_ARGS) BTF_ID_FLAGS(func, bpf_set_dentry_xattr, KF_SLEEPABLE | KF_TRUSTED_ARGS) BTF_ID_FLAGS(func, bpf_remove_dentry_xattr, KF_SLEEPABLE | KF_TRUSTED_ARGS) +BTF_ID_FLAGS(func, bpf_iter_path_new, KF_ITER_NEW | KF_TRUSTED_ARGS | KF_S= LEEPABLE) +BTF_ID_FLAGS(func, bpf_iter_path_next, KF_ITER_NEXT | KF_RET_NULL | KF_SLE= EPABLE) +BTF_ID_FLAGS(func, bpf_iter_path_destroy, KF_ITER_DESTROY | KF_SLEEPABLE) BTF_KFUNCS_END(bpf_fs_kfunc_set_ids) =20 static int bpf_fs_kfuncs_filter(const struct bpf_prog *prog, u32 kfunc_id) diff --git a/kernel/bpf/verifier.c b/kernel/bpf/verifier.c index b1f797616f20..9b5ac7c02867 100644 --- a/kernel/bpf/verifier.c +++ b/kernel/bpf/verifier.c @@ -7049,6 +7049,10 @@ BTF_TYPE_SAFE_TRUSTED_OR_NULL(struct socket) { struct sock *sk; }; =20 +BTF_TYPE_SAFE_TRUSTED_OR_NULL(struct path) { + struct dentry *dentry; +}; + static bool type_is_rcu(struct bpf_verifier_env *env, struct bpf_reg_state *reg, const char *field_name, u32 btf_id) @@ -7089,6 +7093,7 @@ static bool type_is_trusted_or_null(struct bpf_verifi= er_env *env, const char *field_name, u32 btf_id) { BTF_TYPE_EMIT(BTF_TYPE_SAFE_TRUSTED_OR_NULL(struct socket)); + BTF_TYPE_EMIT(BTF_TYPE_SAFE_TRUSTED_OR_NULL(struct path)); =20 return btf_nested_type_is_trusted(&env->log, reg, field_name, btf_id, "__safe_trusted_or_null"); --=20 2.47.1 From nobody Sat Oct 11 00:35:49 2025 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 4DE85218591; Wed, 11 Jun 2025 22:02:46 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1749679367; cv=none; b=pGwg2nQrko4uZwd4JJMjqOGNB7k1l810Br8ikr05J693N0kQ77d3OPEkljAqWYY8HNtmFrm+mMTCoSSjA7erzQcs0AL2iovliJ0ZMKQ7GA2+03X1Cs7fWa0NytvNogGWb0FpC9BDpBrl4hgI/xpgSofAxdCem4Dl6h6BPU+SW8g= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1749679367; c=relaxed/simple; bh=9F10qO9Msdgz89bnpZRuwO8YiDXQDw7GfTMJBW3OmZE=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=JmZDMubZ6BPQnI3D+GQkZ2PMnTSttfD97PDwSQdxB5wB+CNAz4VD/DJLfUaafFAkfUFpK4hgJSBVLre8Qxf8VbngNf6LlGkzr8yLgjvt6mxZx7QFwuPaPDXSg3y5AfWDJk7DNYXQ8HvEw1Qk1KRequWuo2BbGoubJjxLJjKpdXY= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=Kp3Z07xA; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="Kp3Z07xA" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 39DF4C4CEE3; Wed, 11 Jun 2025 22:02:45 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1749679366; bh=9F10qO9Msdgz89bnpZRuwO8YiDXQDw7GfTMJBW3OmZE=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=Kp3Z07xA35Fds9w9PvlnVexQmfBcdgep4DEj8lzIak5loHb0URjbscmByxloe6g28 dwr6IvYerDwnKBjUkJIG8YYqRLPs3Hza4c3dtzZQTf4gLAybzQALmwN8dpsPnUuFV8 kgFWyudO3odCO2DCnK2hvNJTQ6cMnuGtazaD/Wg8u3MfrECQwJJvXFDx0JVaeGKN7f 2dX4TOrJkz1G0d/hkQNrUlxam8zYP7tU3dEEX8FTfyh+GsziP5nykvUDdBIvoC+Eap cF5Lh9Ilx2a49l+aMg0fQ7gRIswigcvOFBn3fHK0u2yVlpKXNpPdEXe4Mk3unYLJ00 QOd7bQBxsk5UQ== From: Song Liu To: bpf@vger.kernel.org, linux-fsdevel@vger.kernel.org, linux-kernel@vger.kernel.org, linux-security-module@vger.kernel.org Cc: kernel-team@meta.com, andrii@kernel.org, eddyz87@gmail.com, ast@kernel.org, daniel@iogearbox.net, martin.lau@linux.dev, viro@zeniv.linux.org.uk, brauner@kernel.org, jack@suse.cz, kpsingh@kernel.org, mattbobrowski@google.com, amir73il@gmail.com, repnop@google.com, jlayton@kernel.org, josef@toxicpanda.com, mic@digikod.net, gnoack@google.com, m@maowtm.org, neil@brown.name, Song Liu Subject: [PATCH v4 bpf-next 4/5] selftests/bpf: Add tests for bpf path iterator Date: Wed, 11 Jun 2025 15:02:19 -0700 Message-ID: <20250611220220.3681382-5-song@kernel.org> X-Mailer: git-send-email 2.47.1 In-Reply-To: <20250611220220.3681382-1-song@kernel.org> References: <20250611220220.3681382-1-song@kernel.org> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Add tests for bpf path iterator, including test cases similar to real workload (call bpf_path_d_path and bpf_get_dentry_xattr), and test cases where the verifier rejects invalid use of the iterator. Signed-off-by: Song Liu --- .../testing/selftests/bpf/bpf_experimental.h | 6 + .../selftests/bpf/prog_tests/path_iter.c | 12 ++ tools/testing/selftests/bpf/progs/path_iter.c | 145 ++++++++++++++++++ 3 files changed, 163 insertions(+) create mode 100644 tools/testing/selftests/bpf/prog_tests/path_iter.c create mode 100644 tools/testing/selftests/bpf/progs/path_iter.c diff --git a/tools/testing/selftests/bpf/bpf_experimental.h b/tools/testing= /selftests/bpf/bpf_experimental.h index 5e512a1d09d1..cbb759b473df 100644 --- a/tools/testing/selftests/bpf/bpf_experimental.h +++ b/tools/testing/selftests/bpf/bpf_experimental.h @@ -596,4 +596,10 @@ extern int bpf_iter_dmabuf_new(struct bpf_iter_dmabuf = *it) __weak __ksym; extern struct dma_buf *bpf_iter_dmabuf_next(struct bpf_iter_dmabuf *it) __= weak __ksym; extern void bpf_iter_dmabuf_destroy(struct bpf_iter_dmabuf *it) __weak __k= sym; =20 +struct bpf_iter_path; +extern int bpf_iter_path_new(struct bpf_iter_path *it, struct path *start, + __u64 flags) __weak __ksym; +extern struct path *bpf_iter_path_next(struct bpf_iter_path *it) __weak __= ksym; +extern void bpf_iter_path_destroy(struct bpf_iter_path *it) __weak __ksym; + #endif diff --git a/tools/testing/selftests/bpf/prog_tests/path_iter.c b/tools/tes= ting/selftests/bpf/prog_tests/path_iter.c new file mode 100644 index 000000000000..3c99c24fbd96 --- /dev/null +++ b/tools/testing/selftests/bpf/prog_tests/path_iter.c @@ -0,0 +1,12 @@ +// SPDX-License-Identifier: GPL-2.0 +/* Copyright (c) 2025 Meta Platforms, Inc. and affiliates. */ + +#include +#include +#include +#include "path_iter.skel.h" + +void test_path_iter(void) +{ + RUN_TESTS(path_iter); +} diff --git a/tools/testing/selftests/bpf/progs/path_iter.c b/tools/testing/= selftests/bpf/progs/path_iter.c new file mode 100644 index 000000000000..74d0f4e19ffa --- /dev/null +++ b/tools/testing/selftests/bpf/progs/path_iter.c @@ -0,0 +1,145 @@ +// SPDX-License-Identifier: GPL-2.0 +/* Copyright (c) 2025 Meta Platforms, Inc. and affiliates. */ + +#include "vmlinux.h" +#include +#include +#include "bpf_misc.h" +#include "bpf_experimental.h" + +char _license[] SEC("license") =3D "GPL"; + +char path_name[256]; +char xattr_val[64]; + +static __always_inline void access_path_dentry(struct path *p) +{ + struct bpf_dynptr ptr; + struct dentry *dentry; + + if (!p) + return; + + bpf_dynptr_from_mem(xattr_val, sizeof(xattr_val), 0, &ptr); + bpf_path_d_path(p, path_name, sizeof(path_name)); + + dentry =3D p->dentry; + if (dentry) + bpf_get_dentry_xattr(dentry, "user.xattr", &ptr); +} + +SEC("lsm.s/file_open") +__success +int BPF_PROG(open_code, struct file *f) +{ + struct bpf_iter_path path_it; + struct path *p; + int ret; + + ret =3D bpf_iter_path_new(&path_it, &f->f_path, 0); + if (ret) { + bpf_iter_path_destroy(&path_it); + return 0; + } + + p =3D bpf_iter_path_next(&path_it); + access_path_dentry(p); + bpf_iter_path_destroy(&path_it); + + return 0; +} + +SEC("lsm.s/file_open") +__success +int BPF_PROG(for_each, struct file *f) +{ + struct path *p; + + bpf_for_each(path, p, &f->f_path, 0) + access_path_dentry(p); + + return 0; +} + +SEC("lsm.s/file_open") +__failure __msg("Unreleased reference") +int BPF_PROG(missing_destroy, struct file *f) +{ + struct bpf_iter_path path_it; + + bpf_iter_path_new(&path_it, &f->f_path, 0); + + return 0; +} + +SEC("lsm.s/file_open") +__failure __msg("expected an initialized iter_path") +int BPF_PROG(missing_new, struct file *f) +{ + struct bpf_iter_path path_it; + + bpf_iter_path_destroy(&path_it); + return 0; +} + +SEC("lsm.s/file_open") +__failure __msg("expected uninitialized iter_path") +int BPF_PROG(new_twice, struct file *f) +{ + struct bpf_iter_path path_it; + + bpf_iter_path_new(&path_it, &f->f_path, 0); + bpf_iter_path_new(&path_it, &f->f_path, 0); + bpf_iter_path_destroy(&path_it); + return 0; +} + +SEC("lsm.s/file_open") +__failure __msg("expected an initialized iter_path") +int BPF_PROG(destroy_twice, struct file *f) +{ + struct bpf_iter_path path_it; + + bpf_iter_path_new(&path_it, &f->f_path, 0); + bpf_iter_path_destroy(&path_it); + bpf_iter_path_destroy(&path_it); + return 0; +} + +SEC("lsm.s/file_open") +__success +int BPF_PROG(reuse_path_iter, struct file *f) +{ + struct bpf_iter_path path_it; + + bpf_iter_path_new(&path_it, &f->f_path, 0); + bpf_iter_path_destroy(&path_it); + bpf_iter_path_new(&path_it, &f->f_path, 0); + bpf_iter_path_destroy(&path_it); + return 0; +} + +SEC("lsm.s/file_open") +__failure __msg("invalid read from stack off") +int BPF_PROG(invalid_read_path_iter, struct file *f) +{ + struct bpf_iter_path path_it; + struct bpf_iter_path path_it_2; + + + bpf_iter_path_new(&path_it, &f->f_path, 0); + path_it_2 =3D path_it; + bpf_iter_path_destroy(&path_it_2); + return 0; +} + +SEC("lsm.s/sb_alloc_security") +__failure __msg("must be referenced or trusted") +int BPF_PROG(untrusted_path, struct super_block *sb) +{ + struct bpf_iter_path path_it; + + bpf_iter_path_new(&path_it, &sb->s_bdev_file->f_path, 0); + bpf_iter_path_destroy(&path_it); + return 0; +} --=20 2.47.1 From nobody Sat Oct 11 00:35:49 2025 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id A3A5D24BC1A; Wed, 11 Jun 2025 22:02:52 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1749679373; cv=none; b=oCQg6Z4uChaiXG5F8R5QKZ05PQL26oK18h9WhBHcjn3w+i+uOCxnZX/pLGNpz9XVBYLd2Es10kNwsvs2/pB8Xbf7FGE4XeqeYqAPZNjuU/rYKll8bi4nzUn/geVtarbGOJxrkY80fu3ky3tPNwMewccYyF6VkVQUHNBUl8GxzdA= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1749679373; c=relaxed/simple; bh=vl/pVqr2RXH2Xn1E+8wtiXLeu/mTXlC3sdSyiyVMmIA=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=ATxO1DKQTWC9B48LarnkFcQl4OiTvXWRr2smkFl3i9KvuJnbsSh3ViaMFj/udIy9V7huNfLcBuwRMkaciMTPdxsfdxID9DGGAYaYzPLa8ML9Uyltapw6SJ4ERKzh1fv4lqdfZFesqWgiTwCn0S7va1diCKZgDs9ff5xr+0z3+xo= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=KU26z/Z3; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="KU26z/Z3" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 91E08C4CEEE; Wed, 11 Jun 2025 22:02:50 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1749679372; bh=vl/pVqr2RXH2Xn1E+8wtiXLeu/mTXlC3sdSyiyVMmIA=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=KU26z/Z3kicXR0SNyEAcbe8ylvH0cNGYTroG/WWfzY0qIqMgmOyzqYxkPw+N272eP zyuz+iDYcepkgPEP/3p0a8DLH2pWnRbabhDhPY6Lv6LyoxCovzK5D7eo2wzE8PgRB2 9BByU8MYRU2eeDHFgg9H01booGZ0WFQps+ZwMWxUiPUYguX8JwPoVb4JldapUb2CSl yoRQlWeN9NIZ7Lq33x0rR4D6LW2aPEov8X8pZ8jHoMp2MuJt0v0Lhyf4mErOTOnSI1 F8jHSMXWrZPOSn6KvtzdS3V/RdupHMehrX1WWcTneygQH1oNDwBZ4SEjy/o4G/P1aW Uv9VZ5r37zxWA== From: Song Liu To: bpf@vger.kernel.org, linux-fsdevel@vger.kernel.org, linux-kernel@vger.kernel.org, linux-security-module@vger.kernel.org Cc: kernel-team@meta.com, andrii@kernel.org, eddyz87@gmail.com, ast@kernel.org, daniel@iogearbox.net, martin.lau@linux.dev, viro@zeniv.linux.org.uk, brauner@kernel.org, jack@suse.cz, kpsingh@kernel.org, mattbobrowski@google.com, amir73il@gmail.com, repnop@google.com, jlayton@kernel.org, josef@toxicpanda.com, mic@digikod.net, gnoack@google.com, m@maowtm.org, neil@brown.name, Song Liu Subject: [PATCH v4 bpf-next 5/5] selftests/bpf: Path walk test Date: Wed, 11 Jun 2025 15:02:20 -0700 Message-ID: <20250611220220.3681382-6-song@kernel.org> X-Mailer: git-send-email 2.47.1 In-Reply-To: <20250611220220.3681382-1-song@kernel.org> References: <20250611220220.3681382-1-song@kernel.org> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Add an end-to-end test with path_iter on security hook file_open. A test file is created in folder /tmp/test_progs_path_iter/folder. On file_open, walk file->f_path up to its parent and grand parent, and test bpf_get_dentry_xattr and bpf_path_d_path on the folders. Signed-off-by: Song Liu --- .../selftests/bpf/prog_tests/path_iter.c | 99 +++++++++++++++++++ tools/testing/selftests/bpf/progs/path_walk.c | 59 +++++++++++ 2 files changed, 158 insertions(+) create mode 100644 tools/testing/selftests/bpf/progs/path_walk.c diff --git a/tools/testing/selftests/bpf/prog_tests/path_iter.c b/tools/tes= ting/selftests/bpf/prog_tests/path_iter.c index 3c99c24fbd96..b9772026fbf7 100644 --- a/tools/testing/selftests/bpf/prog_tests/path_iter.c +++ b/tools/testing/selftests/bpf/prog_tests/path_iter.c @@ -2,11 +2,110 @@ /* Copyright (c) 2025 Meta Platforms, Inc. and affiliates. */ =20 #include +#include #include #include +#include +#include + #include "path_iter.skel.h" +#include "path_walk.skel.h" + +static const char grand_parent_path[] =3D "/tmp/test_progs_path_iter"; +static const char parent_path[] =3D "/tmp/test_progs_path_iter/folder"; +static const char file_path[] =3D "/tmp/test_progs_path_iter/folder/file"; +static const char xattr_name[] =3D "user.bpf.selftests"; +static const char xattr_value[] =3D "selftest_path_iter"; + +static void cleanup_files(void) +{ + remove(file_path); + rmdir(parent_path); + rmdir(grand_parent_path); +} + +static int setup_files_and_xattrs(void) +{ + int ret =3D -1; + + /* create test folders */ + if (mkdir(grand_parent_path, 0755)) + goto error; + if (mkdir(parent_path, 0755)) + goto error; + + /* setxattr for test folders */ + ret =3D setxattr(grand_parent_path, xattr_name, + xattr_value, sizeof(xattr_value), 0); + if (ret < 0) { + /* return errno, so that we can handle EOPNOTSUPP in the caller */ + ret =3D errno; + goto error; + } + ret =3D setxattr(parent_path, xattr_name, + xattr_value, sizeof(xattr_value), 0); + if (ret < 0) { + /* return errno, so that we can handle EOPNOTSUPP in the caller */ + ret =3D errno; + goto error; + } + + return 0; +error: + cleanup_files(); + return ret; +} + +static void test_path_walk(void) +{ + struct path_walk *skel =3D NULL; + int file_fd; + int err; + + err =3D setup_files_and_xattrs(); + if (err =3D=3D EOPNOTSUPP) { + printf("%s:SKIP:local fs doesn't support xattr (%d)\n" + "To run this test, make sure /tmp filesystem supports xattr.\n", + __func__, errno); + test__skip(); + return; + } + + if (!ASSERT_OK(err, "setup_file")) + return; + + skel =3D path_walk__open_and_load(); + if (!ASSERT_OK_PTR(skel, "path_walk__open_and_load")) + goto cleanup; + + skel->bss->monitored_pid =3D getpid(); + if (!ASSERT_OK(path_walk__attach(skel), "path_walk__attach")) + goto cleanup; + + file_fd =3D open(file_path, O_CREAT); + if (!ASSERT_OK_FD(file_fd, "open_file")) + goto cleanup; + close(file_fd); + + ASSERT_OK(strncmp(skel->bss->parent_xattr_buf, xattr_value, strlen(xattr_= value)), + "parent_xattr"); + ASSERT_OK(strncmp(skel->bss->grand_parent_xattr_buf, xattr_value, strlen(= xattr_value)), + "grand_parent_xattr"); + + ASSERT_OK(strncmp(skel->bss->parent_path_buf, parent_path, strlen(parent_= path)), + "parent_d_path"); + ASSERT_OK(strncmp(skel->bss->grand_parent_path_buf, grand_parent_path, + strlen(grand_parent_path)), + "grand_parent_d_path"); + +cleanup: + path_walk__destroy(skel); + cleanup_files(); +} =20 void test_path_iter(void) { RUN_TESTS(path_iter); + if (test__start_subtest("path_walk_example")) + test_path_walk(); } diff --git a/tools/testing/selftests/bpf/progs/path_walk.c b/tools/testing/= selftests/bpf/progs/path_walk.c new file mode 100644 index 000000000000..1e1ae82b47a2 --- /dev/null +++ b/tools/testing/selftests/bpf/progs/path_walk.c @@ -0,0 +1,59 @@ +// SPDX-License-Identifier: GPL-2.0 +/* Copyright (c) 2025 Meta Platforms, Inc. and affiliates. */ + +#include "vmlinux.h" +#include +#include +#include +#include +#include "bpf_kfuncs.h" +#include "bpf_misc.h" + +char _license[] SEC("license") =3D "GPL"; + +__u32 monitored_pid; + +#define BUF_SIZE 1024 +char parent_path_buf[BUF_SIZE] =3D {}; +char parent_xattr_buf[BUF_SIZE] =3D {}; +char grand_parent_path_buf[BUF_SIZE] =3D {}; +char grand_parent_xattr_buf[BUF_SIZE] =3D {}; + +static __always_inline void d_path_and_read_xattr(struct path *p, char *pa= th, char *xattr) +{ + struct bpf_dynptr ptr; + struct dentry *dentry; + + if (!p) + return; + bpf_path_d_path(p, path, BUF_SIZE); + bpf_dynptr_from_mem(xattr, BUF_SIZE, 0, &ptr); + dentry =3D p->dentry; + if (dentry) + bpf_get_dentry_xattr(dentry, "user.bpf.selftests", &ptr); +} + +SEC("lsm.s/file_open") +int BPF_PROG(test_file_open, struct file *f) +{ + __u32 pid =3D bpf_get_current_pid_tgid() >> 32; + struct bpf_iter_path path_it; + struct path *p; + + if (pid !=3D monitored_pid) + return 0; + + bpf_iter_path_new(&path_it, &f->f_path, 0); + + /* Get d_path and xattr for the parent directory */ + p =3D bpf_iter_path_next(&path_it); + d_path_and_read_xattr(p, parent_path_buf, parent_xattr_buf); + + /* Get d_path and xattr for the grand parent directory */ + p =3D bpf_iter_path_next(&path_it); + d_path_and_read_xattr(p, grand_parent_path_buf, grand_parent_xattr_buf); + + bpf_iter_path_destroy(&path_it); + + return 0; +} --=20 2.47.1