summaryrefslogtreecommitdiff
path: root/libs/binder/IPCThreadState.cpp
diff options
context:
space:
mode:
author Xin Li <delphij@google.com> 2019-07-01 20:59:49 +0000
committer Xin Li <delphij@google.com> 2019-07-01 20:59:49 +0000
commit6b0fcb78c769bcd831441c76f27070728510b66d (patch)
tree08e16425757030d410c1e701a9bde7f6cbb6f811 /libs/binder/IPCThreadState.cpp
parenta866288854ae77de0189be88bc3b85b005b30863 (diff)
parent3c40927a25ebdaf6986f80aef0ebea677ebdd2db (diff)
DO NOT MERGE - Merge qt-dev-plus-aosp-without-vendor (5699924) into stage-aosp-master
Bug: 134405016 Change-Id: Icda98bcbfd5d7d81f64d5443268e446d1770e106
Diffstat (limited to 'libs/binder/IPCThreadState.cpp')
-rw-r--r--libs/binder/IPCThreadState.cpp55
1 files changed, 55 insertions, 0 deletions
diff --git a/libs/binder/IPCThreadState.cpp b/libs/binder/IPCThreadState.cpp
index bf107d02b7..a2d10ab0ab 100644
--- a/libs/binder/IPCThreadState.cpp
+++ b/libs/binder/IPCThreadState.cpp
@@ -113,6 +113,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;
@@ -394,6 +396,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;
@@ -759,6 +803,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)
@@ -1132,6 +1178,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);
@@ -1187,6 +1240,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);