This is an automated email from the ASF dual-hosted git repository.

xiaoxiang781216 pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/nuttx.git


The following commit(s) were added to refs/heads/master by this push:
     new a72faaf0fa5 fs/tmpfs: lock parent dir in tmpfs_getpath()
a72faaf0fa5 is described below

commit a72faaf0fa50a896f3b0d3d886412dfa17576a69
Author: dengwenqi <[email protected]>
AuthorDate: Thu Nov 12 17:01:24 2026 +0800

    fs/tmpfs: lock parent dir in tmpfs_getpath()
    
    tmpfs_getpath() walks the parent's tdo_entry[] and copies tde_name
    without the directory lock.  tmpfs_unlink(), tmpfs_rmdir() and
    tmpfs_rename() free names and move entries under that lock, so a
    concurrent F_GETPATH can read a freed name or a moved entry.  Hold
    the directory lock while searching and copying the name.
    
    Signed-off-by: dengwenqi <[email protected]>
    Signed-off-by: jingfei <[email protected]>
---
 fs/tmpfs/fs_tmpfs.c | 7 +++++++
 1 file changed, 7 insertions(+)

diff --git a/fs/tmpfs/fs_tmpfs.c b/fs/tmpfs/fs_tmpfs.c
index 64a48a3ce62..a40c7119363 100644
--- a/fs/tmpfs/fs_tmpfs.c
+++ b/fs/tmpfs/fs_tmpfs.c
@@ -1511,6 +1511,10 @@ static int tmpfs_getpath(FAR struct tmpfs_object_s *to,
 
       tdo = to->to_parent;
 
+      /* unlink/rename free names and compact tdo_entry[] under this lock */
+
+      tmpfs_lock_directory(tdo);
+
       for (i = 0; i < tdo->tdo_nentries; i++)
         {
           tde = &tdo->tdo_entry[i];
@@ -1522,6 +1526,7 @@ static int tmpfs_getpath(FAR struct tmpfs_object_s *to,
 
       if (i == tdo->tdo_nentries)
         {
+          tmpfs_unlock_directory(tdo);
           return -ENOENT;
         }
 
@@ -1530,6 +1535,8 @@ static int tmpfs_getpath(FAR struct tmpfs_object_s *to,
         {
           strlcat(path, "/", len);
         }
+
+      tmpfs_unlock_directory(tdo);
     }
 
   return OK;

Reply via email to