Skip to contentSkip to conversation

Patch "ceph: fix race in concurrent readdir" has been added to the 4.4-stable tree

PATCH [email protected] 1 participant 1 message Jul 25, 2017

Subsystems (2)
lore
Share & tools
lore

[email protected]

author maintainer Applied
#0 lore raw

This is a note to let you know that I've just added the patch titled

ceph: fix race in concurrent readdir

to the 4.4-stable tree which can be found at:
http://www.kernel.org/git/?p=linux/kernel/git/stable/stable-queue.git;a=summary

The filename of the patch is:
ceph-fix-race-in-concurrent-readdir.patch
and it can be found in the queue-4.4 subdirectory.

If you, or anyone else, feels it should not be added to the stable tree, please let <[email protected]> know about it.

Quoted 1 line

From 84583cfb973c4313955c6231cc9cb3772d280b15 Mon Sep 17 00:00:00 2001

From: "Yan, Zheng" <[email protected]>
Date: Thu, 6 Jul 2017 11:12:21 +0800
Subject: ceph: fix race in concurrent readdir

From: Yan, Zheng <[email protected]>

commit 84583cfb973c4313955c6231cc9cb3772d280b15 upstream.

For a large directory, program needs to issue multiple readdir syscalls to get all dentries. When there are multiple programs read the directory concurrently. Following sequence of events can happen.

- program calls readdir with pos = 2. ceph sends readdir request to mds. The reply contains N1 entries. ceph adds these N1 entries to readdir cache.
- program calls readdir with pos = N1+2. The readdir is satisfied by the readdir cache, N2 entries are returned. (Other program calls readdir in the middle, which fills the cache)
- program calls readdir with pos = N1+N2+2. ceph sends readdir request to mds. The reply contains N3 entries and it reaches directory end. ceph adds these N3 entries to the readdir cache and marks directory complete.

The second readdir call does not update fi->readdir_cache_idx. ceph add the last N3 entries to wrong places.

---
 fs/ceph/dir.c |    5 +++++
 1 file changed, 5 insertions(+)
fs/ceph/dir.c +5 -0
@@ -247,6 +247,11 @@ static int __dcache_readdir(struct file
 		if (ret < 0)
 			err = ret;
 		dput(last);
+		/* last_name no longer match cache index */
+		if (fi->readdir_cache_idx >= 0) {
+			fi->readdir_cache_idx = -1;
+			fi->dir_release_count = 0;
+		}
 	}
 	return err;
 }

Patches currently in stable-queue which might be from [email protected] are

queue-4.4/ceph-fix-race-in-concurrent-readdir.patch