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

Kernel: Clarify ambiguous {File,Description}::absolute_path

Found due to smelly code in InodeFile::absolute_path.

In particular, this replaces the following misleading methods:

File::absolute_path
This method *never* returns an actual path, and if called on an
InodeFile (which is impossible), it would VERIFY_NOT_REACHED().

OpenFileDescription::try_serialize_absolute_path
OpenFileDescription::absolute_path
These methods do not guarantee to return an actual path (just like the
other method), and just like Custody::absolute_path they do not
guarantee accuracy. In particular, just renaming the method made a
TOCTOU bug obvious.

The new method signatures use KResultOr, just like
try_serialize_absolute_path() already did.
This commit is contained in:
Ben Wiederhake 2021-10-30 00:45:23 +02:00 committed by Andreas Kling
parent 88ca12f037
commit c05c5a7ff4
28 changed files with 83 additions and 65 deletions

View file

@ -89,15 +89,14 @@ KResultOr<Memory::Region*> InodeFile::mmap(Process& process, OpenFileDescription
vmobject = TRY(Memory::SharedInodeVMObject::try_create_with_inode(inode()));
else
vmobject = TRY(Memory::PrivateInodeVMObject::try_create_with_inode(inode()));
auto path = TRY(description.try_serialize_absolute_path());
auto path = TRY(description.pseudo_path());
return process.address_space().allocate_region_with_vmobject(range, vmobject.release_nonnull(), offset, path->view(), prot, shared);
}
String InodeFile::absolute_path(const OpenFileDescription& description) const
KResultOr<NonnullOwnPtr<KString>> InodeFile::pseudo_path(const OpenFileDescription&) const
{
// If it has an inode, then it has a path, and therefore the caller should have been able to get a custody at some point.
VERIFY_NOT_REACHED();
VERIFY(description.custody());
return description.absolute_path();
}
KResult InodeFile::truncate(u64 size)