diff options
author | Andreas Kling <kling@serenityos.org> | 2020-01-19 09:14:14 +0100 |
---|---|---|
committer | Andreas Kling <kling@serenityos.org> | 2020-01-19 09:18:55 +0100 |
commit | f7b394e9a1dbf5bb7285b317532c21f84e583e61 (patch) | |
tree | de2d9dee9c29ee962ac1753e846360f3494cb5a3 /Kernel/VM/MemoryManager.h | |
parent | 2cd212e5df009cb34239ded40c416e0d1c243207 (diff) | |
download | serenity-f7b394e9a1dbf5bb7285b317532c21f84e583e61.zip |
Kernel: Assert that copy_to/from_user() are called with user addresses
This will panic the kernel immediately if these functions are misused
so we can catch it and fix the misuse.
This patch fixes a couple of misuses:
- create_signal_trampolines() writes to a user-accessible page
above the 3GB address mark. We should really get rid of this
page but that's a whole other thing.
- CoW faults need to use copy_from_user rather than copy_to_user
since it's the *source* pointer that points to user memory.
- Inode faults need to use memcpy rather than copy_to_user since
we're copying a kernel stack buffer into a quickmapped page.
This should make the copy_to/from_user() functions slightly less useful
for exploitation. Before this, they were essentially just glorified
memcpy() with SMAP disabled. :^)
Diffstat (limited to 'Kernel/VM/MemoryManager.h')
-rw-r--r-- | Kernel/VM/MemoryManager.h | 7 |
1 files changed, 7 insertions, 0 deletions
diff --git a/Kernel/VM/MemoryManager.h b/Kernel/VM/MemoryManager.h index d9965cbe6e..27210ac609 100644 --- a/Kernel/VM/MemoryManager.h +++ b/Kernel/VM/MemoryManager.h @@ -214,3 +214,10 @@ inline bool is_user_address(VirtualAddress vaddr) { return vaddr.get() < 0xc0000000; } + +inline bool is_user_range(VirtualAddress vaddr, size_t size) +{ + if (vaddr.offset(size) < vaddr) + return false; + return is_user_address(vaddr) && is_user_address(vaddr.offset(size)); +} |