-
Notifications
You must be signed in to change notification settings - Fork 1
Development #104
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Development #104
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| @@ -1,5 +1,6 @@ | ||||||||||||||||||||
| #include "Process.h" | ||||||||||||||||||||
| #include "Atomics.h" | ||||||||||||||||||||
| #include "KernelHeap.h" | ||||||||||||||||||||
| #ifdef VF_CONFIG_USE_CERBERUS | ||||||||||||||||||||
| #include "Cerberus.h" | ||||||||||||||||||||
| #endif | ||||||||||||||||||||
|
|
@@ -284,7 +285,7 @@ static void __attribute__((visibility("hidden"))) TerminateProcess(uint32_t pid, | |||||||||||||||||||
| #ifdef VF_CONFIG_USE_CERBERUS | ||||||||||||||||||||
| CerberusUnregisterProcess(proc->pid); | ||||||||||||||||||||
| #endif | ||||||||||||||||||||
| if (proc->ProcINFOPath && VfsIsDir(proc->ProcINFOPath)) VfsDelete(proc->ProcINFOPath, true); | ||||||||||||||||||||
| if (proc->ProcessRuntimePath && VfsIsDir(proc->ProcessRuntimePath)) VfsDelete(proc->ProcessRuntimePath, true); | ||||||||||||||||||||
| else PrintKernelWarning("ProcINFOPath invalid during termination\n"); | ||||||||||||||||||||
| } | ||||||||||||||||||||
|
|
||||||||||||||||||||
|
|
@@ -329,7 +330,7 @@ static void __attribute__((visibility("hidden"))) ASTerminate(uint32_t pid, cons | |||||||||||||||||||
|
|
||||||||||||||||||||
| SpinUnlockIrqRestore(&scheduler_lock, flags); | ||||||||||||||||||||
|
|
||||||||||||||||||||
| if (proc->ProcINFOPath && VfsIsDir(proc->ProcINFOPath)) VfsDelete(proc->ProcINFOPath, true); | ||||||||||||||||||||
| if (proc->ProcessRuntimePath && VfsIsDir(proc->ProcessRuntimePath)) VfsDelete(proc->ProcessRuntimePath, true); | ||||||||||||||||||||
| else PrintKernelWarning("ProcINFOPath invalid during termination"); | ||||||||||||||||||||
| } | ||||||||||||||||||||
|
|
||||||||||||||||||||
|
|
@@ -686,7 +687,7 @@ static void SmartAging(void) { | |||||||||||||||||||
| } | ||||||||||||||||||||
|
|
||||||||||||||||||||
| static inline __attribute__((visibility("hidden"))) __attribute__((always_inline)) int ProcINFOPathValidation(const ProcessControlBlock * proc) { | ||||||||||||||||||||
| if (FastStrCmp(proc->ProcINFOPath, FormatS("%s/%d", RuntimeProcesses, proc->pid)) != 0) return 0; | ||||||||||||||||||||
| if (FastStrCmp(proc->ProcessRuntimePath, FormatS("%s/%d", RuntimeProcesses, proc->pid)) != 0) return 0; | ||||||||||||||||||||
| return 1; | ||||||||||||||||||||
| } | ||||||||||||||||||||
|
|
||||||||||||||||||||
|
|
@@ -716,7 +717,7 @@ static inline __attribute__((visibility("hidden"))) __attribute__((always_inline | |||||||||||||||||||
| } | ||||||||||||||||||||
|
|
||||||||||||||||||||
| if (ProcINFOPathValidation(proc) != 1) { | ||||||||||||||||||||
| PrintKernelErrorF("[AS-PREFLIGHT] ProcINFOPath tampering detected for PID: %d (%s)\n", proc->pid, proc->ProcINFOPath); | ||||||||||||||||||||
| PrintKernelErrorF("[AS-PREFLIGHT] ProcINFOPath tampering detected for PID: %d (%s)\n", proc->pid, proc->ProcessRuntimePath); | ||||||||||||||||||||
| ASTerminate(proc->pid, "ProcINFOPath tampering detected"); | ||||||||||||||||||||
| return 0; // Do not schedule this process. | ||||||||||||||||||||
| } | ||||||||||||||||||||
|
|
@@ -1071,16 +1072,15 @@ static __attribute__((visibility("hidden"))) uint32_t CreateSecureProcess(void ( | |||||||||||||||||||
| processes[slot].io_operations = 0; | ||||||||||||||||||||
| processes[slot].preemption_count = 0; | ||||||||||||||||||||
| processes[slot].wait_time = 0; | ||||||||||||||||||||
| processes[slot].ProcINFOPath = FormatS("%s/%d", RuntimeProcesses, new_pid); | ||||||||||||||||||||
|
|
||||||||||||||||||||
| processes[slot].ProcessRuntimePath = FormatS("%s/%d", RuntimeProcesses, new_pid); | ||||||||||||||||||||
| #ifdef VF_CONFIG_USE_CERBERUS | ||||||||||||||||||||
| CerberusRegisterProcess(new_pid, (uint64_t)stack, STACK_SIZE); | ||||||||||||||||||||
| #endif | ||||||||||||||||||||
|
|
||||||||||||||||||||
| #ifdef VF_CONFIG_PROCINFO_CREATE_DEFAULT | ||||||||||||||||||||
| if (!VfsIsDir(processes[slot].ProcINFOPath)) { | ||||||||||||||||||||
| int rc = VfsCreateDir(processes[slot].ProcINFOPath); | ||||||||||||||||||||
| if (rc != 0 && !VfsIsDir(processes[slot].ProcINFOPath)) { | ||||||||||||||||||||
| if (!VfsIsDir(processes[slot].ProcessRuntimePath)) { | ||||||||||||||||||||
| int rc = VfsCreateDir(processes[slot].ProcessRuntimePath); | ||||||||||||||||||||
| if (rc != 0 && !VfsIsDir(processes[slot].ProcessRuntimePath)) { | ||||||||||||||||||||
| PrintKernelError("ProcINFO: failed to create dir for PID "); | ||||||||||||||||||||
| PrintKernelInt(processes[slot].pid); | ||||||||||||||||||||
| PrintKernel("\n"); | ||||||||||||||||||||
|
|
@@ -1472,7 +1472,7 @@ static void Astra(void) { | |||||||||||||||||||
| // register | ||||||||||||||||||||
| security_manager_pid = current->pid; | ||||||||||||||||||||
|
|
||||||||||||||||||||
| FormatA(astra_path, sizeof(astra_path), "%s/astra", current->ProcINFOPath); | ||||||||||||||||||||
| FormatA(astra_path, sizeof(astra_path), "%s/astra", current->ProcessRuntimePath); | ||||||||||||||||||||
| if (VfsCreateFile(astra_path) != 0) PANIC("Failed to create Astra process info file"); | ||||||||||||||||||||
|
|
||||||||||||||||||||
| PrintKernelSuccess("Astra: Astra active.\n"); | ||||||||||||||||||||
|
|
@@ -1664,8 +1664,8 @@ int ProcessInit(void) { | |||||||||||||||||||
| idle_proc->privilege_level = PROC_PRIV_SYSTEM; | ||||||||||||||||||||
| idle_proc->scheduler_node = NULL; | ||||||||||||||||||||
| idle_proc->creation_time = GetSystemTicks(); | ||||||||||||||||||||
| idle_proc->ProcINFOPath = FormatS("%s/%d", RuntimeServices, idle_proc->pid); | ||||||||||||||||||||
| if (VfsCreateDir(idle_proc->ProcINFOPath) != 0) PANIC("Failed to create ProcINFO directory"); | ||||||||||||||||||||
| idle_proc->ProcessRuntimePath = FormatS("%s/%d", RuntimeServices, idle_proc->pid); | ||||||||||||||||||||
| if (VfsCreateDir(idle_proc->ProcessRuntimePath) != 0) PANIC("Failed to create ProcINFO directory"); | ||||||||||||||||||||
| // Securely initialize the token for the Idle Process | ||||||||||||||||||||
|
Comment on lines
+1667
to
1669
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Same persistent path bug for the idle process. Mirror the fix here. - idle_proc->ProcessRuntimePath = FormatS("%s/%d", RuntimeServices, idle_proc->pid);
- if (VfsCreateDir(idle_proc->ProcessRuntimePath) != 0) PANIC("Failed to create ProcINFO directory");
+ FormatA(idle_proc->ProcessRuntimePath,
+ sizeof(idle_proc->ProcessRuntimePath),
+ "%s/%d", RuntimeServices, idle_proc->pid);
+ if (VfsCreateDir(idle_proc->ProcessRuntimePath) != 0)
+ PANIC("Failed to create ProcINFO directory");📝 Committable suggestion
Suggested change
🤖 Prompt for AI Agents |
||||||||||||||||||||
| SecurityToken* token = &idle_proc->token; | ||||||||||||||||||||
| token->magic = SECURITY_MAGIC; | ||||||||||||||||||||
|
|
||||||||||||||||||||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -166,7 +166,7 @@ typedef struct { | |
| ProcessContext context; | ||
| SchedulerNode* scheduler_node; | ||
| uint64_t creation_time; | ||
| char* ProcINFOPath; | ||
| char* ProcessRuntimePath; | ||
| } ProcessControlBlock; | ||
|
Comment on lines
+169
to
170
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 💡 Verification agent 🧩 Analysis chainMake ProcessRuntimePath storage persistent (avoid static-buffer aliasing). Right now, callers store FormatS() results in this field, which returns a pointer to a single static buffer. Every subsequent FormatS() call overwrites all previously stored paths, breaking termination cleanup and tamper checks. Store the path inline to the PCB (or ensure heap-backed storage and free it on cleanup). Option A (recommended: inline storage, zero-copy, no lifetime issues): - char* ProcessRuntimePath;
+ char ProcessRuntimePath[128]; // or define PROC_PATH_MAX and use itRun a quick scan to catch any remaining code assuming a pointer allocation: 🏁 Script executed: #!/bin/bash
rg -nP "ProcessRuntimePath\s*=\s*FormatS" kernel | catLength of output: 289 Make ProcessRuntimePath inline storage to avoid static-buffer aliasing --- a/kernel/process/Process.h
+++ b/kernel/process/Process.h
@@ struct ProcessControlBlock {
- char *ProcessRuntimePath;
+ char ProcessRuntimePath[PROC_PATH_MAX]; // define PROC_PATH_MAX (e.g. 128)
} ProcessControlBlock;Then update the two assignment sites in processes[slot].ProcessRuntimePath = FormatS("%s/%d", RuntimeProcesses, new_pid);
...
idle_proc->ProcessRuntimePath = FormatS("%s/%d", RuntimeServices, idle_proc->pid);to: snprintf(processes[slot].ProcessRuntimePath, PROC_PATH_MAX, "%s/%d", RuntimeProcesses, new_pid);
...
snprintf(idle_proc->ProcessRuntimePath, PROC_PATH_MAX, "%s/%d", RuntimeServices, idle_proc->pid);🤖 Prompt for AI Agents |
||
|
|
||
| typedef struct { | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ProcINFO path validation uses FormatS static buffer (race-prone, false tamper alerts).
Use a stack buffer with FormatA to avoid static-buffer reuse.
📝 Committable suggestion
🤖 Prompt for AI Agents