Kernel: Fix kernel crash in get_dir_entries when buffer too small.

Before e06362de9487806df92cf2360a42d3eed905b6bf this was a sneaky buffer
overflow. BufferStream did not do range checking and continued to write
past the allocated buffer (the size of which was controlled by the
user.)

The issue surfaced after my changes because OutputMemoryStream does
range checking.

Not sure how exploitable that bug was, directory entries are somewhat
controllable by the user but the buffer was on the heap, so exploiting
that should be tough.
This commit is contained in:
asynts 2020-09-16 16:55:29 +02:00 committed by Andreas Kling
parent f69281573e
commit 0579a2db34
Notes: sideshowbarker 2024-07-19 02:23:07 +09:00

View file

@ -191,7 +191,7 @@ ssize_t FileDescription::get_dir_entries(UserOrKernelBuffer& buffer, ssize_t siz
if (result.is_error())
return result;
if (static_cast<size_t>(size) < stream.size())
if (stream.handle_recoverable_error())
return -EINVAL;
if (!buffer.write(stream.bytes()))