git: DragonFly_RELEASE_6_2 tmpfs - Fix readdir() races

Matthew Dillon dillon at
Mon Jan 24 12:55:04 PST 2022

commit 118b483795f2643e8959543b27a5ce4e3a1c7711
Author: Matthew Dillon <dillon at>
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(-)

DragonFly BSD source repository

More information about the Commits mailing list