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

Commit d1238e7b authored by Yi Jin's avatar Yi Jin Committed by Android (Google) Code Review
Browse files

Merge "Fix permissions problems of incidentd."

parents 9c683237 4bab3a19
Loading
Loading
Loading
Loading
+2 −2
Original line number Original line Diff line number Diff line
@@ -12,8 +12,8 @@ Run the test on a device manually


```
```
root$ mmm -j frameworks/base/cmds/incidentd && \
root$ mmm -j frameworks/base/cmds/incidentd && \
adb push $OUT/data/nativetest/incidentd_test/* /data/nativetest/incidentd_test/ && \
adb push $OUT/data/nativetest/incidentd_test/* /data/nativetest/ && \
adb shell /data/nativetest/incidentd_test/incidentd_test 2>/dev/null
adb shell /data/nativetest/incidentd_test 2>/dev/null
```
```


Run the test via AndroidTest.xml
Run the test via AndroidTest.xml
+1 −1
Original line number Original line Diff line number Diff line
@@ -19,4 +19,4 @@ service incidentd /system/bin/incidentd


on post-fs-data
on post-fs-data
    # Create directory for incidentd
    # Create directory for incidentd
    mkdir /data/misc/incidents 0770 root root
    mkdir /data/misc/incidents 0770 incidentd incidentd
+4 −0
Original line number Original line Diff line number Diff line
@@ -63,12 +63,14 @@ FdBuffer::read(int fd, int64_t timeout)


        int64_t remainingTime = (mStartTime + timeout) - uptimeMillis();
        int64_t remainingTime = (mStartTime + timeout) - uptimeMillis();
        if (remainingTime <= 0) {
        if (remainingTime <= 0) {
            if (DEBUG) ALOGD("timed out due to long read");
            mTimedOut = true;
            mTimedOut = true;
            break;
            break;
        }
        }


        int count = poll(&pfds, 1, remainingTime);
        int count = poll(&pfds, 1, remainingTime);
        if (count == 0) {
        if (count == 0) {
            if (DEBUG) ALOGD("timed out due to block calling poll");
            mTimedOut = true;
            mTimedOut = true;
            break;
            break;
        } else if (count < 0) {
        } else if (count < 0) {
@@ -129,6 +131,7 @@ FdBuffer::readProcessedDataInStream(int fd, int toFd, int fromFd, int64_t timeou


        int64_t remainingTime = (mStartTime + timeoutMs) - uptimeMillis();
        int64_t remainingTime = (mStartTime + timeoutMs) - uptimeMillis();
        if (remainingTime <= 0) {
        if (remainingTime <= 0) {
            if (DEBUG) ALOGD("timed out due to long read");
            mTimedOut = true;
            mTimedOut = true;
            break;
            break;
        }
        }
@@ -136,6 +139,7 @@ FdBuffer::readProcessedDataInStream(int fd, int toFd, int fromFd, int64_t timeou
        // wait for any pfds to be ready to perform IO
        // wait for any pfds to be ready to perform IO
        int count = poll(pfds, 3, remainingTime);
        int count = poll(pfds, 3, remainingTime);
        if (count == 0) {
        if (count == 0) {
            if (DEBUG) ALOGD("timed out due to block calling poll");
            mTimedOut = true;
            mTimedOut = true;
            break;
            break;
        } else if (count < 0) {
        } else if (count < 0) {
+21 −6
Original line number Original line Diff line number Diff line
@@ -43,8 +43,9 @@ String16 const DUMP_PERMISSION("android.permission.DUMP");
String16 const USAGE_STATS_PERMISSION("android.permission.PACKAGE_USAGE_STATS");
String16 const USAGE_STATS_PERMISSION("android.permission.PACKAGE_USAGE_STATS");


static Status
static Status
checkIncidentPermissions()
checkIncidentPermissions(const IncidentReportArgs& args)
{
{
    // checking calling permission.
    if (!checkCallingPermission(DUMP_PERMISSION)) {
    if (!checkCallingPermission(DUMP_PERMISSION)) {
        ALOGW("Calling pid %d and uid %d does not have permission: android.permission.DUMP",
        ALOGW("Calling pid %d and uid %d does not have permission: android.permission.DUMP",
                IPCThreadState::self()->getCallingPid(), IPCThreadState::self()->getCallingUid());
                IPCThreadState::self()->getCallingPid(), IPCThreadState::self()->getCallingUid());
@@ -57,10 +58,24 @@ checkIncidentPermissions()
        return Status::fromExceptionCode(Status::EX_SECURITY,
        return Status::fromExceptionCode(Status::EX_SECURITY,
                "Calling process does not have permission: android.permission.USAGE_STATS");
                "Calling process does not have permission: android.permission.USAGE_STATS");
    }
    }

    // checking calling request uid permission.
    uid_t callingUid = IPCThreadState::self()->getCallingUid();
    switch (args.dest()) {
        case DEST_LOCAL:
            if (callingUid != AID_SHELL || callingUid != AID_ROOT) {
                return Status::fromExceptionCode(Status::EX_SECURITY,
                    "Calling process does not have permission to get local data.");
            }
        case DEST_EXPLICIT:
            if (callingUid != AID_SHELL || callingUid != AID_ROOT ||
                callingUid != AID_STATSD || callingUid != AID_SYSTEM) {
                return Status::fromExceptionCode(Status::EX_SECURITY,
                    "Calling process does not have permission to get explicit data.");
            }
    }
    return Status::ok();
    return Status::ok();
}
}


// ================================================================================
// ================================================================================
ReportRequestQueue::ReportRequestQueue()
ReportRequestQueue::ReportRequestQueue()
{
{
@@ -196,7 +211,7 @@ IncidentService::reportIncident(const IncidentReportArgs& args)
{
{
    ALOGI("reportIncident");
    ALOGI("reportIncident");


    Status status = checkIncidentPermissions();
    Status status = checkIncidentPermissions(args);
    if (!status.isOk()) {
    if (!status.isOk()) {
        return status;
        return status;
    }
    }
@@ -212,7 +227,7 @@ IncidentService::reportIncidentToStream(const IncidentReportArgs& args,
{
{
    ALOGI("reportIncidentToStream");
    ALOGI("reportIncidentToStream");


    Status status = checkIncidentPermissions();
    Status status = checkIncidentPermissions(args);
    if (!status.isOk()) {
    if (!status.isOk()) {
        return status;
        return status;
    }
    }
+1 −1
Original line number Original line Diff line number Diff line
@@ -251,7 +251,7 @@ Reporter::create_file(int* fd)
    // Override umask. Not super critical. If it fails go on with life.
    // Override umask. Not super critical. If it fails go on with life.
    chmod(filename, 0660);
    chmod(filename, 0660);


    if (chown(filename, AID_SYSTEM, AID_SYSTEM)) {
    if (chown(filename, AID_INCIDENTD, AID_INCIDENTD)) {
        ALOGE("Unable to change ownership of incident file %s: %s\n", filename, strerror(errno));
        ALOGE("Unable to change ownership of incident file %s: %s\n", filename, strerror(errno));
        status_t err = -errno;
        status_t err = -errno;
        unlink(mFilename.c_str());
        unlink(mFilename.c_str());
Loading