From dfce9051faf758c9eddae5f5607f6cdd734eeef6 Mon Sep 17 00:00:00 2001 From: Andreas Kling Date: Mon, 23 Nov 2020 16:19:30 +0100 Subject: [PATCH] ProcFS: Take the "all inodes" lock when generating /proc/inodes Otherwise the kernel asserts. --- Kernel/FileSystem/Inode.cpp | 5 +++++ Kernel/FileSystem/Inode.h | 2 ++ Kernel/FileSystem/ProcFS.cpp | 1 + 3 files changed, 8 insertions(+) diff --git a/Kernel/FileSystem/Inode.cpp b/Kernel/FileSystem/Inode.cpp index 106c39ffd6..e19ffcac90 100644 --- a/Kernel/FileSystem/Inode.cpp +++ b/Kernel/FileSystem/Inode.cpp @@ -41,6 +41,11 @@ namespace Kernel { static SpinLock s_all_inodes_lock; static AK::Singleton> s_list; +SpinLock& Inode::all_inodes_lock() +{ + return s_all_inodes_lock; +} + InlineLinkedList& Inode::all_with_lock() { ASSERT(s_all_inodes_lock.is_locked()); diff --git a/Kernel/FileSystem/Inode.h b/Kernel/FileSystem/Inode.h index 2567e6fcc4..7cea0178c6 100644 --- a/Kernel/FileSystem/Inode.h +++ b/Kernel/FileSystem/Inode.h @@ -120,6 +120,8 @@ public: Inode* m_next { nullptr }; Inode* m_prev { nullptr }; + static SpinLock& all_inodes_lock(); + protected: Inode(FS& fs, unsigned index); void set_metadata_dirty(bool); diff --git a/Kernel/FileSystem/ProcFS.cpp b/Kernel/FileSystem/ProcFS.cpp index d3ab37c2ad..6e5996a23b 100644 --- a/Kernel/FileSystem/ProcFS.cpp +++ b/Kernel/FileSystem/ProcFS.cpp @@ -914,6 +914,7 @@ static Optional procfs$inodes(InodeIdentifier) { KBufferBuilder builder; InterruptDisabler disabler; + ScopedSpinLock all_inodes_lock(Inode::all_inodes_lock()); for (auto& inode : Inode::all_with_lock()) { builder.appendf("Inode{K%x} %02u:%08u (%u)\n", &inode, inode.fsid(), inode.index(), inode.ref_count()); }