Skip to content

Commit d3ec4f9

Browse files
smore-loreaoleary
authored andcommitted
libbinder: Parcel: validate read data before write
This is slow, but it's required to prevent memory corruption. Ignore-AOSP-First: security Bug: 370840874 Test: fuzzer (cherry picked from commit c54dad65317f851ce9d016bd90ec6a7a04da09fc) (cherry picked from https://googleplex-android-review.googlesource.com/q/commit:f946e3c5e34539ba1fe9f03025005e5b248ebbc6) Merged-In: Ibc5566ade0389221690dc90324f93394cf7fc9a5 Change-Id: Ibc5566ade0389221690dc90324f93394cf7fc9a5
1 parent 58ef98e commit d3ec4f9

File tree

1 file changed

+12
-0
lines changed

1 file changed

+12
-0
lines changed

libs/binder/Parcel.cpp

+12
Original file line numberDiff line numberDiff line change
@@ -888,6 +888,10 @@ void* Parcel::writeInplace(size_t len)
888888
//printf("Writing %ld bytes, padded to %ld\n", len, padded);
889889
uint8_t* const data = mData+mDataPos;
890890

891+
if (status_t status = validateReadData(mDataPos + padded); status != OK) {
892+
return nullptr; // drops status
893+
}
894+
891895
// Need to pad at end?
892896
if (padded != len) {
893897
#if BYTE_ORDER == BIG_ENDIAN
@@ -1405,6 +1409,10 @@ status_t Parcel::writeObject(const flat_binder_object& val, bool nullMetaData)
14051409
const bool enoughObjects = mObjectsSize < mObjectsCapacity;
14061410
if (enoughData && enoughObjects) {
14071411
restart_write:
1412+
if (status_t status = validateReadData(mDataPos + sizeof(val)); status != OK) {
1413+
return status;
1414+
}
1415+
14081416
*reinterpret_cast<flat_binder_object*>(mData+mDataPos) = val;
14091417

14101418
// remember if it's a file descriptor
@@ -1621,6 +1629,10 @@ status_t Parcel::writeAligned(T val) {
16211629

16221630
if ((mDataPos+sizeof(val)) <= mDataCapacity) {
16231631
restart_write:
1632+
if (status_t status = validateReadData(mDataPos + sizeof(val)); status != OK) {
1633+
return status;
1634+
}
1635+
16241636
memcpy(mData + mDataPos, &val, sizeof(val));
16251637
return finishWrite(sizeof(val));
16261638
}

0 commit comments

Comments
 (0)