Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 8259ea2b authored by Steven Moreland's avatar Steven Moreland Committed by android-build-merger
Browse files

Merge "libbinder_ndk: AIBinder_getCalling(Pid|Uid)" am: 2d1e881a am: 61d15cb9

am: febd7130

Change-Id: If9a63ecc723910cacf7c008e2ea83a0ef77015e8
parents ae805af7 febd7130
Loading
Loading
Loading
Loading
+9 −0
Original line number Diff line number Diff line
@@ -22,6 +22,7 @@
#include "status_internal.h"

#include <android-base/logging.h>
#include <binder/IPCThreadState.h>

using DeathRecipient = ::android::IBinder::DeathRecipient;

@@ -346,6 +347,14 @@ binder_status_t AIBinder_unlinkToDeath(AIBinder* binder, AIBinder_DeathRecipient
    return recipient->unlinkToDeath(binder, cookie);
}

uid_t AIBinder_getCallingUid() {
    return ::android::IPCThreadState::self()->getCallingUid();
}

pid_t AIBinder_getCallingPid() {
    return ::android::IPCThreadState::self()->getCallingPid();
}

void AIBinder_incStrong(AIBinder* binder) {
    if (binder == nullptr) {
        LOG(ERROR) << __func__ << ": on null binder";
+26 −0
Original line number Diff line number Diff line
@@ -28,6 +28,7 @@

#include <stdint.h>
#include <sys/cdefs.h>
#include <sys/types.h>

#include <android/binder_parcel.h>
#include <android/binder_status.h>
@@ -269,6 +270,31 @@ binder_status_t AIBinder_linkToDeath(AIBinder* binder, AIBinder_DeathRecipient*
binder_status_t AIBinder_unlinkToDeath(AIBinder* binder, AIBinder_DeathRecipient* recipient,
                                       void* cookie) __INTRODUCED_IN(29);

/**
 * This returns the calling UID assuming that this thread is called from a thread that is processing
 * a binder transaction (for instance, in the implementation of AIBinder_Class_onTransact).
 *
 * This can be used with higher-level system services to determine the caller's identity and check
 * permissions.
 *
 * \return calling uid or the current process's UID if this thread isn't processing a transaction.
 */
uid_t AIBinder_getCallingUid();

/**
 * This returns the calling PID assuming that this thread is called from a thread that is processing
 * a binder transaction (for instance, in the implementation of AIBinder_Class_onTransact).
 *
 * This can be used with higher-level system services to determine the caller's identity and check
 * permissions. However, when doing this, one should be aware of possible TOCTOU problems when the
 * calling process dies and is replaced with another process with elevated permissions and the same
 * PID.
 *
 * \return calling pid or the current process's PID if this thread isn't processing a transaction.
 * If the transaction being processed is a oneway transaction, then this method will return 0.
 */
pid_t AIBinder_getCallingPid();

/**
 * This can only be called if a strong reference to this object already exists in process.
 *
+2 −0
Original line number Diff line number Diff line
@@ -7,6 +7,8 @@ LIBBINDER_NDK { # introduced=29
    AIBinder_debugGetRefCount;
    AIBinder_decStrong;
    AIBinder_fromJavaBinder;
    AIBinder_getCallingPid;
    AIBinder_getCallingUid;
    AIBinder_getClass;
    AIBinder_getUserData;
    AIBinder_incStrong;