From c9892ac20fefed27afbe5dfe0427969eab24e1b1 Mon Sep 17 00:00:00 2001 From: Augustin Cavalier Date: Thu, 16 Jan 2025 23:21:47 -0500 Subject: [PATCH] ramfs: A write lock is needed when truncating files. Should fix all KDLs in #19360. --- .../kernel/file_systems/ramfs/kernel_interface.cpp | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/src/add-ons/kernel/file_systems/ramfs/kernel_interface.cpp b/src/add-ons/kernel/file_systems/ramfs/kernel_interface.cpp index 19d0063e0f..57ee444862 100644 --- a/src/add-ons/kernel/file_systems/ramfs/kernel_interface.cpp +++ b/src/add-ons/kernel/file_systems/ramfs/kernel_interface.cpp @@ -952,8 +952,8 @@ ramfs_open(fs_volume* _volume, fs_vnode* _node, int openMode, void** _cookie) FUNCTION(("node: %lld\n", node->GetID())); - VolumeReadLocker locker(volume); - if (!locker.IsLocked()) + VolumeReadLocker readLocker(volume); + if (!readLocker.IsLocked()) RETURN_ERROR(B_ERROR); status_t error = B_OK; @@ -974,10 +974,16 @@ ramfs_open(fs_volume* _volume, fs_vnode* _node, int openMode, void** _cookie) if (!cookie) SET_ERROR(error, B_NO_MEMORY); } + readLocker.Unlock(); + // truncate if requested - if (error == B_OK && (openMode & O_TRUNC)) + if (error == B_OK && (openMode & O_TRUNC)) { + VolumeWriteLocker writeLocker(volume); + error = node->SetSize(0); - NodeMTimeUpdater mTimeUpdater(node); + NodeMTimeUpdater mTimeUpdater(node); + } + // set result / cleanup on failure if (error == B_OK) *_cookie = cookie;