mirror of
https://github.com/RGBCube/serenity
synced 2025-05-26 02:05:08 +00:00
Kernel: Handle mmap requests on zero-length data file inodes safely
This commit is contained in:
parent
c88cc8557f
commit
3ad0e1a1d5
5 changed files with 28 additions and 5 deletions
|
@ -12,7 +12,17 @@ namespace Kernel::Memory {
|
|||
|
||||
ErrorOr<NonnullLockRefPtr<SharedInodeVMObject>> SharedInodeVMObject::try_create_with_inode(Inode& inode)
|
||||
{
|
||||
size_t size = inode.size();
|
||||
if (inode.size() == 0)
|
||||
return EINVAL;
|
||||
return try_create_with_inode_and_range(inode, 0, inode.size());
|
||||
}
|
||||
|
||||
ErrorOr<NonnullLockRefPtr<SharedInodeVMObject>> SharedInodeVMObject::try_create_with_inode_and_range(Inode& inode, u64 offset, size_t range_size)
|
||||
{
|
||||
// Note: To ensure further allocation of a Region with this VMObject will not complain
|
||||
// on "smaller" VMObject than the requested Region, we simply take the max size between both values.
|
||||
auto size = max(inode.size(), (offset + range_size));
|
||||
VERIFY(size > 0);
|
||||
if (auto shared_vmobject = inode.shared_vmobject())
|
||||
return shared_vmobject.release_nonnull();
|
||||
auto new_physical_pages = TRY(VMObject::try_create_physical_pages(size));
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue