]> git.apps.os.sepia.ceph.com Git - ceph-ci.git/commit
client: Resolve symlink from dirfd for empty pathname
authorAnoop C S <anoopcs@cryptolab.net>
Tue, 27 Aug 2024 10:20:44 +0000 (15:50 +0530)
committerAnoop C S <anoopcs@cryptolab.net>
Tue, 15 Oct 2024 10:51:15 +0000 (16:21 +0530)
commit24f453dd39c25e00527d0ed0a1e9fefa6295999b
tree9efd928bf7f2d2490fb1f220bd2fb48483b187e3
parent8443821073b23946a32009106c45581db0d51e8f
client: Resolve symlink from dirfd for empty pathname

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>
src/client/Client.cc
src/test/libcephfs/test.cc