diff options
author | Steven Moreland <smoreland@google.com> | 2019-01-09 18:01:02 -0800 |
---|---|---|
committer | Steven Moreland <smoreland@google.com> | 2019-01-09 19:32:42 -0800 |
commit | b1a27638623288e48cf303223dd58bc35284b38b (patch) | |
tree | 0fed6a7391d9f53c5fd9a5da01a219706434e17f /Binder.cpp | |
parent | 61d78e2bea02c381bf2b030a986ceb1136bb200a (diff) | |
download | libhwbinder-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.cpp | 60 |
1 files changed, 47 insertions, 13 deletions
@@ -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 { |