diff options
Diffstat (limited to 'libs/binder/ndk/ibinder.cpp')
-rw-r--r-- | libs/binder/ndk/ibinder.cpp | 17 |
1 files changed, 15 insertions, 2 deletions
diff --git a/libs/binder/ndk/ibinder.cpp b/libs/binder/ndk/ibinder.cpp index bf7a0ba5f0..cf5942059a 100644 --- a/libs/binder/ndk/ibinder.cpp +++ b/libs/binder/ndk/ibinder.cpp @@ -24,6 +24,7 @@ #include <private/android_filesystem_config.h> #endif +#include "../BuildFlags.h" #include "ibinder_internal.h" #include "parcel_internal.h" #include "status_internal.h" @@ -44,7 +45,9 @@ namespace ABBinderTag { static const void* kId = "ABBinder"; static void* kValue = static_cast<void*>(new bool{true}); -void clean(const void* /*id*/, void* /*obj*/, void* /*cookie*/){/* do nothing */}; +void clean(const void* /*id*/, void* /*obj*/, void* /*cookie*/) { + /* do nothing */ +} static void attach(const sp<IBinder>& binder) { auto alreadyAttached = binder->attachObject(kId, kValue, nullptr /*cookie*/, clean); @@ -69,7 +72,7 @@ void clean(const void* id, void* obj, void* cookie) { LOG_ALWAYS_FATAL_IF(id != kId, "%p %p %p", id, obj, cookie); delete static_cast<Value*>(obj); -}; +} } // namespace ABpBinderTag @@ -211,6 +214,12 @@ status_t ABBinder::onTransact(transaction_code_t code, const Parcel& data, Parce binder_status_t status = getClass()->onTransact(this, code, &in, &out); return PruneStatusT(status); } else if (code == SHELL_COMMAND_TRANSACTION && getClass()->handleShellCommand != nullptr) { + if constexpr (!android::kEnableKernelIpc) { + // Non-IPC builds do not have getCallingUid(), + // so we have no way of authenticating the caller + return STATUS_PERMISSION_DENIED; + } + int in = data.readFileDescriptor(); int out = data.readFileDescriptor(); int err = data.readFileDescriptor(); @@ -569,6 +578,7 @@ binder_status_t AIBinder_unlinkToDeath(AIBinder* binder, AIBinder_DeathRecipient return recipient->unlinkToDeath(binder->getBinder(), cookie); } +#ifdef BINDER_WITH_KERNEL_IPC uid_t AIBinder_getCallingUid() { return ::android::IPCThreadState::self()->getCallingUid(); } @@ -580,6 +590,7 @@ pid_t AIBinder_getCallingPid() { bool AIBinder_isHandlingTransaction() { return ::android::IPCThreadState::self()->getServingStackPointer() != nullptr; } +#endif void AIBinder_incStrong(AIBinder* binder) { if (binder == nullptr) { @@ -797,9 +808,11 @@ void AIBinder_setRequestingSid(AIBinder* binder, bool requestingSid) { localBinder->setRequestingSid(requestingSid); } +#ifdef BINDER_WITH_KERNEL_IPC const char* AIBinder_getCallingSid() { return ::android::IPCThreadState::self()->getCallingSid(); } +#endif void AIBinder_setMinSchedulerPolicy(AIBinder* binder, int policy, int priority) { binder->asABBinder()->setMinSchedulerPolicy(policy, priority); |