Skip to content

Commit

Permalink
Kernel: When validating a string read, validate the pointer first.
Browse files Browse the repository at this point in the history
Calling strlen() on an invalid pointer is just gonna crash the process.
  • Loading branch information
awesomekling committed Feb 7, 2019
1 parent 887b4a7 commit f4bce03
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 1 deletion.
7 changes: 7 additions & 0 deletions Kernel/Process.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1643,6 +1643,13 @@ bool Process::validate_read_from_kernel(LinearAddress laddr) const
return validate_read(laddr.as_ptr(), 1);
}

bool Process::validate_read_str(const char* str)
{
if (!validate_read(str, 1))
return false;
return validate_read(str, strlen(str) + 1);
}

bool Process::validate_read(const void* address, size_t size) const
{
if (is_ring0()) {
Expand Down
2 changes: 1 addition & 1 deletion Kernel/Process.h
Original file line number Diff line number Diff line change
Expand Up @@ -267,7 +267,7 @@ class Process : public InlineLinkedListNode<Process>, public Weakable<Process> {

bool validate_read(const void*, size_t) const;
bool validate_write(void*, size_t) const;
bool validate_read_str(const char* str) { return validate_read(str, strlen(str) + 1); }
bool validate_read_str(const char* str);
template<typename T> bool validate_read_typed(T* value, size_t count = 1) { return validate_read(value, sizeof(T) * count); }
template<typename T> bool validate_write_typed(T* value, size_t count = 1) { return validate_write(value, sizeof(T) * count); }

Expand Down

0 comments on commit f4bce03

Please sign in to comment.