1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-05-31 06:58:11 +00:00

Kernel: Make Inode::lookup() return a RefPtr<Inode>

Previously this API would return an InodeIdentifier, which meant that
there was a race in path resolution where an inode could be unlinked
in between finding the InodeIdentifier for a path component, and
actually resolving that to an Inode object.

Attaching a test that would quickly trip an assertion before.

Test: Kernel/path-resolution-race.cpp
This commit is contained in:
Andreas Kling 2020-02-01 09:23:46 +01:00
parent 5aa37f6f5c
commit c44b4d61f3
11 changed files with 50 additions and 36 deletions

View file

@ -233,20 +233,20 @@ ssize_t TmpFSInode::write_bytes(off_t offset, ssize_t size, const u8* buffer, Fi
return size;
}
InodeIdentifier TmpFSInode::lookup(StringView name)
RefPtr<Inode> TmpFSInode::lookup(StringView name)
{
LOCKER(m_lock);
ASSERT(is_directory());
if (name == ".")
return identifier();
return fs().get_inode(identifier());
if (name == "..")
return m_parent;
return fs().get_inode(m_parent);
auto it = m_children.find(name);
if (it == m_children.end())
return {};
return it->value.entry.inode;
return fs().get_inode(it->value.entry.inode);
}
size_t TmpFSInode::directory_entry_count() const