07-02 21:51:03.224 7260 9452 E AndroidRuntime: Process: android.content.cts, PID: 7260
07-02 21:51:03.224 7260 9452 E AndroidRuntime: java.lang.IllegalStateException: Test timed out after 300000 milliseconds but execution thread failed to terminate
07-02 21:51:03.224 7260 9452 E AndroidRuntime: Dumping instr and main threads:
07-02 21:51:03.224 7260 9452 E AndroidRuntime: Thread[Instr: android.support.test.runner.AndroidJUnitRunner,5,main]
07-02 21:51:03.224 7260 9452 E AndroidRuntime: at dalvik.system.VMStack.getThreadStackTrace(Native Method)
07-02 21:51:03.224 7260 9452 E AndroidRuntime: at java.lang.Thread.getStackTrace(Thread.java:1566)
07-02 21:51:03.224 7260 9452 E AndroidRuntime: at android.support.test.internal.runner.junit3.AndroidTestSuite.getStackTraces(AndroidTestSuite.java:174)
07-02 21:51:03.224 7260 9452 E AndroidRuntime: at android.support.test.internal.runner.junit3.AndroidTestSuite.runTestWithTimeout(AndroidTestSuite.java:128)
07-02 21:51:03.224 7260 9452 E AndroidRuntime: at android.support.test.internal.runner.junit3.AndroidTestSuite.runTestsWithTimeout(AndroidTestSuite.java:80)
07-02 21:51:03.224 7260 9452 E AndroidRuntime: at android.support.test.internal.runner.junit3.AndroidTestSuite.run(AndroidTestSuite.java:66)
07-02 21:51:03.224 7260 9452 E AndroidRuntime: at android.support.test.internal.runner.junit3.JUnit38ClassRunner.run(JUnit38ClassRunner.java:103)
07-02 21:51:03.224 7260 9452 E AndroidRuntime: at org.junit.runners.Suite.runChild(Suite.java:128)
07-02 21:51:03.224 7260 9452 E AndroidRuntime: at org.junit.runners.Suite.runChild(Suite.java:27)
07-02 21:51:03.224 7260 9452 E AndroidRuntime: at org.junit.runners.ParentRunner$3.run(ParentRunner.java:290)
07-02 21:51:03.224 7260 9452 E AndroidRuntime: at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:71)
07-02 21:51:03.224 7260 9452 E AndroidRuntime: at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:288)
07-02 21:51:03.224 7260 9452 E AndroidRuntime: at org.junit.runners.ParentRunner.access$000(ParentRunner.java:58)
07-02 21:51:03.224 7260 9452 E AndroidRuntime: at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:268)
07-02 21:51:03.224 7260 9452 E AndroidRuntime: at org.junit.runners.ParentRunner.run(ParentRunner.java:363)
07-02 21:51:03.224 7260 9452 E AndroidRuntime: at org.junit.runner.JUnitCore.run(JUnitCore.java:137)
07-02 21:51:03.224 7260 9452 E AndroidRuntime: at org.junit.runner.JUnitCore.run(JUnitCore.java:115)
07-02 21:51:03.224 7260 9452 E AndroidRuntime: at android.support.test.internal.runner.TestExecutor.execute(TestExecutor.java:59)
07-02 21:51:03.224 7260 9452 E AndroidRuntime: at android.support.test.runner.AndroidJUnitRunner.onStart(AndroidJUnitRunner.java:272)
07-02 21:51:03.224 7260 9452 E AndroidRuntime: at android.app.Instrumentation$InstrumentationThread.run(Instrumentation.java:1996)
07-02 21:51:03.224 7260 9452 E AndroidRuntime:
07-02 21:51:03.224 7260 9452 E AndroidRuntime: Thread[main,5,main]
07-02 21:51:03.224 7260 9452 E AndroidRuntime: at android.os.MessageQueue.nativePollOnce(Native Method)
07-02 21:51:03.224 7260 9452 E AndroidRuntime: at android.os.MessageQueue.next(MessageQueue.java:328)
07-02 21:51:03.224 7260 9452 E AndroidRuntime: at android.os.Looper.loop(Looper.java:148)
07-02 21:51:03.224 7260 9452 E AndroidRuntime: at android.app.ActivityThread.main(ActivityThread.java:6528)
07-02 21:51:03.224 7260 9452 E AndroidRuntime: at java.lang.reflect.Method.invoke(Native Method)
07-02 21:51:03.224 7260 9452 E AndroidRuntime: at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1084)
07-02 21:51:03.224 7260 9452 E AndroidRuntime: at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:945)
07-02 21:51:03.224 7260 9452 E AndroidRuntime:
07-02 21:51:03.224 7260 9452 E AndroidRuntime:
07-02 21:51:03.224 7260 9452 E AndroidRuntime: at android.support.test.internal.runner.junit3.AndroidTestSuite.runTestWithTimeout(AndroidTestSuite.java:128)
07-02 21:51:03.224 7260 9452 E AndroidRuntime: at android.support.test.internal.runner.junit3.AndroidTestSuite.runTestsWithTimeout(AndroidTestSuite.java:80)
07-02 21:51:03.224 7260 9452 E AndroidRuntime: at android.support.test.internal.runner.junit3.AndroidTestSuite.run(AndroidTestSuite.java:66)
07-02 21:51:03.224 7260 9452 E AndroidRuntime: at android.support.test.internal.runner.junit3.JUnit38ClassRunner.run(JUnit38ClassRunner.java:103)
07-02 21:51:03.224 7260 9452 E AndroidRuntime: at org.junit.runners.Suite.runChild(Suite.java:128)
07-02 21:51:03.224 7260 9452 E AndroidRuntime: at org.junit.runners.Suite.runChild(Suite.java:27)
07-02 21:51:03.224 7260 9452 E AndroidRuntime: at org.junit.runners.ParentRunner$3.run(ParentRunner.java:290)
07-02 21:51:03.224 7260 9452 E AndroidRuntime: at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:71)
07-02 21:51:03.224 7260 9452 E AndroidRuntime: at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:288)
07-02 21:51:03.224 7260 9452 E AndroidRuntime: at org.junit.runners.ParentRunner.access$000(ParentRunner.java:58)
07-02 21:51:03.224 7260 9452 E AndroidRuntime: at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:268)
07-02 21:51:03.224 7260 9452 E AndroidRuntime: at org.junit.runners.ParentRunner.run(ParentRunner.java:363)
07-02 21:51:03.224 7260 9452 E AndroidRuntime: at org.junit.runner.JUnitCore.run(JUnitCore.java:137)
07-02 21:51:03.224 7260 9452 E AndroidRuntime: at org.junit.runner.JUnitCore.run(JUnitCore.java:115)
07-02 21:51:03.224 7260 9452 E AndroidRuntime: at android.support.test.internal.runner.TestExecutor.execute(TestExecutor.java:59)
07-02 21:51:03.224 7260 9452 E AndroidRuntime: at android.support.test.runner.AndroidJUnitRunner.onStart(AndroidJUnitRunner.java:272)
07-02 21:51:03.224 7260 9452 E AndroidRuntime: at android.app.Instrumentation$InstrumentationThread.run(Instrumentation.java:1996)
06-27 10:13:41.770 3743 3756 E Parcel : Attempt to read from protected data in Parcel 0xaa6c8d70
06-27 10:13:41.770 3743 3756 E Parcel : Attempt to read from protected data in Parcel 0xaa6c8d70
06-27 10:13:41.770 3743 3756 E Parcel : Attempt to read from protected data in Parcel 0xaa6c8d70
06-27 10:13:41.771 3724 3740 W Parcel : Attempt to read object from Parcel 0xa5e1e1c0 at offset 68 that is not in the object list
06-27 10:13:41.771 3724 3740 E CursorWindow: CursorWindow::createFromParcel, BAD_TYPE:-2147483647
06-27 10:13:41.771 3724 3740 E CursorWindow: Could not create CursorWindow from Parcel due to error -2147483647.
06-27 10:13:41.773 3724 3740 I TestRunner: failed: testQuery(android.content.cts.ContentProviderCursorWindowTest)
06-27 10:13:41.773 3724 3740 I TestRunner: ----- begin exception -----
06-27 10:13:41.775 3724 3740 I TestRunner: android.database.CursorWindowAllocationException: Cursor window could not be created from binder.
06-27 10:13:41.775 3724 3740 I TestRunner: at android.database.CursorWindow.<init>(CursorWindow.java:137)
06-27 10:13:41.775 3724 3740 I TestRunner: at android.database.CursorWindow.<init>(CursorWindow.java)
06-27 10:13:41.775 3724 3740 I TestRunner: at android.database.CursorWindow$1.createFromParcel(CursorWindow.java:685)
06-27 10:13:41.775 3724 3740 I TestRunner: at android.database.CursorWindow$1.createFromParcel(CursorWindow.java:684)
06-27 10:13:41.775 3724 3740 I TestRunner: at android.database.BulkCursorDescriptor.readFromParcel(BulkCursorDescriptor.java:75)
06-27 10:13:41.775 3724 3740 I TestRunner: at android.database.BulkCursorDescriptor$1.createFromParcel(BulkCursorDescriptor.java:34)
06-27 10:13:41.775 3724 3740 I TestRunner: at android.database.BulkCursorDescriptor$1.createFromParcel(BulkCursorDescriptor.java:32)
06-27 10:13:41.775 3724 3740 I TestRunner: at android.content.ContentProviderProxy.query(ContentProviderNative.java:424)
06-27 10:13:41.775 3724 3740 I TestRunner: at android.content.ContentResolver.query(ContentResolver.java:537)
- [ALPS03965552] Disallow reading object data from Parcels with non-object reads
- http://gerrit.mediatek.inc:8080/c/platform/frameworks/native/+/1582307
- [ALPS03965552] Increment when attempting to read protected Parcel Data
- http://gerrit.mediatek.inc:8080/c/platform/frameworks/native/+/1630638
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 |
diff --git a/libs/binder/Parcel.cpp b/libs/binder/Parcel.cpp index 395caef..b2cc55c 100644 --- a/libs/binder/Parcel.cpp +++ b/libs/binder/Parcel.cpp @@ -1430,7 +1430,12 @@ && len <= pad_size(len)) { if (mObjectsSize > 0) { status_t err = validateReadData(mDataPos + pad_size(len)); - if(err != NO_ERROR) return err; + if(err != NO_ERROR) { + // Still increment the data position by the expected length + mDataPos += pad_size(len); + ALOGV("read Setting data pos of %p to %zu", this, mDataPos); + return err; + } } memcpy(outData, mData+mDataPos, len); mDataPos += pad_size(len); @@ -1452,7 +1457,12 @@ && len <= pad_size(len)) { if (mObjectsSize > 0) { status_t err = validateReadData(mDataPos + pad_size(len)); - if(err != NO_ERROR) return NULL; + if(err != NO_ERROR) { + // Still increment the data position by the expected length + mDataPos += pad_size(len); + ALOGV("readInplace Setting data pos of %p to %zu", this, mDataPos); + return NULL; + } } const void* data = mData+mDataPos; @@ -1470,7 +1480,11 @@ if ((mDataPos+sizeof(T)) <= mDataSize) { if (mObjectsSize > 0) { status_t err = validateReadData(mDataPos + sizeof(T)); - if(err != NO_ERROR) return err; + if(err != NO_ERROR) { + // Still increment the data position by the expected length + mDataPos += sizeof(T); + return err; + } } const void* data = mData+mDataPos; |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 |
diff --git a/include/binder/Parcel.h b/include/binder/Parcel.h index 2490b82..6ea8453 100644 --- a/include/binder/Parcel.h +++ b/include/binder/Parcel.h @@ -375,6 +375,7 @@ void freeDataNoInit(); void initState(); void scanForFds() const; + status_t validateReadData(size_t len) const; template status_t readAligned(T *pArg) const; @@ -421,6 +422,7 @@ size_t mObjectsSize; size_t mObjectsCapacity; mutable size_t mNextObjectHint; + mutable bool mObjectsSorted; mutable bool mFdsKnown; mutable bool mHasFds; diff --git a/libs/binder/Parcel.cpp b/libs/binder/Parcel.cpp index b2e45f2..395caef 100644 --- a/libs/binder/Parcel.cpp +++ b/libs/binder/Parcel.cpp @@ -459,6 +459,7 @@ mDataPos = pos; mNextObjectHint = 0; + mObjectsSorted = false; } status_t Parcel::setDataCapacity(size_t size) @@ -1364,6 +1365,59 @@ LOG_ALWAYS_FATAL("Parcel::remove() not yet implemented!"); } +status_t Parcel::validateReadData(size_t upperBound) const +{ + // Don't allow non-object reads on object data + if (mObjectsSorted || mObjectsSize <= 1) { +data_sorted: + // Expect to check only against the next object + if (mNextObjectHint < mObjectsSize && upperBound > mObjects[mNextObjectHint]) { + // For some reason the current read position is greater than the next object + // hint. Iterate until we find the right object + size_t nextObject = mNextObjectHint; + do { + if (mDataPos < mObjects[nextObject] + sizeof(flat_binder_object)) { + // Requested info overlaps with an object + ALOGE("Attempt to read from protected data in Parcel %p", this); + return PERMISSION_DENIED; + } + nextObject++; + } while (nextObject < mObjectsSize && upperBound > mObjects[nextObject]); + mNextObjectHint = nextObject; + } + return NO_ERROR; + } + // Quickly determine if mObjects is sorted. + binder_size_t* currObj = mObjects + mObjectsSize - 1; + binder_size_t* prevObj = currObj; + while (currObj > mObjects) { + prevObj--; + if(*prevObj > *currObj) { + goto data_unsorted; + } + currObj--; + } + mObjectsSorted = true; + goto data_sorted; + +data_unsorted: + // Insertion Sort mObjects + // Great for mostly sorted lists. If randomly sorted or reverse ordered mObjects become common, + // switch to std::sort(mObjects, mObjects + mObjectsSize); + for (binder_size_t* iter0 = mObjects + 1; iter0 < mObjects + mObjectsSize; iter0++) { + binder_size_t temp = *iter0; + binder_size_t* iter1 = iter0 - 1; + while (iter1 >= mObjects && *iter1 > temp) { + *(iter1 + 1) = *iter1; + iter1--; + } + *(iter1 + 1) = temp; + } + mNextObjectHint = 0; + mObjectsSorted = true; + goto data_sorted; +} + status_t Parcel::read(void* outData, size_t len) const { if (len > INT32_MAX) { @@ -1374,6 +1428,10 @@ if ((mDataPos+pad_size(len)) >= mDataPos && (mDataPos+pad_size(len)) <= mDataSize && len <= pad_size(len)) { + if (mObjectsSize > 0) { + status_t err = validateReadData(mDataPos + pad_size(len)); + if(err != NO_ERROR) return err; + } memcpy(outData, mData+mDataPos, len); mDataPos += pad_size(len); ALOGV("read Setting data pos of %p to %zu", this, mDataPos); @@ -1392,6 +1450,11 @@ if ((mDataPos+pad_size(len)) >= mDataPos && (mDataPos+pad_size(len)) <= mDataSize && len <= pad_size(len)) { + if (mObjectsSize > 0) { + status_t err = validateReadData(mDataPos + pad_size(len)); + if(err != NO_ERROR) return NULL; + } + const void* data = mData+mDataPos; mDataPos += pad_size(len); ALOGV("readInplace Setting data pos of %p to %zu", this, mDataPos); @@ -1405,6 +1468,11 @@ COMPILE_TIME_ASSERT_FUNCTION_SCOPE(PAD_SIZE_UNSAFE(sizeof(T)) == sizeof(T)); if ((mDataPos+sizeof(T)) <= mDataSize) { + if (mObjectsSize > 0) { + status_t err = validateReadData(mDataPos + sizeof(T)); + if(err != NO_ERROR) return err; + } + const void* data = mData+mDataPos; mDataPos += sizeof(T); *pArg = *reinterpret_cast(data); @@ -2211,6 +2279,7 @@ mObjects = const_cast<binder_size_t*>(objects); mObjectsSize = mObjectsCapacity = objectsCount; mNextObjectHint = 0; + mObjectsSorted = false; mOwner = relFunc; mOwnerCookie = relCookie; for (size_t i = 0; i < mObjectsSize; i++) { @@ -2373,6 +2442,7 @@ mObjects = NULL; mObjectsSize = mObjectsCapacity = 0; mNextObjectHint = 0; + mObjectsSorted = false; mHasFds = false; mFdsKnown = true; mAllowFds = true; @@ -2459,6 +2529,7 @@ mDataCapacity = desired; mObjectsSize = mObjectsCapacity = objectsSize; mNextObjectHint = 0; + mObjectsSorted = false; } else if (mData) { if (objectsSize < mObjectsSize) { @@ -2480,6 +2551,7 @@ } mObjectsSize = objectsSize; mNextObjectHint = 0; + mObjectsSorted = false; } // We own the data, so we can just do a realloc(). @@ -2552,6 +2624,7 @@ mObjectsSize = 0; mObjectsCapacity = 0; mNextObjectHint = 0; + mObjectsSorted = false; mHasFds = false; mFdsKnown = true; mAllowFds = true; |
06-27 10:13:41.773 3724 3740 I TestRunner: ----- begin exception -----
06-27 10:13:41.775 3724 3740 I TestRunner: android.database.CursorWindowAllocationException: Cursor window could not be created from binder.
06-27 10:13:41.775 3724 3740 I TestRunner: at android.database.CursorWindow.<init>(CursorWindow.java:137)
06-27 10:13:41.775 3724 3740 I TestRunner: at android.database.CursorWindow.<init>(CursorWindow.java)
06-27 10:13:41.775 3724 3740 I TestRunner: at android.database.CursorWindow$1.createFromParcel(CursorWindow.java:685)
06-27 10:13:41.775 3724 3740 I TestRunner: at android.database.CursorWindow$1.createFromParcel(CursorWindow.java:684)
如何是如上错误,当前的问题是google issue , 请申请豁免
https://android-review.googlesource.com/c/platform/cts/+/705304
Make CTS test testQuery more flexible It shouldn't fail on systems without protected Parcel data patch. Test: atest android.content.cts.ContentProviderCursorWindowTest Bug: 78176586 Bug: 80207731 |