From: chentao.2022 Date: Mon, 24 Jun 2024 03:23:27 +0000 (+0800) Subject: cephfs: Fixed a bug in the readdir_cache_cb function that may have used freed memory... X-Git-Tag: v19.2.1~317^2 X-Git-Url: http://git-server-git.apps.pok.os.sepia.ceph.com/?a=commitdiff_plain;h=f6e7c9f04a55acb33f59de6f82cfb4b20fdb8a95;p=ceph.git cephfs: Fixed a bug in the readdir_cache_cb function that may have used freed memory after the _getattr operation returned Fixes: https://tracker.ceph.com/issues/56288 Signed-off-by: Tod Chen (cherry picked from commit a71c9dd7e57a6a1dd64ccfb67f24c2a7cf29f652 --- diff --git a/src/client/Client.cc b/src/client/Client.cc index 5bc050e97b5d..6d5d2ded8575 100644 --- a/src/client/Client.cc +++ b/src/client/Client.cc @@ -9398,6 +9398,12 @@ int Client::_readdir_cache_cb(dir_result_t *dirp, add_dirent_cb_t cb, void *p, int r = _getattr(dn->inode, mask, dirp->perms); if (r < 0) return r; + + /* fix https://tracker.ceph.com/issues/56288 */ + if (dirp->inode->dir == NULL) { + ldout(cct, 0) << " dir is closed, so we should return" << dendl; + return -CEPHFS_EAGAIN; + } // the content of readdir_cache may change after _getattr(), so pd may be invalid iterator pd = dir->readdir_cache.begin() + idx;