diff options
author | Andreas Kling <awesomekling@gmail.com> | 2020-01-05 18:00:15 +0100 |
---|---|---|
committer | Andreas Kling <awesomekling@gmail.com> | 2020-01-05 18:14:51 +0100 |
commit | 9eef39d68a99c5e29099ae4eb4a56934b35eecde (patch) | |
tree | 992cd16e74009907740a54df812f1f791a92b385 /Kernel/FileSystem | |
parent | 04b734501a6be77501b21f787607963f253ebc32 (diff) | |
download | serenity-9eef39d68a99c5e29099ae4eb4a56934b35eecde.zip |
Kernel: Start implementing x86 SMAP support
Supervisor Mode Access Prevention (SMAP) is an x86 CPU feature that
prevents the kernel from accessing userspace memory. With SMAP enabled,
trying to read/write a userspace memory address while in the kernel
will now generate a page fault.
Since it's sometimes necessary to read/write userspace memory, there
are two new instructions that quickly switch the protection on/off:
STAC (disables protection) and CLAC (enables protection.)
These are exposed in kernel code via the stac() and clac() helpers.
There's also a SmapDisabler RAII object that can be used to ensure
that you don't forget to re-enable protection before returning to
userspace code.
THis patch also adds copy_to_user(), copy_from_user() and memset_user()
which are the "correct" way of doing things. These functions allow us
to briefly disable protection for a specific purpose, and then turn it
back on immediately after it's done. Going forward all kernel code
should be moved to using these and all uses of SmapDisabler are to be
considered FIXME's.
Note that we're not realizing the full potential of this feature since
I've used SmapDisabler quite liberally in this initial bring-up patch.
Diffstat (limited to 'Kernel/FileSystem')
-rw-r--r-- | Kernel/FileSystem/FileDescription.cpp | 5 |
1 files changed, 4 insertions, 1 deletions
diff --git a/Kernel/FileSystem/FileDescription.cpp b/Kernel/FileSystem/FileDescription.cpp index 0a4514db48..13c3850ffd 100644 --- a/Kernel/FileSystem/FileDescription.cpp +++ b/Kernel/FileSystem/FileDescription.cpp @@ -48,6 +48,7 @@ FileDescription::~FileDescription() KResult FileDescription::fstat(stat& buffer) { + SmapDisabler disabler; if (is_fifo()) { memset(&buffer, 0, sizeof(buffer)); buffer.st_mode = 001000; @@ -102,6 +103,7 @@ off_t FileDescription::seek(off_t offset, int whence) ssize_t FileDescription::read(u8* buffer, ssize_t count) { + SmapDisabler disabler; int nread = m_file->read(*this, buffer, count); if (nread > 0 && m_file->is_seekable()) m_current_offset += nread; @@ -110,6 +112,7 @@ ssize_t FileDescription::read(u8* buffer, ssize_t count) ssize_t FileDescription::write(const u8* data, ssize_t size) { + SmapDisabler disabler; int nwritten = m_file->write(*this, data, size); if (nwritten > 0 && m_file->is_seekable()) m_current_offset += nwritten; @@ -160,7 +163,7 @@ ssize_t FileDescription::get_dir_entries(u8* buffer, ssize_t size) if (size < temp_buffer.size()) return -1; - memcpy(buffer, temp_buffer.data(), temp_buffer.size()); + copy_to_user(buffer, temp_buffer.data(), temp_buffer.size()); return stream.offset(); } |