diff options
| author | 2019-04-08 19:22:11 -0700 | |
|---|---|---|
| committer | 2019-04-08 19:24:40 -0700 | |
| commit | 47942d97d419aae1745fca9ff895c57b037c7bdc (patch) | |
| tree | 73b7322c24a400914b8793f190beae5bb8e22535 | |
| parent | 5baeab86a03861fa6f1772acde3956bfdb52b999 (diff) | |
hwbinder: explicitly disallow local java binder
Local binders from Java are currently not supported. However, changes
which make them appear to work are planned (but which will also make
using them require unnecessary parceling). Explicitly disabling them
so that there is a clear error message instead of random errors.
Bug: 129150021
Test: boot, check logs
Test: system/tools/hidl/test/run_all_device_tests.sh
Change-Id: I107cbc768d6285b50c0eef6d41a16155d76e35dd
| -rw-r--r-- | core/jni/android_os_HwBinder.cpp | 19 | ||||
| -rw-r--r-- | core/jni/android_os_HwBinder.h | 2 | ||||
| -rw-r--r-- | core/jni/android_os_HwParcel.cpp | 8 |
3 files changed, 25 insertions, 4 deletions
diff --git a/core/jni/android_os_HwBinder.cpp b/core/jni/android_os_HwBinder.cpp index 42e3942eb350..9c60e6bd8565 100644 --- a/core/jni/android_os_HwBinder.cpp +++ b/core/jni/android_os_HwBinder.cpp @@ -224,6 +224,21 @@ status_t JHwBinder::onTransact( return err; } +bool validateCanUseHwBinder(const sp<hardware::IBinder>& binder) { + if (binder != nullptr && binder->localBinder() != nullptr) { + // untested/unsupported/inefficient + // see b/129150021, doesn't work with scatter-gather + // + // explicitly disabling until it is supported + // (note, even if this is fixed to work with scatter gather, we would also need + // to convert this to the Java object rather than re-wrapping with a proxy) + LOG(ERROR) << "Local Java Binder not supported."; + return false; + } + + return true; +} + } // namespace android //////////////////////////////////////////////////////////////////////////////// @@ -324,9 +339,9 @@ static jobject JHwBinder_native_getService( sp<IBase> ret = getRawServiceInternal(ifaceName, serviceName, retry /* retry */, false /* getStub */); sp<hardware::IBinder> service = hardware::toBinder<hidl::base::V1_0::IBase>(ret); - if (service == NULL) { + if (service == nullptr || !validateCanUseHwBinder(service)) { signalExceptionForError(env, NAME_NOT_FOUND); - return NULL; + return nullptr; } LOG(INFO) << "HwBinder: Starting thread pool for getting: " << ifaceName << "/" << serviceName; diff --git a/core/jni/android_os_HwBinder.h b/core/jni/android_os_HwBinder.h index 5352f1e607c2..99195b1abc9c 100644 --- a/core/jni/android_os_HwBinder.h +++ b/core/jni/android_os_HwBinder.h @@ -54,6 +54,8 @@ private: int register_android_os_HwBinder(JNIEnv *env); +bool validateCanUseHwBinder(const sp<hardware::IBinder>& binder); + } // namespace android #endif // _ANDROID_OS_HW_BINDER_H diff --git a/core/jni/android_os_HwParcel.cpp b/core/jni/android_os_HwParcel.cpp index 7221ca11cc00..f437a78e35f8 100644 --- a/core/jni/android_os_HwParcel.cpp +++ b/core/jni/android_os_HwParcel.cpp @@ -883,8 +883,12 @@ static jobject JHwParcel_native_readStrongBinder(JNIEnv *env, jobject thiz) { sp<hardware::IBinder> binder = parcel->readStrongBinder(); - if (binder == NULL) { - return NULL; + if (binder == nullptr) { + return nullptr; + } + + if (!validateCanUseHwBinder(binder)) { + return nullptr; } return JHwRemoteBinder::NewObject(env, binder); |