From: Tingmao Wang <m@maowtm.org>
To: "Song Liu" <song@kernel.org>, "Mickaël Salaün" <mic@digikod.net>
Cc: Al Viro <viro@zeniv.linux.org.uk>, Jan Kara <jack@suse.cz>,
bpf@vger.kernel.org, linux-fsdevel@vger.kernel.org,
linux-kernel@vger.kernel.org,
linux-security-module@vger.kernel.org, kernel-team@meta.com,
andrii@kernel.org, eddyz87@gmail.com, ast@kernel.org,
daniel@iogearbox.net, martin.lau@linux.dev, brauner@kernel.org,
kpsingh@kernel.org, mattbobrowski@google.com, amir73il@gmail.com,
repnop@google.com, jlayton@kernel.org, josef@toxicpanda.com,
gnoack@google.com
Subject: Re: [PATCH bpf-next 3/4] bpf: Introduce path iterator
Date: Sat, 31 May 2025 15:05:46 +0100 [thread overview]
Message-ID: <c2d0bae8-691f-4bb6-9c0e-64ab7cdaebd6@maowtm.org> (raw)
In-Reply-To: <CAPhsuW5U-nPk4MFdZSeBNds0qEHjQZrC=c5q+AGNpsKiveC2wA@mail.gmail.com>
On 5/30/25 19:55, Song Liu wrote:
> On Fri, May 30, 2025 at 5:20 AM Mickaël Salaün <mic@digikod.net> wrote:
> [...]
>>>
>>> If we update path_parent in this patchset with choose_mountpoint(),
>>> and use it in Landlock, we will close this race condition, right?
>>
>> choose_mountpoint() is currently private, but if we add a new filesystem
>> helper, I think the right approach would be to expose follow_dotdot(),
>> updating its arguments with public types. This way the intermediates
>> mount points will not be exposed, RCU optimization will be leveraged,
>> and usage of this new helper will be simplified.
>
> I think it is easier to add a helper similar to follow_dotdot(), but not with
> nameidata. follow_dotdot() touches so many things in nameidata, so it
> is better to keep it as-is. I am having the following:
>
> /**
> * path_parent - Find 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
> * not changed.
> *
> * Returns:
> * true - if @path is updated to its parent.
> * false - if @path is already the root (real root or @root).
> */
> bool path_parent(struct path *path, const struct path *root)
> {
> struct dentry *parent;
>
> if (path_equal(path, root))
> return false;
>
> if (unlikely(path->dentry == path->mnt->mnt_root)) {
> struct path p;
>
> if (!choose_mountpoint(real_mount(path->mnt), root, &p))
> return false;
> path_put(path);
> *path = p;
> return true;
> }
>
> if (unlikely(IS_ROOT(path->dentry)))
> return false;
>
> parent = dget_parent(path->dentry);
> if (unlikely(!path_connected(path->mnt, parent))) {
> dput(parent);
> return false;
> }
> dput(path->dentry);
> path->dentry = parent;
> return true;
> }
> EXPORT_SYMBOL_GPL(path_parent);
>
> And for Landlock, it is simply:
>
> if (path_parent(&walker_path, &root))
> continue;
>
> if (unlikely(IS_ROOT(walker_path.dentry))) {
> /*
> * Stops at disconnected or real root directories.
> * Only allows access to internal filesystems
> * (e.g. nsfs, which is reachable through
> * /proc/<pid>/ns/<namespace>).
> */
> if (walker_path.mnt->mnt_flags & MNT_INTERNAL) {
> allowed_parent1 = true;
> allowed_parent2 = true;
> }
> break;
Hi, maybe I'm missing the complete picture of this code, but since
path_parent doesn't change walker_path if it returns false (e.g. if it's
disconnected, or choose_mountpoint fails), I think this `break;` should be
outside the
if (unlikely(IS_ROOT(walker_path.dentry)))
right? (Assuming this whole thing is under a `while (true)`) Otherwise we
might get stuck at the current path and get infinite loop?
> }
>
> Does this look right?
>
> Thanks,
> Song
next prev parent reply other threads:[~2025-05-31 14:05 UTC|newest]
Thread overview: 45+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-05-28 22:26 [PATCH bpf-next 0/4] bpf " Song Liu
2025-05-28 22:26 ` [PATCH bpf-next 1/4] namei: Introduce new helper function path_parent() Song Liu
2025-05-28 22:26 ` [PATCH bpf-next 2/4] landlock: Use path_parent() Song Liu
2025-05-31 13:51 ` Tingmao Wang
2025-06-02 13:36 ` Song Liu
2025-06-03 0:10 ` Song Liu
2025-06-03 12:47 ` Mickaël Salaün
2025-06-02 17:35 ` Mickaël Salaün
2025-06-02 22:56 ` Tingmao Wang
2025-05-28 22:26 ` [PATCH bpf-next 3/4] bpf: Introduce path iterator Song Liu
2025-05-28 22:37 ` Al Viro
2025-05-29 11:58 ` Jan Kara
2025-05-29 16:53 ` Song Liu
2025-05-29 16:57 ` Alexei Starovoitov
2025-05-29 17:05 ` Song Liu
2025-05-30 14:20 ` Mickaël Salaün
2025-06-02 9:41 ` Christian Brauner
2025-06-03 9:46 ` Jan Kara
2025-06-03 12:49 ` Mickaël Salaün
2025-06-03 21:13 ` Jan Kara
2025-05-29 17:38 ` Al Viro
2025-05-29 18:00 ` Song Liu
2025-05-29 18:35 ` Al Viro
2025-05-29 19:46 ` Song Liu
2025-05-29 20:15 ` Al Viro
2025-05-29 21:07 ` Song Liu
2025-05-29 21:45 ` Al Viro
2025-05-29 22:13 ` Song Liu
2025-05-29 23:10 ` Al Viro
2025-05-30 0:42 ` Song Liu
2025-05-30 12:20 ` Mickaël Salaün
2025-05-30 18:43 ` Al Viro
2025-05-31 8:39 ` Mickaël Salaün
2025-06-02 9:32 ` Christian Brauner
2025-05-30 18:55 ` Song Liu
2025-05-31 8:40 ` Mickaël Salaün
2025-05-31 14:05 ` Tingmao Wang [this message]
2025-06-01 23:33 ` Song Liu
2025-06-04 0:58 ` Tingmao Wang
2025-06-02 9:30 ` Christian Brauner
2025-06-02 9:27 ` Christian Brauner
2025-06-02 13:27 ` Song Liu
2025-06-02 15:40 ` Alexei Starovoitov
2025-06-02 21:39 ` Song Liu
2025-05-28 22:26 ` [PATCH bpf-next 4/4] selftests/bpf: Add tests for bpf " Song Liu
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=c2d0bae8-691f-4bb6-9c0e-64ab7cdaebd6@maowtm.org \
--to=m@maowtm.org \
--cc=amir73il@gmail.com \
--cc=andrii@kernel.org \
--cc=ast@kernel.org \
--cc=bpf@vger.kernel.org \
--cc=brauner@kernel.org \
--cc=daniel@iogearbox.net \
--cc=eddyz87@gmail.com \
--cc=gnoack@google.com \
--cc=jack@suse.cz \
--cc=jlayton@kernel.org \
--cc=josef@toxicpanda.com \
--cc=kernel-team@meta.com \
--cc=kpsingh@kernel.org \
--cc=linux-fsdevel@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-security-module@vger.kernel.org \
--cc=martin.lau@linux.dev \
--cc=mattbobrowski@google.com \
--cc=mic@digikod.net \
--cc=repnop@google.com \
--cc=song@kernel.org \
--cc=viro@zeniv.linux.org.uk \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®