From 88b722965aebd26417161026478cdeb931a2aca5 Mon Sep 17 00:00:00 2001 From: Michael Lotz Date: Sat, 26 Jul 2014 00:21:20 +0200 Subject: [PATCH] exfat: Add missing locking around SplayTree lookup/insertion. A lookup in a splay tree does move the looked up entry to the root of the tree. This means the tree structure is modified on lookup alone. Obviously the tree structure is also modified when inserting new nodes. For both of these reasons access to the f{Node|Ino}Tree needs to be locked on lookup and insert. Fixes crashes when the tree is concurrently modified by multiple threads accessing the same exfat volume. In addition this protects the fNextId field that hands out new inode ids. --- src/add-ons/kernel/file_systems/exfat/Volume.cpp | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/add-ons/kernel/file_systems/exfat/Volume.cpp b/src/add-ons/kernel/file_systems/exfat/Volume.cpp index 1e885045f3..44f6d2e189 100644 --- a/src/add-ons/kernel/file_systems/exfat/Volume.cpp +++ b/src/add-ons/kernel/file_systems/exfat/Volume.cpp @@ -463,6 +463,8 @@ Volume::GetIno(cluster_t cluster, uint32 offset, ino_t parent) struct node_key key; key.cluster = cluster; key.offset = offset; + + MutexLocker locker(fLock); struct node* node = fNodeTree.Lookup(key); if (node != NULL) { TRACE("Volume::GetIno() cached cluster %" B_PRIu32 " offset %" B_PRIu32 @@ -484,6 +486,7 @@ Volume::GetIno(cluster_t cluster, uint32 offset, ino_t parent) struct node_key* Volume::GetNode(ino_t ino, ino_t &parent) { + MutexLocker locker(fLock); struct node* node = fInoTree.Lookup(ino); if (node != NULL) { parent = node->parent;