diff options
author | 2019-09-05 16:53:28 +0000 | |
---|---|---|
committer | 2019-09-05 16:53:28 +0000 | |
commit | b653dd0a088f3be9d0fccd3d2099b3f8ab63ca2c (patch) | |
tree | a3796f67d19deece6118e60d2faebde9499ce083 /libs/binder/IPCThreadState.cpp | |
parent | 0bc2361309d705f8c7f7766f1912fd0f7035d199 (diff) | |
parent | 9c724d78b9f2e00a7d4de3bfd2c65f6226fa8529 (diff) |
Merge "DO NOT MERGE - Merge Android 10 into master"
Diffstat (limited to 'libs/binder/IPCThreadState.cpp')
-rw-r--r-- | libs/binder/IPCThreadState.cpp | 57 |
1 files changed, 56 insertions, 1 deletions
diff --git a/libs/binder/IPCThreadState.cpp b/libs/binder/IPCThreadState.cpp index 4356706b7e..7c45c775c7 100644 --- a/libs/binder/IPCThreadState.cpp +++ b/libs/binder/IPCThreadState.cpp @@ -114,6 +114,8 @@ static const char *kCommandStrings[] = { "BC_DEAD_BINDER_DONE" }; +static const int64_t kWorkSourcePropagatedBitIndex = 32; + static const char* getReturnString(uint32_t cmd) { size_t idx = cmd & _IOC_NRMASK; @@ -395,6 +397,48 @@ int32_t IPCThreadState::getStrictModePolicy() const return mStrictModePolicy; } +int64_t IPCThreadState::setCallingWorkSourceUid(uid_t uid) +{ + int64_t token = setCallingWorkSourceUidWithoutPropagation(uid); + mPropagateWorkSource = true; + return token; +} + +int64_t IPCThreadState::setCallingWorkSourceUidWithoutPropagation(uid_t uid) +{ + const int64_t propagatedBit = ((int64_t)mPropagateWorkSource) << kWorkSourcePropagatedBitIndex; + int64_t token = propagatedBit | mWorkSource; + mWorkSource = uid; + return token; +} + +void IPCThreadState::clearPropagateWorkSource() +{ + mPropagateWorkSource = false; +} + +bool IPCThreadState::shouldPropagateWorkSource() const +{ + return mPropagateWorkSource; +} + +uid_t IPCThreadState::getCallingWorkSourceUid() const +{ + return mWorkSource; +} + +int64_t IPCThreadState::clearCallingWorkSource() +{ + return setCallingWorkSourceUid(kUnsetWorkSource); +} + +void IPCThreadState::restoreCallingWorkSource(int64_t token) +{ + uid_t uid = (int)token; + setCallingWorkSourceUidWithoutPropagation(uid); + mPropagateWorkSource = ((token >> kWorkSourcePropagatedBitIndex) & 1) == 1; +} + void IPCThreadState::setLastTransactionBinderFlags(int32_t flags) { mLastTransactionBinderFlags = flags; @@ -760,6 +804,8 @@ status_t IPCThreadState::clearDeathNotification(int32_t handle, BpBinder* proxy) IPCThreadState::IPCThreadState() : mProcess(ProcessState::self()), + mWorkSource(kUnsetWorkSource), + mPropagateWorkSource(false), mStrictModePolicy(0), mLastTransactionBinderFlags(0), mCallRestriction(mProcess->mCallRestriction) @@ -1017,7 +1063,7 @@ status_t IPCThreadState::writeTransactionData(int32_t cmd, uint32_t binderFlags, sp<BBinder> the_context_object; -void setTheContextObject(sp<BBinder> obj) +void IPCThreadState::setTheContextObject(sp<BBinder> obj) { the_context_object = obj; } @@ -1133,6 +1179,13 @@ status_t IPCThreadState::executeCommand(int32_t cmd) const uid_t origUid = mCallingUid; const int32_t origStrictModePolicy = mStrictModePolicy; const int32_t origTransactionBinderFlags = mLastTransactionBinderFlags; + const int32_t origWorkSource = mWorkSource; + const bool origPropagateWorkSet = mPropagateWorkSource; + // Calling work source will be set by Parcel#enforceInterface. Parcel#enforceInterface + // is only guaranteed to be called for AIDL-generated stubs so we reset the work source + // here to never propagate it. + clearCallingWorkSource(); + clearPropagateWorkSource(); mCallingPid = tr.sender_pid; mCallingSid = reinterpret_cast<const char*>(tr_secctx.secctx); @@ -1188,6 +1241,8 @@ status_t IPCThreadState::executeCommand(int32_t cmd) mCallingUid = origUid; mStrictModePolicy = origStrictModePolicy; mLastTransactionBinderFlags = origTransactionBinderFlags; + mWorkSource = origWorkSource; + mPropagateWorkSource = origPropagateWorkSet; IF_LOG_TRANSACTIONS() { TextOutput::Bundle _b(alog); |