Revert "pal: validate stream handle in pal server wrapper"
Reason for revert: Causes a fatal crash with current available blobs.
This reverts commit 9ad4b3168d78dd870e8a287ff425efc1e28f4eb9.
Change-Id: I8ffccc6fa8e458b332ceda6f4b7e6d3cccacc3a1
diff --git a/ipc/HwBinders/pal_ipc_server/inc/pal_server_wrapper.h b/ipc/HwBinders/pal_ipc_server/inc/pal_server_wrapper.h
index 214e312..c17abc4 100644
--- a/ipc/HwBinders/pal_ipc_server/inc/pal_server_wrapper.h
+++ b/ipc/HwBinders/pal_ipc_server/inc/pal_server_wrapper.h
@@ -111,7 +111,6 @@
struct PAL : public IPAL /*, public android::hardware::hidl_death_recipient*/{
public:
- std::mutex mClientLock;
PAL()
{
sInstance = this;
@@ -203,7 +202,6 @@
static PAL* sInstance;
int find_dup_fd_from_input_fd(const uint64_t streamHandle, int input_fd, int *dup_fd);
void add_input_and_dup_fd(const uint64_t streamHandle, int input_fd, int dup_fd);
- bool isValidstreamHandle(const uint64_t streamHandle);
};
class PalClientDeathRecipient : public android::hardware::hidl_death_recipient
diff --git a/ipc/HwBinders/pal_ipc_server/src/pal_server_wrapper.cpp b/ipc/HwBinders/pal_ipc_server/src/pal_server_wrapper.cpp
index d9db67e..5e2497b 100644
--- a/ipc/HwBinders/pal_ipc_server/src/pal_server_wrapper.cpp
+++ b/ipc/HwBinders/pal_ipc_server/src/pal_server_wrapper.cpp
@@ -57,7 +57,6 @@
std::lock_guard<std::mutex> guard(mLock);
ALOGD("%s : client died pid : %d", __func__, cookie);
int pid = (int) cookie;
- std::lock_guard<std::mutex> lock(mPalInstance->mClientLock);
auto &clients = mPalInstance->mPalClients;
for (auto itr = clients.begin(); itr != clients.end(); itr++) {
auto client = *itr;
@@ -89,7 +88,6 @@
void PAL::add_input_and_dup_fd(const uint64_t streamHandle, int input_fd, int dup_fd)
{
std::vector<std::pair<int, int>>::iterator it;
- std::lock_guard<std::mutex> guard(mClientLock);
for (auto& s: mPalClients) {
std::lock_guard<std::mutex> lock(s->mActiveSessionsLock);
for (int i = 0; i < s->mActiveSessions.size(); i++) {
@@ -133,7 +131,6 @@
ALOGE("%s: No PAL instance running", __func__);
return false;
}
- std::lock_guard<std::mutex> guard(PAL::getInstance()->mClientLock);
for (auto& s: PAL::getInstance()->mPalClients) {
std::lock_guard<std::mutex> lock(s->mActiveSessionsLock);
for (int idx = 0; idx < s->mActiveSessions.size(); idx++) {
@@ -173,7 +170,6 @@
* Find the original fd that was passed by client based on what
* input and dup fd list and send that back.
*/
- PAL::getInstance()->mClientLock.lock();
for (auto& s: PAL::getInstance()->mPalClients) {
std::lock_guard<std::mutex> lock(s->mActiveSessionsLock);
for (int idx = 0; idx < s->mActiveSessions.size(); idx++) {
@@ -196,7 +192,6 @@
}
}
}
- PAL::getInstance()->mClientLock.unlock();
rwDonePayloadHidl.resize(sizeof(struct pal_event_read_write_done_payload));
rwDonePayload =(PalEventReadWriteDonePayload *)rwDonePayloadHidl.data();
@@ -316,32 +311,6 @@
print_media_config(&attr->out_media_config);
}
-bool PAL::isValidstreamHandle(const uint64_t streamHandle) {
- int pid = ::android::hardware::IPCThreadState::self()->getCallingPid();
-
- std::lock_guard<std::mutex> guard(mClientLock);
- for (auto itr = mPalClients.begin(); itr != mPalClients.end(); ) {
- auto client = *itr;
- if (client->pid == pid) {
- std::lock_guard<std::mutex> lock(client->mActiveSessionsLock);
- auto sItr = client->mActiveSessions.begin();
- for (; sItr != client->mActiveSessions.end(); sItr++) {
- if (sItr->session_handle == streamHandle) {
- return true;
- }
- }
- ALOGE("%s: streamHandle: %pK for pid %d not found",
- __func__, streamHandle, pid);
- return false;
- }
- itr++;
- }
-
- ALOGE("%s: client info for pid %d not found",
- __func__, pid);
- return false;
-}
-
Return<void> PAL::ipc_pal_stream_open(const hidl_vec<PalStreamAttributes>& attr_hidl,
uint32_t noOfDevices,
const hidl_vec<PalDevice>& devs_hidl,
@@ -445,7 +414,6 @@
callback, (uint64_t)sr_clbk_data.get(), &stream_handle);
if (!ret) {
- std::lock_guard<std::mutex> guard(mClientLock);
for(auto& client: mPalClients) {
if (client->pid == pid) {
/*Another session from the same client*/
@@ -501,13 +469,8 @@
Return<int32_t> PAL::ipc_pal_stream_close(const uint64_t streamHandle)
{
int pid = ::android::hardware::IPCThreadState::self()->getCallingPid();
+ Return<int32_t> status = pal_stream_close((pal_stream_handle_t *)streamHandle);
- if (!isValidstreamHandle(streamHandle)) {
- ALOGE("%s: Invalid streamHandle: %pK", __func__, streamHandle);
- return -EINVAL;
- }
-
- mClientLock.lock();
for (auto itr = mPalClients.begin(); itr != mPalClients.end(); ) {
auto client = *itr;
if (client->pid == pid) {
@@ -540,77 +503,38 @@
break;
}
}
- mClientLock.unlock();
-
- Return<int32_t> status = pal_stream_close((pal_stream_handle_t *)streamHandle);
-
return status;
}
Return<int32_t> PAL::ipc_pal_stream_start(const uint64_t streamHandle) {
- if (!isValidstreamHandle(streamHandle)) {
- ALOGE("%s: Invalid streamHandle: %pK", __func__, streamHandle);
- return -EINVAL;
- }
return pal_stream_start((pal_stream_handle_t *)streamHandle);
}
Return<int32_t> PAL::ipc_pal_stream_stop(const uint64_t streamHandle) {
- if (!isValidstreamHandle(streamHandle)) {
- ALOGE("%s: Invalid streamHandle: %pK", __func__, streamHandle);
- return -EINVAL;
- }
-
return pal_stream_stop((pal_stream_handle_t *)streamHandle);
}
Return<int32_t> PAL::ipc_pal_stream_pause(const uint64_t streamHandle) {
- if (!isValidstreamHandle(streamHandle)) {
- ALOGE("%s: Invalid streamHandle: %pK", __func__, streamHandle);
- return -EINVAL;
- }
-
return pal_stream_pause((pal_stream_handle_t *)streamHandle);
}
Return<int32_t> PAL::ipc_pal_stream_drain(uint64_t streamHandle, PalDrainType type)
{
pal_drain_type_t drain_type = (pal_drain_type_t) type;
-
- if (!isValidstreamHandle(streamHandle)) {
- ALOGE("%s: Invalid streamHandle: %pK", __func__, streamHandle);
- return -EINVAL;
- }
-
return pal_stream_drain((pal_stream_handle_t *)streamHandle,
drain_type);
}
Return<int32_t> PAL::ipc_pal_stream_flush(const uint64_t streamHandle) {
- if (!isValidstreamHandle(streamHandle)) {
- ALOGE("%s: Invalid streamHandle: %pK", __func__, streamHandle);
- return -EINVAL;
- }
-
return pal_stream_flush((pal_stream_handle_t *)streamHandle);
}
Return<int32_t> PAL::ipc_pal_stream_suspend(const uint64_t streamHandle) {
- if (!isValidstreamHandle(streamHandle)) {
- ALOGE("%s: Invalid streamHandle: %pK", __func__, streamHandle);
- return -EINVAL;
- }
-
return pal_stream_suspend((pal_stream_handle_t *)streamHandle);
}
Return<int32_t> PAL::ipc_pal_stream_resume(const uint64_t streamHandle) {
- if (!isValidstreamHandle(streamHandle)) {
- ALOGE("%s: Invalid streamHandle: %pK", __func__, streamHandle);
- return -EINVAL;
- }
-
return pal_stream_resume((pal_stream_handle_t *)streamHandle);
}
@@ -623,11 +547,6 @@
pal_buffer_config_t out_buf_cfg, in_buf_cfg;
PalBufferConfig in_buff_config_ret, out_buff_config_ret;
- if (!isValidstreamHandle(streamHandle)) {
- ALOGE("%s: Invalid streamHandle: %pK", __func__, streamHandle);
- return Void();
- }
-
in_buf_cfg.buf_count = in_buff_config.buf_count;
in_buf_cfg.buf_size = in_buff_config.buf_size;
in_buf_cfg.max_metadata_size = in_buff_config.max_metadata_size;
@@ -674,12 +593,6 @@
struct pal_buffer buf = {0};
uint32_t bufSize;
const native_handle *allochandle = nullptr;
-
- if (!isValidstreamHandle(streamHandle)) {
- ALOGE("%s: Invalid streamHandle: %pK", __func__, streamHandle);
- return -EINVAL;
- }
-
bufSize = buff_hidl.data()->size;
if (buff_hidl.data()->buffer.size() == bufSize)
buf.buffer = (uint8_t *)calloc(1, bufSize);
@@ -746,10 +659,6 @@
goto exit;
}
- if (!isValidstreamHandle(streamHandle)) {
- ALOGE("%s: Invalid streamHandle: %pK", __func__, streamHandle);
- return Void();
- }
allochandle = inBuff_hidl.data()->alloc_info.alloc_handle.handle();
@@ -800,12 +709,6 @@
ALOGE("Invalid payload size");
return -EINVAL;
}
-
- if (!isValidstreamHandle(streamHandle)) {
- ALOGE("%s: Invalid streamHandle: %pK", __func__, streamHandle);
- return -EINVAL;
- }
-
param_payload = (pal_param_payload *)calloc (1,
sizeof(pal_param_payload) + paramPayload.data()->size);
if (!param_payload) {
@@ -827,12 +730,6 @@
int32_t ret = 0;
pal_param_payload *param_payload;
hidl_vec<PalParamPayload> paramPayload;
-
- if (!isValidstreamHandle(streamHandle)) {
- ALOGE("%s: Invalid streamHandle: %pK", __func__, streamHandle);
- return Void();
- }
-
ret = pal_stream_get_param((pal_stream_handle_t *)streamHandle, paramId, ¶m_payload);
if (ret == 0) {
paramPayload.resize(sizeof(PalParamPayload));
@@ -860,17 +757,10 @@
struct pal_device *devices = NULL;
int cnt = 0;
int32_t ret = -ENOMEM;
-
- if (!isValidstreamHandle(streamHandle)) {
- ALOGE("%s: Invalid streamHandle: %pK", __func__, streamHandle);
- return -EINVAL;
- }
-
if (noOfDevices > devs_hidl.size()) {
ALOGE("Invalid noOfDevices");
return -EINVAL;
}
-
if (devs_hidl.size()) {
PalDevice *dev_hidl = NULL;
devices = (struct pal_device *)calloc (1,
@@ -921,12 +811,6 @@
ALOGE("Invalid vol vector size");
return -EINVAL;
}
-
- if (!isValidstreamHandle(streamHandle)) {
- ALOGE("%s: Invalid streamHandle: %pK", __func__, streamHandle);
- return -EINVAL;
- }
-
volume = (struct pal_volume_data *) calloc(1,
sizeof(struct pal_volume_data) +
noOfVolPairs * sizeof(pal_channel_vol_kv));
@@ -959,11 +843,6 @@
Return<int32_t> PAL::ipc_pal_stream_set_mute(const uint64_t streamHandle,
bool state)
{
- if (!isValidstreamHandle(streamHandle)) {
- ALOGE("%s: Invalid streamHandle: %pK", __func__, streamHandle);
- return -EINVAL;
- }
-
return pal_stream_set_mute((pal_stream_handle_t *)streamHandle, state);
}
@@ -982,12 +861,6 @@
{
struct pal_session_time stime;
int32_t ret = 0;
-
- if (!isValidstreamHandle(streamHandle)) {
- ALOGE("%s: Invalid streamHandle: %pK", __func__, streamHandle);
- return Void();
- }
-
hidl_vec<PalSessionTime> sessTime_hidl;
sessTime_hidl.resize(sizeof(struct pal_session_time));
ret = pal_get_timestamp((pal_stream_handle_t *)streamHandle, &stime);
@@ -1000,11 +873,6 @@
const PalAudioEffect effect,
bool enable)
{
- if (!isValidstreamHandle(streamHandle)) {
- ALOGE("%s: Invalid streamHandle: %pK", __func__, streamHandle);
- return -EINVAL;
- }
-
return pal_add_remove_effect((pal_stream_handle_t *)streamHandle,
(pal_audio_effect_t) effect, enable);
}
@@ -1064,12 +932,6 @@
int32_t ret = 0;
struct pal_mmap_buffer info;
hidl_vec<PalMmapBuffer> mMapBuffer_hidl;
-
- if (!isValidstreamHandle(streamHandle)) {
- ALOGE("%s: Invalid streamHandle: %pK", __func__, streamHandle);
- return Void();
- }
-
mMapBuffer_hidl.resize(sizeof(struct pal_mmap_buffer));
ret = pal_stream_create_mmap_buffer((pal_stream_handle_t *)streamHandle, min_size_frames, &info);
mMapBuffer_hidl.data()->buffer = (uint64_t)info.buffer;
@@ -1087,12 +949,6 @@
int32_t ret = 0;
struct pal_mmap_position mmap_position;
hidl_vec<PalMmapPosition> mmap_position_hidl;
-
- if (!isValidstreamHandle(streamHandle)) {
- ALOGE("%s: Invalid streamHandle: %pK", __func__, streamHandle);
- return Void();
- }
-
mmap_position_hidl.resize(sizeof(struct pal_mmap_position));
ret = pal_stream_get_mmap_position((pal_stream_handle_t *)streamHandle, &mmap_position);
memcpy(mmap_position_hidl.data(), &mmap_position, sizeof(struct pal_mmap_position));
@@ -1121,11 +977,6 @@
size_t sz = size;
hidl_vec<uint8_t> payloadRet;
- if (!isValidstreamHandle(streamHandle)) {
- ALOGE("%s: Invalid streamHandle: %pK", __func__, streamHandle);
- return Void();
- }
-
if (size > 0) {
payload = (uint8_t *)calloc(1, size);
if (!payload) {