git: tmpfs - Fix readdir() races
Matthew Dillon
dillon at crater.dragonflybsd.org
Sun Jan 23 22:06:47 PST 2022
commit e91c5b2636e1fdd0d9e5170f24e5e39987211a49
Author: Matthew Dillon <dillon at apollo.backplane.com>
Date: Sun Jan 23 21:55:44 2022 -0800
tmpfs - Fix readdir() races
* Fix multi-threaded deletion races against readdir(). These races
can cause a directory scan in one thread to return EINVAL if the
file representing the chaining cookie is deleted by another thread.
Fix the issue by allowing tmpfs_dir_lookupbycookie() to return the
nearest directory entry with a cookie >= the requested cookie.
* Use a better cookie value for EOF
* Allow readdir() to fail on "." or "..". Instead just iterate to
the next entry. This can occur when a directory is deleted out
from under a scan that has chdir()'d into it.
* tmpfs was previously rescanning all entries to locate a cookie,
which is rather dumb given that we have a RB tree. Do a proper
iterative recursive search instead.
Reported-by: zrj, others
Summary of changes:
sys/vfs/tmpfs/tmpfs.h | 19 ++++++++++++++++---
sys/vfs/tmpfs/tmpfs_subr.c | 44 ++++++++++++++++++++++++++++++++++++++++----
sys/vfs/tmpfs/tmpfs_vnops.c | 8 ++++----
3 files changed, 60 insertions(+), 11 deletions(-)
http://gitweb.dragonflybsd.org/dragonfly.git/commitdiff/e91c5b2636e1fdd0d9e5170f24e5e39987211a49
--
DragonFly BSD source repository
More information about the Commits
mailing list