Skip to content

Commit c54dad6

Browse files
author
Steven Moreland
committed
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 Change-Id: Ibc5566ade0389221690dc90324f93394cf7fc9a5
1 parent 608524d commit c54dad6

1 file changed

Lines changed: 12 additions & 0 deletions

File tree

libs/binder/Parcel.cpp

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1211,6 +1211,10 @@ void* Parcel::writeInplace(size_t len)
12111211
//printf("Writing %ld bytes, padded to %ld\n", len, padded);
12121212
uint8_t* const data = mData+mDataPos;
12131213

1214+
if (status_t status = validateReadData(mDataPos + padded); status != OK) {
1215+
return nullptr; // drops status
1216+
}
1217+
12141218
// Need to pad at end?
12151219
if (padded != len) {
12161220
#if BYTE_ORDER == BIG_ENDIAN
@@ -1799,6 +1803,10 @@ status_t Parcel::writeObject(const flat_binder_object& val, bool nullMetaData)
17991803
const bool enoughObjects = kernelFields->mObjectsSize < kernelFields->mObjectsCapacity;
18001804
if (enoughData && enoughObjects) {
18011805
restart_write:
1806+
if (status_t status = validateReadData(mDataPos + sizeof(val)); status != OK) {
1807+
return status;
1808+
}
1809+
18021810
*reinterpret_cast<flat_binder_object*>(mData+mDataPos) = val;
18031811

18041812
// remember if it's a file descriptor
@@ -2042,6 +2050,10 @@ status_t Parcel::writeAligned(T val) {
20422050

20432051
if ((mDataPos+sizeof(val)) <= mDataCapacity) {
20442052
restart_write:
2053+
if (status_t status = validateReadData(mDataPos + sizeof(val)); status != OK) {
2054+
return status;
2055+
}
2056+
20452057
memcpy(mData + mDataPos, &val, sizeof(val));
20462058
return finishWrite(sizeof(val));
20472059
}

0 commit comments

Comments
 (0)