Revert "getCallingSid: get calling security context"

This reverts commit 96108497705c3ba22f02f4869fa70af1a97d0574.

Reason for revert: Breaks QCOM prebuilts.

Bug: 122551831
Bug: 121035042
Change-Id: I9296b6cc3aa9530e4b46ff7bdb4516d0fa68eb98
Test: reverting stops cnd crashing on crosshatch
(cherry picked from commit 61d78e2bea02c381bf2b030a986ceb1136bb200a)
diff --git a/Binder.cpp b/Binder.cpp
index 16b5698..8f576ae 100644
--- a/Binder.cpp
+++ b/Binder.cpp
@@ -67,7 +67,7 @@
 
 // ---------------------------------------------------------------------------
 
-BHwBinder::BHwBinder() : mSchedPolicy(SCHED_NORMAL), mSchedPriority(0), mRequestingSid(false), mExtras(nullptr)
+BHwBinder::BHwBinder() : mSchedPolicy(SCHED_NORMAL), mSchedPriority(0), mExtras(nullptr)
 {
 }
 
@@ -79,10 +79,6 @@
     return mSchedPriority;
 }
 
-bool BHwBinder::isRequestingSid() {
-    return mRequestingSid;
-}
-
 status_t BHwBinder::transact(
     uint32_t code, const Parcel& data, Parcel* reply, uint32_t flags, TransactCallback callback)
 {
diff --git a/IPCThreadState.cpp b/IPCThreadState.cpp
index 89fc35b..c7c71be 100644
--- a/IPCThreadState.cpp
+++ b/IPCThreadState.cpp
@@ -87,8 +87,7 @@
     "BR_FINISHED",
     "BR_DEAD_BINDER",
     "BR_CLEAR_DEATH_NOTIFICATION_DONE",
-    "BR_FAILED_REPLY",
-    "BR_TRANSACTION_SEC_CTX",
+    "BR_FAILED_REPLY"
 };
 
 static const char *kCommandStrings[] = {
@@ -354,11 +353,6 @@
     return mCallingPid;
 }
 
-const char* IPCThreadState::getCallingSid() const
-{
-    return mCallingSid;
-}
-
 uid_t IPCThreadState::getCallingUid() const
 {
     return mCallingUid;
@@ -366,7 +360,6 @@
 
 int64_t IPCThreadState::clearCallingIdentity()
 {
-    // ignore mCallingSid for legacy reasons
     int64_t token = ((int64_t)mCallingUid<<32) | mCallingPid;
     clearCaller();
     return token;
@@ -395,14 +388,12 @@
 void IPCThreadState::restoreCallingIdentity(int64_t token)
 {
     mCallingUid = (int)(token>>32);
-    mCallingSid = nullptr;  // not enough data to restore
     mCallingPid = (int)token;
 }
 
 void IPCThreadState::clearCaller()
 {
     mCallingPid = getpid();
-    mCallingSid = nullptr;  // expensive to lookup
     mCallingUid = getuid();
 }
 
@@ -1117,19 +1108,10 @@
         }
         break;
 
-    case BR_TRANSACTION_SEC_CTX:
     case BR_TRANSACTION:
         {
-            binder_transaction_data_secctx tr_secctx;
-            binder_transaction_data& tr = tr_secctx.transaction_data;
-
-            if (cmd == BR_TRANSACTION_SEC_CTX) {
-                result = mIn.read(&tr_secctx, sizeof(tr_secctx));
-            } else {
-                result = mIn.read(&tr, sizeof(tr));
-                tr_secctx.secctx = 0;
-            }
-
+            binder_transaction_data tr;
+            result = mIn.read(&tr, sizeof(tr));
             ALOG_ASSERT(result == NO_ERROR,
                 "Not enough command data for brTRANSACTION");
             if (result != NO_ERROR) break;
@@ -1145,18 +1127,15 @@
                 tr.offsets_size/sizeof(binder_size_t), freeBuffer, this);
 
             const pid_t origPid = mCallingPid;
-            const char* origSid = mCallingSid;
             const uid_t origUid = mCallingUid;
             const int32_t origStrictModePolicy = mStrictModePolicy;
             const int32_t origTransactionBinderFlags = mLastTransactionBinderFlags;
 
             mCallingPid = tr.sender_pid;
-            mCallingSid = reinterpret_cast<const char*>(tr_secctx.secctx);
             mCallingUid = tr.sender_euid;
             mLastTransactionBinderFlags = tr.flags;
 
-            // ALOGI(">>>> TRANSACT from pid %d sid %s uid %d\n", mCallingPid,
-            //    (mCallingSid ? mCallingSid : "<N/A>"), mCallingUid);
+            //ALOGI(">>>> TRANSACT from pid %d uid %d\n", mCallingPid, mCallingUid);
 
             Parcel reply;
             status_t error;
@@ -1221,11 +1200,11 @@
                 // One-way transaction, don't care about return value or reply.
             }
 
-            //ALOGI("<<<< TRANSACT from pid %d restore pid %d sid %s uid %d\n",
-            //     mCallingPid, origPid, (origSid ? origSid : "<N/A>"), origUid);
+            //ALOGI("<<<< TRANSACT from pid %d restore pid %d uid %d\n",
+            //     mCallingPid, origPid, origUid);
+
 
             mCallingPid = origPid;
-            mCallingSid = origSid;
             mCallingUid = origUid;
             mStrictModePolicy = origStrictModePolicy;
             mLastTransactionBinderFlags = origTransactionBinderFlags;
