]> git-server-git.apps.pok.os.sepia.ceph.com Git - ceph.git/commit
client: Resolve symlink from dirfd for empty pathname 60372/head
authorAnoop C S <anoopcs@cryptolab.net>
Tue, 27 Aug 2024 10:20:44 +0000 (15:50 +0530)
committerAnoop C S <anoopcs@cryptolab.net>
Tue, 17 Dec 2024 11:46:02 +0000 (17:16 +0530)
commitacf6717bad7d3e6440c28f5f776dbbe53dec9cda
tree5d6da84743e6910db02a0053b00cd55b1ce67695
parentd887a29fec4553e8170b18e724953a4c2ddee7e0
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>
(cherry picked from commit 24f453dd39c25e00527d0ed0a1e9fefa6295999b)
src/client/Client.cc
src/test/libcephfs/test.cc