diff options
author | 2024-10-02 00:37:59 +0000 | |
---|---|---|
committer | 2024-10-02 01:17:45 +0000 | |
commit | c54dad65317f851ce9d016bd90ec6a7a04da09fc (patch) | |
tree | 52c73034b03e2f17dbe03504f0a8e2a3368d2d75 /libs/binder/Parcel.cpp | |
parent | 608524d462278c2c9f6716cd94f126c85e9f2e91 (diff) |
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
Diffstat (limited to 'libs/binder/Parcel.cpp')
-rw-r--r-- | libs/binder/Parcel.cpp | 12 |
1 files changed, 12 insertions, 0 deletions
diff --git a/libs/binder/Parcel.cpp b/libs/binder/Parcel.cpp index 3d36f2eed7..d346ad15d2 100644 --- a/libs/binder/Parcel.cpp +++ b/libs/binder/Parcel.cpp @@ -1211,6 +1211,10 @@ restart_write: //printf("Writing %ld bytes, padded to %ld\n", len, padded); uint8_t* const data = mData+mDataPos; + if (status_t status = validateReadData(mDataPos + padded); status != OK) { + return nullptr; // drops status + } + // Need to pad at end? if (padded != len) { #if BYTE_ORDER == BIG_ENDIAN @@ -1799,6 +1803,10 @@ status_t Parcel::writeObject(const flat_binder_object& val, bool nullMetaData) const bool enoughObjects = kernelFields->mObjectsSize < kernelFields->mObjectsCapacity; if (enoughData && enoughObjects) { restart_write: + if (status_t status = validateReadData(mDataPos + sizeof(val)); status != OK) { + return status; + } + *reinterpret_cast<flat_binder_object*>(mData+mDataPos) = val; // remember if it's a file descriptor @@ -2042,6 +2050,10 @@ status_t Parcel::writeAligned(T val) { if ((mDataPos+sizeof(val)) <= mDataCapacity) { restart_write: + if (status_t status = validateReadData(mDataPos + sizeof(val)); status != OK) { + return status; + } + memcpy(mData + mDataPos, &val, sizeof(val)); return finishWrite(sizeof(val)); } |