summaryrefslogtreecommitdiff
path: root/Kernel/Process.cpp
diff options
context:
space:
mode:
authorRobin Burchell <robin+git@viroteck.net>2019-07-19 17:46:21 +0200
committerAndreas Kling <awesomekling@gmail.com>2019-07-19 19:06:28 +0200
commit2d4d465206d0ca2bc6f1cc70edba89b848768f98 (patch)
tree2fbb25ab6087aa272dc03cd1bd0df84529364ef1 /Kernel/Process.cpp
parentf8beb0f665af7d21bfe36f48647b8cd88f331c52 (diff)
downloadserenity-2d4d465206d0ca2bc6f1cc70edba89b848768f98.zip
SharedBuffer: Fix a denial of service
It's a very bad idea to increment the refcount on behalf of another process. That process may (for either benign or evil reasons) not reference the SharedBuffer, and then we'll be stuck with loads of SharedBuffers until we OOM. Instead, increment the refcount when the buffer is mapped. That way, a buffer is only kept if *someone* has explicitly requested it via get_shared_buffer. Fixes #341
Diffstat (limited to 'Kernel/Process.cpp')
-rw-r--r--Kernel/Process.cpp6
1 files changed, 3 insertions, 3 deletions
diff --git a/Kernel/Process.cpp b/Kernel/Process.cpp
index e051d1ed13..5b143240e3 100644
--- a/Kernel/Process.cpp
+++ b/Kernel/Process.cpp
@@ -2408,7 +2408,7 @@ int Process::sys$create_shared_buffer(int size, void** buffer)
int shared_buffer_id = ++s_next_shared_buffer_id;
auto shared_buffer = make<SharedBuffer>(shared_buffer_id, size);
shared_buffer->share_with(m_pid);
- *buffer = shared_buffer->get_address(*this);
+ *buffer = shared_buffer->ref_for_process_and_get_address(*this);
ASSERT((int)shared_buffer->size() >= size);
#ifdef SHARED_BUFFER_DEBUG
kprintf("%s(%u): Created shared buffer %d @ %p (%u bytes, vmo is %u)\n", name().characters(), pid(), shared_buffer_id, *buffer, size, shared_buffer->size());
@@ -2447,7 +2447,7 @@ int Process::sys$release_shared_buffer(int shared_buffer_id)
#ifdef SHARED_BUFFER_DEBUG
kprintf("%s(%u): Releasing shared buffer %d, buffer count: %u\n", name().characters(), pid(), shared_buffer_id, shared_buffers().resource().size());
#endif
- shared_buffer.release(*this);
+ shared_buffer.deref_for_process(*this);
return 0;
}
@@ -2463,7 +2463,7 @@ void* Process::sys$get_shared_buffer(int shared_buffer_id)
#ifdef SHARED_BUFFER_DEBUG
kprintf("%s(%u): Retaining shared buffer %d, buffer count: %u\n", name().characters(), pid(), shared_buffer_id, shared_buffers().resource().size());
#endif
- return shared_buffer.get_address(*this);
+ return shared_buffer.ref_for_process_and_get_address(*this);
}
int Process::sys$seal_shared_buffer(int shared_buffer_id)