mirror of
				https://github.com/RGBCube/serenity
				synced 2025-10-31 00:42:44 +00:00 
			
		
		
		
	 c05c5a7ff4
			
		
	
	
		c05c5a7ff4
		
	
	
	
	
		
			
			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.
		
			
				
	
	
		
			38 lines
		
	
	
	
		
			948 B
		
	
	
	
		
			C++
		
	
	
	
	
	
			
		
		
	
	
			38 lines
		
	
	
	
		
			948 B
		
	
	
	
		
			C++
		
	
	
	
	
	
| /*
 | |
|  * Copyright (c) 2021, Andreas Kling <kling@serenityos.org>
 | |
|  *
 | |
|  * SPDX-License-Identifier: BSD-2-Clause
 | |
|  */
 | |
| 
 | |
| #include <Kernel/FileSystem/AnonymousFile.h>
 | |
| #include <Kernel/Memory/AnonymousVMObject.h>
 | |
| #include <Kernel/Process.h>
 | |
| 
 | |
| namespace Kernel {
 | |
| 
 | |
| AnonymousFile::AnonymousFile(NonnullRefPtr<Memory::AnonymousVMObject> vmobject)
 | |
|     : m_vmobject(move(vmobject))
 | |
| {
 | |
| }
 | |
| 
 | |
| AnonymousFile::~AnonymousFile()
 | |
| {
 | |
| }
 | |
| 
 | |
| KResultOr<Memory::Region*> AnonymousFile::mmap(Process& process, OpenFileDescription&, Memory::VirtualRange const& range, u64 offset, int prot, bool shared)
 | |
| {
 | |
|     if (offset != 0)
 | |
|         return EINVAL;
 | |
| 
 | |
|     if (range.size() != m_vmobject->size())
 | |
|         return EINVAL;
 | |
| 
 | |
|     return process.address_space().allocate_region_with_vmobject(range, m_vmobject, offset, {}, prot, shared);
 | |
| }
 | |
| 
 | |
| KResultOr<NonnullOwnPtr<KString>> AnonymousFile::pseudo_path(const OpenFileDescription&) const
 | |
| {
 | |
|     return KString::try_create(":anonymous-file:"sv);
 | |
| }
 | |
| 
 | |
| }
 |