From 0558e8040c0d9628858ddd85ce573b9c80941a1f Mon Sep 17 00:00:00 2001 From: Amlal EL Mahrouss Date: Sat, 29 Jun 2024 23:45:47 +0200 Subject: Implement ipc_sanitize_packet as syscall. Signed-off-by: Amlal EL Mahrouss --- Kernel/Sources/HError.cxx | 2 +- Kernel/Sources/Network/IPCEP.cxx | 40 ++++++++++++++++++++++++++++++++++------ 2 files changed, 35 insertions(+), 7 deletions(-) (limited to 'Kernel/Sources') diff --git a/Kernel/Sources/HError.cxx b/Kernel/Sources/HError.cxx index 5ba02049..d38f2e07 100644 --- a/Kernel/Sources/HError.cxx +++ b/Kernel/Sources/HError.cxx @@ -11,7 +11,7 @@ namespace NewOS /// @brief Doea a system wide bug check. /// @param void no params. /// @return if error-free: true, otherwise false. - Boolean ke_bug_check(void) noexcept + Boolean err_bug_check(void) noexcept { /// TODO: return false; diff --git a/Kernel/Sources/Network/IPCEP.cxx b/Kernel/Sources/Network/IPCEP.cxx index 0cd9d778..9e198385 100644 --- a/Kernel/Sources/Network/IPCEP.cxx +++ b/Kernel/Sources/Network/IPCEP.cxx @@ -5,10 +5,14 @@ ------------------------------------------- */ #include +#include +#include using namespace NewOS; -Bool ipc_sanitize_packet(IPCEPMessageHeader* pckt) +/// @internal +/// @brief The internal sanitize function. +Bool __ipc_sanitize_packet(IPCEPMessageHeader* pckt) { if (!pckt) return false; @@ -19,25 +23,49 @@ Bool ipc_sanitize_packet(IPCEPMessageHeader* pckt) case Endian::kEndianBig: { if (pckt->IpcEndianess == eIPCEPLittleEndian) - return false; + goto _Fail; break; } case Endian::kEndianLittle: { if (pckt->IpcEndianess == eIPCEPBigEndian) - return false; + goto _Fail; break; } case Endian::kEndianMixed: break; default: - return false; + goto _Fail; } - if (pckt->IpcFrom == pckt->IpcTo) return false; - if (pckt->IpcPacketSize > cIPCEPMsgSize) return false; + if (pckt->IpcFrom == pckt->IpcTo) + { + goto _Fail; + } + if (pckt->IpcPacketSize > cIPCEPMsgSize) + { + goto _Fail; + } return pckt->IpcPacketSize > 1 && pckt->IpcHeaderMagic == cRemoteHeaderMagic; + +_Fail: + ErrLocal() = kErrorIPC; + return false; +} + +/// @brief Sanitize packet function +/// @retval true packet is correct. +/// @retval false packet is incorrect and process has crashed. +Bool ipc_sanitize_packet(IPCEPMessageHeader* pckt) +{ + if (!__ipc_sanitize_packet(pckt)) + { + ProcessScheduler::The().Leak().TheCurrent().Leak().Crash(); + return false; + } + + return true; } -- cgit v1.2.3