libbinder: Add binder already sent checks
These operations should only be done before the binder object
is sent out to another process:
- setRequestingSid
- setMinSchedulerPolicy
- setInheritRt
- setExtension
Add log and abort if these are attempted after the binder object
has been sent already.
Bug: 166282674
Test: binderParcelTest
Change-Id: Id2c1d0dc783cad75754a06a3047cf6c7bf704c63
diff --git a/libs/binder/Parcel.cpp b/libs/binder/Parcel.cpp
index 10188fe..232a70c 100644
--- a/libs/binder/Parcel.cpp
+++ b/libs/binder/Parcel.cpp
@@ -196,8 +196,11 @@
return (priority & FLAT_BINDER_FLAG_PRIORITY_MASK) | ((policy & 3) << FLAT_BINDER_FLAG_SCHED_POLICY_SHIFT);
}
-status_t Parcel::flattenBinder(const sp<IBinder>& binder)
-{
+status_t Parcel::flattenBinder(const sp<IBinder>& binder) {
+ BBinder* local = nullptr;
+ if (binder) local = binder->localBinder();
+ if (local) local->setParceled();
+
if (isForRpc()) {
if (binder) {
status_t status = writeInt32(1); // non-null
@@ -223,7 +226,6 @@
}
if (binder != nullptr) {
- BBinder *local = binder->localBinder();
if (!local) {
BpBinder *proxy = binder->remoteBinder();
if (proxy == nullptr) {