summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
-rw-r--r--Comm/herror.hxx1
-rw-r--r--Kernel/HALKit/AMD64/HalKernelMain.cxx9
-rw-r--r--Kernel/KernelKit/HError.hpp3
-rw-r--r--Kernel/Sources/HError.cxx2
-rw-r--r--Kernel/Sources/Network/IPCEP.cxx40
5 files changed, 46 insertions, 9 deletions
diff --git a/Comm/herror.hxx b/Comm/herror.hxx
index 6f6abf6f..7138055a 100644
--- a/Comm/herror.hxx
+++ b/Comm/herror.hxx
@@ -41,6 +41,7 @@ inline constexpr HError kErrorDisk = 55;
inline constexpr HError kErrorInvalidData = 56;
inline constexpr HError kErrorAsync = 57;
inline constexpr HError kErrorNonBlocking = 58;
+inline constexpr HError kErrorIPC = 59;
inline constexpr HError kErrorUnimplemented = 0;
inline HError kLastError = 0;
diff --git a/Kernel/HALKit/AMD64/HalKernelMain.cxx b/Kernel/HALKit/AMD64/HalKernelMain.cxx
index 7d641153..d8c60e25 100644
--- a/Kernel/HALKit/AMD64/HalKernelMain.cxx
+++ b/Kernel/HALKit/AMD64/HalKernelMain.cxx
@@ -17,6 +17,7 @@
#include <Modules/CoreCG/Accessibility.hxx>
#include <KernelKit/CodeManager.hpp>
#include <Modules/ACPI/ACPIFactoryInterface.hxx>
+#include <NetworkKit/IPCEP.hxx>
#define KERNEL_INIT(X) X; \
NewOS::ke_stop(RUNTIME_CHECK_BOOTSTRAP);
@@ -103,7 +104,7 @@ EXTERN_C void hal_init_platform(
CONST NewOS::HAL::IDTLoader cIDT;
cIDT.Load(idtBase);
- // register the basic NAPI syscalls.
+ // Register the basic SCI functions.
constexpr auto cSerialAlertInterrupt = 0x10;
constexpr auto cTlsInterrupt = 0x11;
@@ -123,6 +124,7 @@ EXTERN_C void hal_init_platform(
constexpr auto cLPCSendMsg = 0x25;
constexpr auto cLPCOpenMsg = 0x26;
constexpr auto cLPCCloseMsg = 0x27;
+ constexpr auto cLPCSanitizeMsg = 0x28;
kSyscalls[cSerialAlertInterrupt].Leak().Leak()->fProc = [](NewOS::VoidPtr rdx) -> void {
const char* msg = (const char*)rdx;
@@ -133,6 +135,10 @@ EXTERN_C void hal_init_platform(
tls_check_syscall_impl(rdx);
};
+ kSyscalls[cLPCSanitizeMsg].Leak().Leak()->fProc = [](NewOS::VoidPtr rdx) -> void {
+ NewOS::ipc_sanitize_packet(reinterpret_cast<NewOS::IPCEPMessageHeader*>(rdx));
+ };
+
kSyscalls[cNewInterrupt].Leak().Leak()->fProc = [](NewOS::VoidPtr rdx) -> void {
// get HAC struct.
HeapAllocInfo* rdxInf = reinterpret_cast<HeapAllocInfo*>(rdx);
@@ -198,6 +204,7 @@ EXTERN_C void hal_init_platform(
kSyscalls[cLastExitInterrupt].Leak().Leak()->fHooked = true;
kSyscalls[cShutdownInterrupt].Leak().Leak()->fHooked = true;
kSyscalls[cRebootInterrupt].Leak().Leak()->fHooked = true;
+ kSyscalls[cLPCSanitizeMsg].Leak().Leak()->fHooked = true;
NewOS::HAL::hal_system_get_cores(kHandoverHeader->f_HardwareTables.f_RsdPtr);
diff --git a/Kernel/KernelKit/HError.hpp b/Kernel/KernelKit/HError.hpp
index a61d84d4..468f9a12 100644
--- a/Kernel/KernelKit/HError.hpp
+++ b/Kernel/KernelKit/HError.hpp
@@ -46,8 +46,9 @@ namespace NewOS
inline constexpr HError kErrorInvalidData = 56;
inline constexpr HError kErrorAsync = 57;
inline constexpr HError kErrorNonBlocking = 58;
+ inline constexpr HError kErrorIPC = 59;
inline constexpr HError kErrorUnimplemented = 0;
- Boolean ke_bug_check(void) noexcept;
+ Boolean err_bug_check(void) noexcept;
} // namespace NewOS
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 <NetworkKit/IPCEP.hxx>
+#include <KernelKit/HError.hpp>
+#include <KernelKit/ProcessScheduler.hxx>
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;
}