mirror of
https://github.com/RGBCube/serenity
synced 2025-05-31 22:58:11 +00:00
Kernel: Make copy_to/from_user safe and remove unnecessary checks
Since the CPU already does almost all necessary validation steps for us, we don't really need to attempt to do this. Doing it ourselves doesn't really work very reliably, because we'd have to account for other processors modifying virtual memory, and we'd have to account for e.g. pages not being able to be allocated due to insufficient resources. So change the copy_to/from_user (and associated helper functions) to use the new safe_memcpy, which will return whether it succeeded or not. The only manual validation step needed (which the CPU can't perform for us) is making sure the pointers provided by user mode aren't pointing to kernel mappings. To make it easier to read/write from/to either kernel or user mode data add the UserOrKernelBuffer helper class, which will internally either use copy_from/to_user or directly memcpy, or pass the data through directly using a temporary buffer on the stack. Last but not least we need to keep syscall params trivial as we need to copy them from/to user mode using copy_from/to_user.
This commit is contained in:
parent
7d1b8417bd
commit
c8d9f1b9c9
149 changed files with 1585 additions and 1244 deletions
|
@ -37,7 +37,7 @@ class SlavePTY final : public TTY {
|
|||
public:
|
||||
virtual ~SlavePTY() override;
|
||||
|
||||
void on_master_write(const u8*, ssize_t);
|
||||
void on_master_write(const UserOrKernelBuffer&, ssize_t);
|
||||
unsigned index() const { return m_index; }
|
||||
|
||||
time_t time_of_last_write() const { return m_time_of_last_write; }
|
||||
|
@ -45,12 +45,12 @@ public:
|
|||
private:
|
||||
// ^TTY
|
||||
virtual String tty_name() const override;
|
||||
virtual ssize_t on_tty_write(const u8*, ssize_t) override;
|
||||
virtual ssize_t on_tty_write(const UserOrKernelBuffer&, ssize_t) override;
|
||||
virtual void echo(u8) override;
|
||||
|
||||
// ^CharacterDevice
|
||||
virtual bool can_read(const FileDescription&, size_t) const override;
|
||||
virtual KResultOr<size_t> read(FileDescription&, size_t, u8*, size_t) override;
|
||||
virtual KResultOr<size_t> read(FileDescription&, size_t, UserOrKernelBuffer&, size_t) override;
|
||||
virtual bool can_write(const FileDescription&, size_t) const override;
|
||||
virtual const char* class_name() const override { return "SlavePTY"; }
|
||||
virtual KResult close() override;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue