Re: [PATCH bpf-next 2/2] selftests/bpf: Add tests for bpf_get_dentry_xattr

From: Al Viro
Date: Tue Aug 20 2024 - 02:29:39 EST


On Mon, Aug 19, 2024 at 08:25:38PM +0000, Song Liu wrote:

> int bpf_get_parent_path(struct path *p) {
> again:
> if (p->dentry == p->mnt.mnt_root) {
> follow_up(p);
> goto again;
> }
> if (unlikely(IS_ROOT(p->dentry))) {
> return PARENT_WALK_DONE;
> }
> parent_dentry = dget_parent(p->dentry);
> dput(p->dentry);
> p->dentry = parent_dentry;
> return PARENT_WALK_NEXT;
> }
>
> This will handle the mount. However, we cannot guarantee deny-by-default
> policies like LandLock does, because this is just a building block of
> some security policies.

You do realize that above is racy as hell, right?

Filesystem objects do get moved around. You can, theoretically, play with
rename_lock, but that is highly antisocial.

What's more, _mounts_ can get moved around. That is to say, there is no
such thing as stable canonical pathname of a file.