summaryrefslogtreecommitdiff
path: root/Binder.cpp
diff options
context:
space:
mode:
authorSteven Moreland <smoreland@google.com>2019-01-09 18:01:02 -0800
committerSteven Moreland <smoreland@google.com>2019-01-09 19:32:42 -0800
commitb1a27638623288e48cf303223dd58bc35284b38b (patch)
tree0fed6a7391d9f53c5fd9a5da01a219706434e17f /Binder.cpp
parent61d78e2bea02c381bf2b030a986ceb1136bb200a (diff)
downloadlibhwbinder-b1a27638623288e48cf303223dd58bc35284b38b.tar.gz
Revert "Revert "getCallingSid: get calling security context""
This reverts commit 61d78e2bea02c381bf2b030a986ceb1136bb200a. This enables getting security contexts from the kernel. Bug: 121035042 Test: boot patch w/ w/o kernel patch on cuttlefish and check for security logs. Test: check for cnd failures on crosshatch. Change-Id: Ia40b63c8bc245751b064ef68854f4c9e95fbc2e7
Diffstat (limited to 'Binder.cpp')
-rw-r--r--Binder.cpp60
1 files changed, 47 insertions, 13 deletions
diff --git a/Binder.cpp b/Binder.cpp
index 8f576ae..72884f0 100644
--- a/Binder.cpp
+++ b/Binder.cpp
@@ -61,6 +61,10 @@ bool IBinder::checkSubclass(const void* /*subclassID*/) const
class BHwBinder::Extras
{
public:
+ // unlocked objects
+ bool mRequestingSid = false;
+
+ // for below objects
Mutex mLock;
BpHwBinder::ObjectManager mObjects;
};
@@ -79,6 +83,28 @@ int BHwBinder::getMinSchedulingPriority() {
return mSchedPriority;
}
+bool BHwBinder::isRequestingSid() {
+ Extras* e = mExtras.load(std::memory_order_acquire);
+
+ return e && e->mRequestingSid;
+}
+
+void BHwBinder::setRequestingSid(bool requestingSid) {
+ Extras* e = mExtras.load(std::memory_order_acquire);
+
+ if (!e) {
+ // default is false. Most things don't need sids, so avoiding allocations when possible.
+ if (!requestingSid) {
+ return;
+ }
+
+ e = getOrCreateExtras();
+ if (!e) return; // out of memory
+ }
+
+ e->mRequestingSid = true;
+}
+
status_t BHwBinder::transact(
uint32_t code, const Parcel& data, Parcel* reply, uint32_t flags, TransactCallback callback)
{
@@ -118,19 +144,8 @@ void BHwBinder::attachObject(
const void* objectID, void* object, void* cleanupCookie,
object_cleanup_func func)
{
- Extras* e = mExtras.load(std::memory_order_acquire);
-
- if (!e) {
- e = new Extras;
- Extras* expected = nullptr;
- if (!mExtras.compare_exchange_strong(expected, e,
- std::memory_order_release,
- std::memory_order_acquire)) {
- delete e;
- e = expected; // Filled in by CAS
- }
- if (e == nullptr) return; // out of memory
- }
+ Extras* e = getOrCreateExtras();
+ if (!e) return; // out of memory
AutoMutex _l(e->mLock);
e->mObjects.attach(objectID, object, cleanupCookie, func);
@@ -173,6 +188,25 @@ status_t BHwBinder::onTransact(
return UNKNOWN_TRANSACTION;
}
+BHwBinder::Extras* BHwBinder::getOrCreateExtras()
+{
+ Extras* e = mExtras.load(std::memory_order_acquire);
+
+ if (!e) {
+ e = new Extras;
+ Extras* expected = nullptr;
+ if (!mExtras.compare_exchange_strong(expected, e,
+ std::memory_order_release,
+ std::memory_order_acquire)) {
+ delete e;
+ e = expected; // Filled in by CAS
+ }
+ if (e == nullptr) return nullptr; // out of memory
+ }
+
+ return e;
+}
+
// ---------------------------------------------------------------------------
enum {