Skip to content

virtio/fs/linux: Fix xattrs on symlinks#224

Merged
slp merged 1 commit intocontainers:mainfrom
hoshinolina:fix-symlink-xattrs
Oct 16, 2024
Merged

virtio/fs/linux: Fix xattrs on symlinks#224
slp merged 1 commit intocontainers:mainfrom
hoshinolina:fix-symlink-xattrs

Conversation

@hoshinolina
Copy link
Copy Markdown
Contributor

@hoshinolina hoshinolina commented Oct 15, 2024

The f*attr library of functions only works on files opened normally. Symlinks can only be opened with O_PATH, but that doesn't support xattr operations. So, to handle symlinks, we need to use the l*attr family of functions directly on the pathname.

Thankfully, this does still work via /proc/self/fd/* for fds opened with O_PATH, so we can still do fd-relative operations (l*attr on such a path resolves the magic symlink and operates on the symlink that is actually opened as that fd).

This fixes ls: bin: Too many levels of symbolic links errors in the guest when SELinux attributes are in use.

The f*attr library of functions only works on files opened normally.
Symlinks can only be opened with O_PATH, but that doesn't support xattr
operations. So, to handle symlinks, we need to use the l*attr family of
functions directly on the pathname.

Thankfully, this does still work via /proc/self/fd/* for fds opened with
O_PATH, so we can still do fd-relative operations (l*attr on such a path
resolves the magic symlink and operates on the symlink that is actually
opened as that fd).

Signed-off-by: Asahi Lina <lina@asahilina.net>
Copy link
Copy Markdown
Collaborator

@slp slp left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice one, thanks.

@slp slp merged commit 201124d into containers:main Oct 16, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants