X-Git-Url: https://git.saurik.com/apple/security.git/blobdiff_plain/b04fe171f0375ecd5d8a24747ca1dff85720a0ca..7e6b461318c8a779d91381531435a68ee4e8b6ed:/securityd/src/process.cpp diff --git a/securityd/src/process.cpp b/securityd/src/process.cpp index 6439308e..9ab05df8 100644 --- a/securityd/src/process.cpp +++ b/securityd/src/process.cpp @@ -40,31 +40,43 @@ // 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 _(*this); - + xpc_transaction_begin(); // 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. if (this->pid() == getpid() // called ourselves (through some API). Do NOT record this as a "dirty" transaction || ServerChild::find(this->pid())) // securityd's child; do not mark this txn dirty - VProc::Transaction::deactivate(); + xpc_transaction_end(); - 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,19 +91,18 @@ void Process::reset(TaskPort taskPort, const ClientSetupInfo *info, const Common { StLock _(*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 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); - CodeSigningHost::reset(); + secnotice("SecServer", "%p Client reset full", this); } } @@ -124,11 +135,13 @@ 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(); + } + xpc_transaction_end(); } 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()); } @@ -196,7 +209,6 @@ void Process::dumpNode() Debug::dump(" FLIPPED"); Debug::dump(" task=%d pid=%d uid/gid=%d/%d", mTaskPort.port(), mPid, mUid, mGid); - CodeSigningHost::dump(); ClientIdentification::dump(); }