From f96456d86346808ec6e7d33fd79abe1d4c06207e Mon Sep 17 00:00:00 2001 From: Augustin Cavalier Date: Mon, 19 Jun 2023 14:27:48 -0400 Subject: [PATCH] kernel/vfs: Fix missing lock in fs_mount(). At least a read lock of the sVnodeLock must be held when calling lookup_vnode, but we held none at all. This rectifies that problem. This bug appears to have been around for many years, but no-one noticed since ASSERT_READ_LOCKED_RW_LOCK only works with more debug options turned on than the kernel is built with. I discovered this while working on a new version of those additional options. --- src/system/kernel/fs/vfs.cpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/system/kernel/fs/vfs.cpp b/src/system/kernel/fs/vfs.cpp index e00b9700ae..8239cf0085 100644 --- a/src/system/kernel/fs/vfs.cpp +++ b/src/system/kernel/fs/vfs.cpp @@ -7677,15 +7677,16 @@ fs_mount(char* path, const char* device, const char* fsName, uint32 flags, // the root node is supposed to be owned by the file system - it must // exist at this point + rw_lock_write_lock(&sVnodeLock); mount->root_vnode = lookup_vnode(mount->id, rootID); if (mount->root_vnode == NULL || mount->root_vnode->ref_count != 1) { panic("fs_mount: file system does not own its root node!\n"); status = B_ERROR; + rw_lock_write_unlock(&sVnodeLock); goto err4; } // set up the links between the root vnode and the vnode it covers - rw_lock_write_lock(&sVnodeLock); if (coveredNode != NULL) { if (coveredNode->IsCovered()) { // the vnode is covered now