]> git.saurik.com Git - apple/security.git/blobdiff - securityd/src/process.cpp
Security-58286.260.20.tar.gz
[apple/security.git] / securityd / src / process.cpp
index 6439308eda817c0c10cec2d938e4c593f8142e96..b31937988f282dc11257cdfc598ae1e282acd221 100644 (file)
 // Construct a Process object.
 //
 Process::Process(TaskPort taskPort,    const ClientSetupInfo *info, const CommonCriteria::AuditToken &audit)
- :  mTaskPort(taskPort), mByteFlipped(false), mPid(audit.pid()), mUid(audit.euid()), mGid(audit.egid())
+ :  mTaskPort(taskPort), mByteFlipped(false), mPid(audit.pid()), mUid(audit.euid()), mGid(audit.egid()), mAudit(audit)
 {
        StLock<Mutex> _(*this);
        
        // set parent session
        parent(Session::find(audit.sessionId(), true));
-
-    // let's take a look at our wannabe client...
+       
+       // let's take a look at our wannabe client...
+       
+       // Not enough to make sure we will get the right process, as
+       // pids get recycled. But we will later create the actual SecCode using
+       // the audit token, which is unique to the one instance of the process,
+       // so this just catches a pid mismatch early.
        if (mTaskPort.pid() != mPid) {
-               secnotice("SS", "Task/pid setup mismatch pid=%d task=%d(%d)",
-                       mPid, mTaskPort.port(), mTaskPort.pid());
+               secnotice("SecServer", "Task/pid setup mismatch pid=%d task=%d(%d)",
+                                 mPid, mTaskPort.port(), mTaskPort.pid());
                CssmError::throwMe(CSSMERR_CSSM_ADDIN_AUTHENTICATE_FAILED);     // you lied!
        }
-
+       
        setup(info);
-       ClientIdentification::setup(this->pid());
-
+       ClientIdentification::setup(this->audit_token());
+       
+       if(!processCode()) {
+               // This can happen if the process died in the meantime.
+               secnotice("SecServer", "no process created in setup, old pid=%d old task=%d(%d)",
+                                 mPid, mTaskPort.port(), mTaskPort.pid());
+               CssmError::throwMe(CSSMERR_CSSM_ADDIN_AUTHENTICATE_FAILED);
+       }
+       
     // NB: ServerChild::find() should only be used to determine
     // *existence*.  Don't use the returned Child object for anything else, 
     // as it is not protected against its underlying process's destruction.  
@@ -64,7 +76,7 @@ Process::Process(TaskPort taskPort,   const ClientSetupInfo *info, const CommonCri
         || ServerChild::find<ServerChild>(this->pid()))   // securityd's child; do not mark this txn dirty
                VProc::Transaction::deactivate();
 
-    secinfo("SS", "%p client new: pid:%d session:%d %s taskPort:%d uid:%d gid:%d", this, this->pid(), this->session().sessionId(),
+    secinfo("SecServer", "%p client new: pid:%d session:%d %s taskPort:%d uid:%d gid:%d", this, this->pid(), this->session().sessionId(),
              (char *)codePath(this->processCode()).c_str(), taskPort.port(), mUid, mGid);
 }
 
@@ -79,18 +91,18 @@ void Process::reset(TaskPort taskPort, const ClientSetupInfo *info, const Common
 {
        StLock<Mutex> _(*this);
        if (taskPort != mTaskPort) {
-               secnotice("SS", "Process %p(%d) reset mismatch (tp %d-%d)",
+               secnotice("SecServer", "Process %p(%d) reset mismatch (tp %d-%d)",
                        this, pid(), taskPort.port(), mTaskPort.port());
                //@@@ CssmError::throwMe(CSSM_ERRCODE_VERIFICATION_FAILURE);            // liar
        }
        setup(info);
        CFCopyRef<SecCodeRef> oldCode = processCode();
 
-       ClientIdentification::setup(this->pid());       // re-constructs processCode()
+       ClientIdentification::setup(this->audit_token());       // re-constructs processCode()
        if (CFEqual(oldCode, processCode())) {
-        secnotice("SS", "%p Client reset amnesia", this);
+        secnotice("SecServer", "%p Client reset amnesia", this);
        } else {
-        secnotice("SS", "%p Client reset full", this);
+        secnotice("SecServer", "%p Client reset full", this);
                CodeSigningHost::reset();
        }
 }
@@ -124,11 +136,12 @@ void Process::setup(const ClientSetupInfo *info)
 //
 Process::~Process()
 {
-    secinfo("SS", "%p client release: %d", this, this->pid());
+    secinfo("SecServer", "%p client release: %d", this, this->pid());
 
     // release our name for the process's task port
-       if (mTaskPort)
-        mTaskPort.destroy();
+    if (mTaskPort) {
+        mTaskPort.deallocate();
+    }
 }
 
 void Process::kill()
@@ -180,7 +193,7 @@ void Process::changeSession(Session::SessionId sessionId)
 {
        // re-parent
        parent(Session::find(sessionId, true));
-    secnotice("SS", "%p client change session to %d", this, this->session().sessionId());
+    secnotice("SecServer", "%p client change session to %d", this, this->session().sessionId());
 }