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

Commit b85f9901 authored by Steven Moreland's avatar Steven Moreland Committed by Automerger Merge Worker
Browse files

Merge "libbinder: support BR_ONEWAY_SPAM_SUSPECT" am: 77e3f9fa am:...

Merge "libbinder: support BR_ONEWAY_SPAM_SUSPECT" am: 77e3f9fa am: 1964c066 am: 1fee8479 am: 0261321c

Original change: https://android-review.googlesource.com/c/platform/frameworks/native/+/1676195

Change-Id: Ie4fcf1cc8f26079e2402fc3c70b82228684e14da
parents 9de70d2b 0261321c
Loading
Loading
Loading
Loading
+7 −0
Original line number Diff line number Diff line
@@ -90,6 +90,8 @@ static const char *kReturnStrings[] = {
    "BR_DEAD_BINDER",
    "BR_CLEAR_DEATH_NOTIFICATION_DONE",
    "BR_FAILED_REPLY",
    "BR_FROZEN_REPLY",
    "BR_ONEWAY_SPAM_SUSPECT",
    "BR_TRANSACTION_SEC_CTX",
};

@@ -894,6 +896,11 @@ status_t IPCThreadState::waitForResponse(Parcel *reply, status_t *acquireResult)
        }

        switch (cmd) {
        case BR_ONEWAY_SPAM_SUSPECT:
            ALOGE("Process seems to be sending too many oneway calls.");
            CallStack::logStack("oneway spamming", CallStack::getCurrent().get(),
                    ANDROID_LOG_ERROR);
            [[fallthrough]];
        case BR_TRANSACTION_COMPLETE:
            if (!reply && !acquireResult) goto finish;
            break;
+15 −0
Original line number Diff line number Diff line
@@ -43,6 +43,7 @@

#define BINDER_VM_SIZE ((1 * 1024 * 1024) - sysconf(_SC_PAGE_SIZE) * 2)
#define DEFAULT_MAX_BINDER_THREADS 15
#define DEFAULT_ENABLE_ONEWAY_SPAM_DETECTION 1

#ifdef __ANDROID_VNDK__
const char* kDefaultDriver = "/dev/vndbinder";
@@ -358,6 +359,15 @@ status_t ProcessState::setThreadPoolMaxThreadCount(size_t maxThreads) {
    return result;
}

status_t ProcessState::enableOnewaySpamDetection(bool enable) {
    uint32_t enableDetection = enable ? 1 : 0;
    if (ioctl(mDriverFD, BINDER_ENABLE_ONEWAY_SPAM_DETECTION, &enableDetection) == -1) {
        ALOGE("Binder ioctl to enable oneway spam detection failed: %s", strerror(errno));
        return -errno;
    }
    return NO_ERROR;
}

void ProcessState::giveThreadPoolName() {
    androidSetThreadName( makeBinderThreadName().string() );
}
@@ -388,6 +398,11 @@ static int open_driver(const char *driver)
        if (result == -1) {
            ALOGE("Binder ioctl to set max threads failed: %s", strerror(errno));
        }
        uint32_t enable = DEFAULT_ENABLE_ONEWAY_SPAM_DETECTION;
        result = ioctl(fd, BINDER_ENABLE_ONEWAY_SPAM_DETECTION, &enable);
        if (result == -1) {
            ALOGE("Binder ioctl to enable oneway spam detection failed: %s", strerror(errno));
        }
    } else {
        ALOGW("Opening '%s' failed: %s\n", driver, strerror(errno));
    }
+1 −0
Original line number Diff line number Diff line
@@ -58,6 +58,7 @@ public:
            void                spawnPooledThread(bool isMain);
            
            status_t            setThreadPoolMaxThreadCount(size_t maxThreads);
            status_t            enableOnewaySpamDetection(bool enable);
            void                giveThreadPoolName();

            String8             getDriverName();
+13 −7
Original line number Diff line number Diff line
@@ -32,10 +32,6 @@
#include <sys/ioctl.h>
#include <linux/android/binder.h>

#ifdef __cplusplus
namespace android {
#endif

#ifndef BR_FROZEN_REPLY
// Temporary definition of BR_FROZEN_REPLY. For production
// this will come from UAPI binder.h
@@ -88,8 +84,18 @@ struct binder_frozen_status_info {
};
#endif //BINDER_GET_FROZEN_INFO

#ifdef __cplusplus
}   // namespace android
#endif
#ifndef BR_ONEWAY_SPAM_SUSPECT
// Temporary definition of BR_ONEWAY_SPAM_SUSPECT. For production
// this will come from UAPI binder.h
#define BR_ONEWAY_SPAM_SUSPECT _IO('r', 19)
#endif //BR_ONEWAY_SPAM_SUSPECT

#ifndef BINDER_ENABLE_ONEWAY_SPAM_DETECTION
/*
 * Temporary definitions for oneway spam detection support. For the final version
 * these will be defined in the UAPI binder.h file from upstream kernel.
 */
#define BINDER_ENABLE_ONEWAY_SPAM_DETECTION _IOW('b', 16, __u32)
#endif //BINDER_ENABLE_ONEWAY_SPAM_DETECTION

#endif // _BINDER_MODULE_H_