Skip to content

Commit c7a20ed

Browse files
jtlaytongregkh
authored andcommitted
ceph: clean up unsafe d_parent accesses in build_dentry_path
[ Upstream commit c6b0b656ca24ede6657abb4a2cd910fa9c1879ba ] While we hold a reference to the dentry when build_dentry_path is called, we could end up racing with a rename that changes d_parent. Handle that situation correctly, by using the rcu_read_lock to ensure that the parent dentry and inode stick around long enough to safely check ceph_snap and ceph_ino. Link: http://tracker.ceph.com/issues/18148 Signed-off-by: Jeff Layton <jlayton@redhat.com> Reviewed-by: Yan, Zheng <zyan@redhat.com> Signed-off-by: Ilya Dryomov <idryomov@gmail.com> Signed-off-by: Sasha Levin <alexander.levin@verizon.com> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
1 parent c128baf commit c7a20ed

1 file changed

Lines changed: 7 additions & 2 deletions

File tree

fs/ceph/mds_client.c

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1845,13 +1845,18 @@ static int build_dentry_path(struct dentry *dentry,
18451845
int *pfreepath)
18461846
{
18471847
char *path;
1848+
struct inode *dir;
18481849

1849-
if (ceph_snap(d_inode(dentry->d_parent)) == CEPH_NOSNAP) {
1850-
*pino = ceph_ino(d_inode(dentry->d_parent));
1850+
rcu_read_lock();
1851+
dir = d_inode_rcu(dentry->d_parent);
1852+
if (dir && ceph_snap(dir) == CEPH_NOSNAP) {
1853+
*pino = ceph_ino(dir);
1854+
rcu_read_unlock();
18511855
*ppath = dentry->d_name.name;
18521856
*ppathlen = dentry->d_name.len;
18531857
return 0;
18541858
}
1859+
rcu_read_unlock();
18551860
path = ceph_mdsc_build_path(dentry, ppathlen, pino, 1);
18561861
if (IS_ERR(path))
18571862
return PTR_ERR(path);

0 commit comments

Comments
 (0)