1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-05-20 18:15:07 +00:00

Kernel/FS: Fix check-then-act concurrency bug in FileSystem/Inode

When the FileSystem does a sync, it gathers up all the inodes with
dirty metadata into a vector. The inode mutex is not held while
checking the inode dirty bit, which can lead to a kernel panic
due to concurrent inode modifications.

Fixes: #21796
This commit is contained in:
Blake Smith 2023-11-19 19:15:37 -06:00 committed by Andreas Kling
parent 2372584b18
commit e346331424
2 changed files with 4 additions and 3 deletions

View file

@ -494,6 +494,9 @@ InodeMetadata Ext2FSInode::metadata() const
ErrorOr<void> Ext2FSInode::flush_metadata()
{
MutexLocker locker(m_inode_lock);
if (!is_metadata_dirty())
return {};
dbgln_if(EXT2_DEBUG, "Ext2FSInode[{}]::flush_metadata(): Flushing inode", identifier());
TRY(fs().write_ext2_inode(index(), m_raw_inode));
if (is_directory()) {