diff --git a/Parcel.cpp b/Parcel.cpp
index 38d97eb..b58cf9c 100644
--- a/Parcel.cpp
+++ b/Parcel.cpp
@@ -219,9 +219,6 @@
             obj.flags = priority & FLAT_BINDER_FLAG_PRIORITY_MASK;
             obj.flags |= FLAT_BINDER_FLAG_ACCEPTS_FDS | FLAT_BINDER_FLAG_INHERIT_RT;
             obj.flags |= (policy & 3) << FLAT_BINDER_FLAG_SCHEDPOLICY_SHIFT;
-            if (local->isRequestingSid()) {
-                obj.flags |= FLAT_BINDER_FLAG_TXN_SECURITY_CTX;
-            }
             obj.hdr.type = BINDER_TYPE_BINDER;
             obj.binder = reinterpret_cast<uintptr_t>(local->getWeakRefs());
             obj.cookie = reinterpret_cast<uintptr_t>(local);
diff --git a/ProcessState.cpp b/ProcessState.cpp
index 5e6642e..84fb8f7 100644
--- a/ProcessState.cpp
+++ b/ProcessState.cpp
@@ -167,20 +167,8 @@
         mBinderContextCheckFunc = checkFunc;
         mBinderContextUserData = userData;
 
-        flat_binder_object obj {
-            .flags = FLAT_BINDER_FLAG_TXN_SECURITY_CTX,
-        };
-
-        status_t result = ioctl(mDriverFD, BINDER_SET_CONTEXT_MGR_EXT, &obj);
-
-        // fallback to original method
-        if (result != 0) {
-            android_errorWriteLog(0x534e4554, "121035042");
-
-            int dummy = 0;
-            result = ioctl(mDriverFD, BINDER_SET_CONTEXT_MGR, &dummy);
-        }
-
+        int dummy = 0;
+        status_t result = ioctl(mDriverFD, BINDER_SET_CONTEXT_MGR, &dummy);
         if (result == 0) {
             mManagesContexts = true;
         } else if (result == -1) {
diff --git a/include/hwbinder/Binder.h b/include/hwbinder/Binder.h
index 7d8fc9f..11ca331 100644
--- a/include/hwbinder/Binder.h
+++ b/include/hwbinder/Binder.h
@@ -56,8 +56,6 @@
 
     int                 getMinSchedulingPolicy();
     int                 getMinSchedulingPriority();
-    bool                isRequestingSid();
-
 protected:
     virtual             ~BHwBinder();
 
@@ -69,7 +67,6 @@
     int                 mSchedPolicy; // policy to run transaction from this node at
     // priority [-20..19] for SCHED_NORMAL, [1..99] for SCHED_FIFO/RT
     int                 mSchedPriority;
-    bool                mRequestingSid;
 private:
                         BHwBinder(const BHwBinder& o);
             BHwBinder&    operator=(const BHwBinder& o);
diff --git a/include/hwbinder/IPCThreadState.h b/include/hwbinder/IPCThreadState.h
index 579c331..f2112c0 100644
--- a/include/hwbinder/IPCThreadState.h
+++ b/include/hwbinder/IPCThreadState.h
@@ -46,11 +46,6 @@
             status_t            clearLastError();
 
             pid_t               getCallingPid() const;
-            // nullptr if unavailable
-            //
-            // this can't be restored once it's cleared, and it does not return the
-            // context of the current process when not in a binder call.
-            const char*         getCallingSid() const;
             uid_t               getCallingUid() const;
 
             void                setStrictModePolicy(int32_t policy);
@@ -60,7 +55,6 @@
             int32_t             getLastTransactionBinderFlags() const;
 
             int64_t             clearCallingIdentity();
-            // Restores PID/UID (not SID)
             void                restoreCallingIdentity(int64_t token);
 
             int                 setupPolling(int* fd);
@@ -171,7 +165,6 @@
             Parcel              mOut;
             status_t            mLastError;
             pid_t               mCallingPid;
-            const char*         mCallingSid;
             uid_t               mCallingUid;
             int32_t             mStrictModePolicy;
             int32_t             mLastTransactionBinderFlags;
diff --git a/include/hwbinder/binder_kernel.h b/include/hwbinder/binder_kernel.h
index 08483ae..f78b294 100644
--- a/include/hwbinder/binder_kernel.h
+++ b/include/hwbinder/binder_kernel.h
@@ -34,7 +34,6 @@
         FLAT_BINDER_FLAG_SCHEDPOLICY_MASK = 0x600,
         FLAT_BINDER_FLAG_SCHEDPOLICY_SHIFT = 9,
         FLAT_BINDER_FLAG_INHERIT_RT = 0x800,
-        FLAT_BINDER_FLAG_TXN_SECURITY_CTX = 0x1000,
 };
 
 struct binder_node_info_for_ref {
@@ -47,17 +46,5 @@
 };
 
 #define BINDER_GET_NODE_INFO_FOR_REF	_IOWR('b', 12, struct binder_node_info_for_ref)
-#define BINDER_SET_CONTEXT_MGR_EXT      _IOW('b', 13, struct flat_binder_object)
-
-struct binder_transaction_data_secctx {
-        struct binder_transaction_data transaction_data;
-        binder_uintptr_t secctx;
-};
-
-enum {
-        BR_TRANSACTION_SEC_CTX = _IOR('r', 2,
-                              struct binder_transaction_data_secctx),
-};
-
 
 #endif // ANDROID_HARDWARE_BINDER_KERNEL_H