mirror of
https://github.com/RGBCube/serenity
synced 2025-07-25 17:07:34 +00:00
Kernel: AnonymousVMObject::create_for_physical_range() should fail more
Previously it was not possible for this function to fail. You could exploit this by triggering the creation of a VMObject whose physical memory range would wrap around the 32-bit limit. It was quite easy to map kernel memory into userspace and read/write whatever you wanted in it. Test: Kernel/bxvga-mmap-kernel-into-userspace.cpp
This commit is contained in:
parent
bd059e32e1
commit
c17f80e720
6 changed files with 109 additions and 6 deletions
|
@ -116,10 +116,12 @@ KResultOr<Region*> BXVGADevice::mmap(Process& process, FileDescription&, Virtual
|
|||
ASSERT(offset == 0);
|
||||
ASSERT(size == framebuffer_size_in_bytes());
|
||||
auto vmobject = AnonymousVMObject::create_for_physical_range(m_framebuffer_address, framebuffer_size_in_bytes());
|
||||
if (!vmobject)
|
||||
return KResult(-ENOMEM);
|
||||
auto* region = process.allocate_region_with_vmobject(
|
||||
preferred_vaddr,
|
||||
framebuffer_size_in_bytes(),
|
||||
move(vmobject),
|
||||
vmobject.release_nonnull(),
|
||||
0,
|
||||
"BXVGA Framebuffer",
|
||||
prot);
|
||||
|
|
|
@ -55,10 +55,12 @@ KResultOr<Region*> MBVGADevice::mmap(Process& process, FileDescription&, Virtual
|
|||
ASSERT(offset == 0);
|
||||
ASSERT(size == framebuffer_size_in_bytes());
|
||||
auto vmobject = AnonymousVMObject::create_for_physical_range(m_framebuffer_address, framebuffer_size_in_bytes());
|
||||
if (!vmobject)
|
||||
return KResult(-ENOMEM);
|
||||
auto* region = process.allocate_region_with_vmobject(
|
||||
preferred_vaddr,
|
||||
framebuffer_size_in_bytes(),
|
||||
move(vmobject),
|
||||
vmobject.release_nonnull(),
|
||||
0,
|
||||
"MBVGA Framebuffer",
|
||||
prot);
|
||||
|
|
|
@ -32,8 +32,12 @@ NonnullRefPtr<AnonymousVMObject> AnonymousVMObject::create_with_size(size_t size
|
|||
return adopt(*new AnonymousVMObject(size));
|
||||
}
|
||||
|
||||
NonnullRefPtr<AnonymousVMObject> AnonymousVMObject::create_for_physical_range(PhysicalAddress paddr, size_t size)
|
||||
RefPtr<AnonymousVMObject> AnonymousVMObject::create_for_physical_range(PhysicalAddress paddr, size_t size)
|
||||
{
|
||||
if (paddr.offset(size) < paddr) {
|
||||
dbg() << "Shenanigans! create_for_physical_range(" << paddr << ", " << size << ") would wrap around";
|
||||
return nullptr;
|
||||
}
|
||||
return adopt(*new AnonymousVMObject(paddr, size));
|
||||
}
|
||||
|
||||
|
|
|
@ -34,7 +34,7 @@ public:
|
|||
virtual ~AnonymousVMObject() override;
|
||||
|
||||
static NonnullRefPtr<AnonymousVMObject> create_with_size(size_t);
|
||||
static NonnullRefPtr<AnonymousVMObject> create_for_physical_range(PhysicalAddress, size_t);
|
||||
static RefPtr<AnonymousVMObject> create_for_physical_range(PhysicalAddress, size_t);
|
||||
static NonnullRefPtr<AnonymousVMObject> create_with_physical_page(PhysicalPage&);
|
||||
virtual NonnullRefPtr<VMObject> clone() override;
|
||||
|
||||
|
|
|
@ -313,11 +313,14 @@ OwnPtr<Region> MemoryManager::allocate_kernel_region(PhysicalAddress paddr, size
|
|||
ASSERT(!(size % PAGE_SIZE));
|
||||
auto range = kernel_page_directory().range_allocator().allocate_anywhere(size);
|
||||
ASSERT(range.is_valid());
|
||||
auto vmobject = AnonymousVMObject::create_for_physical_range(paddr, size);
|
||||
if (!vmobject)
|
||||
return nullptr;
|
||||
OwnPtr<Region> region;
|
||||
if (user_accessible)
|
||||
region = Region::create_user_accessible(range, AnonymousVMObject::create_for_physical_range(paddr, size), 0, name, access, cacheable);
|
||||
region = Region::create_user_accessible(range, vmobject.release_nonnull(), 0, name, access, cacheable);
|
||||
else
|
||||
region = Region::create_kernel_only(range, AnonymousVMObject::create_for_physical_range(paddr, size), 0, name, access, cacheable);
|
||||
region = Region::create_kernel_only(range, vmobject.release_nonnull(), 0, name, access, cacheable);
|
||||
region->map(kernel_page_directory());
|
||||
return region;
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue