diff options
author | 2022-03-10 23:34:07 +0000 | |
---|---|---|
committer | 2022-03-14 18:05:51 +0000 | |
commit | 2a1e241d8042c3df6e191462d384580bd0358977 (patch) | |
tree | 10d8120c8ed9cb79647ee226819fb401264d76b7 | |
parent | 2362edf7a6c9c7d756d6e573c4d44837e16fed36 (diff) |
libbinder*: ParcelableHolder assert stability read
The interface a ParcelableHolder is in determines its stability,
and it shouldn't change based on what is sent.
Bug: 215458170
Test: aidl_integration_test
Change-Id: I35f1342edc9f3dc40e2553a4eaf386f67a9fbaa1
-rw-r--r-- | libs/binder/ParcelableHolder.cpp | 5 | ||||
-rw-r--r-- | libs/binder/ndk/include_cpp/android/binder_parcelable_utils.h | 7 | ||||
-rw-r--r-- | libs/binder/rust/src/parcel/parcelable_holder.rs | 4 |
3 files changed, 13 insertions, 3 deletions
diff --git a/libs/binder/ParcelableHolder.cpp b/libs/binder/ParcelableHolder.cpp index 2e86b7415a..3cf94e3047 100644 --- a/libs/binder/ParcelableHolder.cpp +++ b/libs/binder/ParcelableHolder.cpp @@ -52,7 +52,10 @@ status_t ParcelableHolder::writeToParcel(Parcel* p) const { } status_t ParcelableHolder::readFromParcel(const Parcel* p) { - this->mStability = static_cast<Stability>(p->readInt32()); + int32_t wireStability; + if (status_t status = p->readInt32(&wireStability); status != OK) return status; + if (static_cast<int32_t>(this->mStability) != wireStability) return BAD_VALUE; + this->mParcelable = nullptr; this->mParcelableName = std::nullopt; int32_t rawDataSize; diff --git a/libs/binder/ndk/include_cpp/android/binder_parcelable_utils.h b/libs/binder/ndk/include_cpp/android/binder_parcelable_utils.h index 28819bb42a..f45aa7631b 100644 --- a/libs/binder/ndk/include_cpp/android/binder_parcelable_utils.h +++ b/libs/binder/ndk/include_cpp/android/binder_parcelable_utils.h @@ -101,7 +101,12 @@ class AParcelableHolder { return STATUS_INVALID_OPERATION; } - RETURN_ON_FAILURE(AParcel_readInt32(parcel, &this->mStability)); + parcelable_stability_t wireStability; + RETURN_ON_FAILURE(AParcel_readInt32(parcel, &wireStability)); + if (this->mStability != wireStability) { + return STATUS_BAD_VALUE; + } + int32_t dataSize; binder_status_t status = AParcel_readInt32(parcel, &dataSize); diff --git a/libs/binder/rust/src/parcel/parcelable_holder.rs b/libs/binder/rust/src/parcel/parcelable_holder.rs index d58e839ad4..432da5dfd7 100644 --- a/libs/binder/rust/src/parcel/parcelable_holder.rs +++ b/libs/binder/rust/src/parcel/parcelable_holder.rs @@ -233,7 +233,9 @@ impl Parcelable for ParcelableHolder { } fn read_from_parcel(&mut self, parcel: &BorrowedParcel<'_>) -> Result<(), StatusCode> { - self.stability = parcel.read()?; + if self.stability != parcel.read()? { + return Err(StatusCode::BAD_VALUE); + } let data_size: i32 = parcel.read()?; if data_size < 0 { |