2525#import < LindChain/Services/trustd/LDETrust.h>
2626#import < LindChain/ProcEnvironment/Server/Trust.h>
2727#import < LindChain/ProcEnvironment/panic.h>
28+ #import < LindChain/ProcEnvironment/Utils/klog.h>
2829
2930ksurface_error_t proc_init_kproc (void )
3031{
3132#ifdef HOST_ENV
3233 reflock_lock (&(surface->reflock ));
3334
35+ klog_log (@" proc:kproc" , @" initilizing kernel process" );
36+
3437 if (surface->proc_info .proc_count != 0 )
3538 {
3639 // Its not nyxian adding it self to the list... This shall never happen under no condition
@@ -49,6 +52,7 @@ ksurface_error_t proc_init_kproc(void)
4952 NSString *executablePath = [[NSBundle mainBundle ] executablePath ];
5053 strncpy (proc.nyx .executable_path , [executablePath UTF8String ], PATH_MAX);
5154 proc_setentitlements (proc, PEEntitlementKernel);
55+ klog_log (@" proc:kproc" , @" setting kernel process entitlements to %lu " , PEEntitlementKernel);
5256
5357 // Set bsd process stuff
5458 if (gettimeofday (&proc.bsd .kp_proc .p_un .__p_starttime , NULL ) != 0 )
@@ -81,6 +85,10 @@ ksurface_error_t proc_init_kproc(void)
8185 proc.bsd .kp_eproc .e_flag = 2 ;
8286
8387 ksurface_error_t error = proc_append (proc);
88+ if (error == kSurfaceErrorSuccess )
89+ {
90+ klog_log (@" proc:kproc" , @" successfully created kernel process in process table" );
91+ }
8492
8593 // Adding/Inserting proc
8694 reflock_unlock (&(surface->reflock ));
@@ -98,6 +106,8 @@ ksurface_error_t proc_new_child_proc(pid_t ppid,
98106#ifdef HOST_ENV
99107 reflock_lock (&(surface->reflock ));
100108
109+ klog_log (@" proc:new" , @" pid %d requested creation of its child pid %d in the process table with executable path \" %@ \" " , ppid, pid, executablePath);
110+
101111 // Get the old process
102112 ksurface_proc_t proc = {};
103113 ksurface_error_t error = proc_for_pid (ppid, &proc);
@@ -107,9 +117,13 @@ ksurface_error_t proc_new_child_proc(pid_t ppid,
107117 return error;
108118 }
109119
120+ klog_log (@" proc:new" , @" found process structure of pid %d in table" , ppid);
121+
110122 // Check if Nyxian spawned it, if so, drop its permitives accordingly
111123 if (proc_getppid (proc) == PID_LAUNCHD)
112124 {
125+ klog_log (@" proc:new" , @" dropping permitives of child process %d " , pid);
126+
113127 // Its Nyxian it self and due to that we have to drop permitives to mobile user
114128 proc_setuid (proc, 501 );
115129 proc_setruid (proc, 501 );
@@ -122,20 +136,25 @@ ksurface_error_t proc_new_child_proc(pid_t ppid,
122136 // Inheriting entitlements or not?
123137 if (!entitlement_got_entitlement (proc_getentitlements (proc), PEEntitlementProcessSpawnInheriteEntitlements))
124138 {
139+ klog_log (@" proc:new" , @" pid %d doesnt inherit entitlements of pid %d " , pid, ppid);
125140 NSString *entHash = [LDETrust entHashOfExecutableAtPath: executablePath];
126141 if (entHash == nil )
127142 {
143+ klog_log (@" proc:new" , @" no hash found for pid %d dropping entitlements to %lu " , pid, PEEntitlementSandboxedApplication);
128144 proc_setentitlements (proc, PEEntitlementSandboxedApplication);
129145 }
130146 else
131147 {
132- proc_setentitlements (proc, [[TrustCache shared ] getEntitlementsForHash: entHash]);
148+ PEEntitlement entitlement = [[TrustCache shared ] getEntitlementsForHash: entHash];
149+ klog_log (@" proc:new" , @" hash found for pid %d setting entitlements to %lu " , pid, entitlement);
150+ proc_setentitlements (proc, entitlement);
133151 }
134152 }
135153
136154 // Reset time to now
137155 if (gettimeofday (&proc.bsd .kp_proc .p_un .__p_starttime , NULL ) != 0 )
138156 {
157+ klog_log (@" proc:new" , @" failed to get time of the day" );
139158 reflock_unlock (&(surface->reflock ));
140159 return kSurfaceErrorUndefined ;
141160 }
@@ -149,6 +168,7 @@ ksurface_error_t proc_new_child_proc(pid_t ppid,
149168 proc_setpid (proc, pid);
150169
151170 // Insert it back
171+ klog_log (@" proc:new" , @" Inserting process structure of pid %d " , pid);
152172 error = proc_append (proc);
153173
154174 reflock_unlock (&(surface->reflock ));
0 commit comments