Skip to content

reef: client: Fix opening and reading of symlinks#60373

Merged
mchangir merged 2 commits intoceph:reeffrom
anoopcs9:wip-68574-reef
Feb 4, 2025
Merged

reef: client: Fix opening and reading of symlinks#60373
mchangir merged 2 commits intoceph:reeffrom
anoopcs9:wip-68574-reef

Conversation

@anoopcs9
Copy link
Contributor

backport tracker: https://tracker.ceph.com/issues/68574


backport of #59503
parent tracker: https://tracker.ceph.com/issues/67833

this backport was staged using ceph-backport.sh version 16.0.0.6848
find the latest version at https://github.com/ceph/ceph/blob/main/src/script/ceph-backport.sh

@github-actions github-actions bot added cephfs Ceph File System tests labels Oct 17, 2024
@github-actions github-actions bot added this to the reef milestone Oct 17, 2024
@github-actions
Copy link

This pull request has been automatically marked as stale because it has not had any activity for 60 days. It will be closed if no further activity occurs for another 30 days.
If you are a maintainer or core committer, please follow-up on this pull request to identify what steps should be taken by the author to move this proposed change forward.
If you are the author of this pull request, thank you for your proposed contribution. If you believe this change is still appropriate, please ensure that any feedback has been addressed and ask for a code review.

@github-actions github-actions bot added the stale label Dec 16, 2024
man open(2)[1] says the following for O_PATH:

. . .
If  pathname is a symbolic link and the O_NOFOLLOW flag is also
specified, then the call returns a file descriptor referring to the
symbolic link.  This file descriptor can be used as the dirfd argument
in calls to fchownat(2), fstatat(2), linkat(2), and readlinkat(2) with
an empty pathname to have the calls operate on the symbolic link.
. . .

symlink check within may_open() failed to consider the O_PATH flag
resulting in a ELOOP error to the client. In order to return a valid
file descriptor we introduce a check for the presence of O_PATH in
the client provided flags.

Fixes: https://tracker.ceph.com/issues/67833

[1] https://www.man7.org/linux/man-pages/man2/open.2.html

Signed-off-by: Anoop C S <anoopcs@cryptolab.net>
(cherry picked from commit 8443821)
man readlinkat(2)[1] points at a special case for readlinkat() syscall
as follows:

. . .
Since Linux 2.6.39, pathname can be an empty string, in which case the
call operates on the symbolic link referred to by dirfd (which should
have been obtained using open(2) with the O_PATH and O_NOFOLLOW flags).
. . .

man open(2)[2] further explains the need for such a special case when
a symlink is opened with O_PATH and O_NOFOLLOW:

. . .
If  pathname is a symbolic link and the O_NOFOLLOW flag is also
specified, then the call returns a file descriptor referring to the
symbolic link.  This file descriptor can be used as the dirfd argument
in calls to fchownat(2), fstatat(2), linkat(2), and readlinkat(2) with
an empty pathname to have the calls operate on the symbolic link.
. . .

Accordingly have a check to resolve symlinks out of dirfd when empty
pathnames are encountered within readlinkat(). In addition to that
match the standard file system behavior to return ENOENT instead of
EINVAL when the inode pointed to by dirfd is not a symbolic link with
empty pathnames.

Fixes: https://tracker.ceph.com/issues/67833

[1] https://www.man7.org/linux/man-pages/man2/readlinkat.2.html
[2] https://www.man7.org/linux/man-pages/man2/open.2.html

Signed-off-by: Anoop C S <anoopcs@cryptolab.net>
(cherry picked from commit 24f453d)
@anoopcs9
Copy link
Contributor Author

jenkins test api

@anoopcs9
Copy link
Contributor Author

jenkins test make check

1 similar comment
@vshankar
Copy link
Contributor

vshankar commented Jan 3, 2025

jenkins test make check

@vshankar
Copy link
Contributor

This PR is under test in https://tracker.ceph.com/issues/69503.

@ceph-jenkins
Copy link
Collaborator

Can one of the admins verify this patch?

vshankar added a commit to vshankar/ceph that referenced this pull request Jan 13, 2025
* refs/pull/60373/head:
	client: Resolve symlink from dirfd for empty pathname
	client: Fix symlink open with O_PATH and O_NOFOLLOW
@mchangir
Copy link
Contributor

jenkins test make check

Copy link
Contributor

@mchangir mchangir left a comment

Choose a reason for hiding this comment

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

@mchangir mchangir merged commit d10f55f into ceph:reef Feb 4, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants