summaryrefslogtreecommitdiff
path: root/msm8996
diff options
context:
space:
mode:
authorPraveen Chavan <pchavan@codeaurora.org>2016-03-21 12:43:42 -0700
committerMarco Nelissen <marcone@google.com>2016-04-05 08:25:28 -0700
commit417bd6d3d293ef616a5a33741cfd6ac8c50f685f (patch)
tree95f63832b1c0b533d3c022a1cccf81f3c81197e9 /msm8996
parentaf0b35a2e7f4d246242c0f35fcde04858dd6670d (diff)
downloadmedia-417bd6d3d293ef616a5a33741cfd6ac8c50f685f.tar.gz
mm-video-v4l2: venc: add safety checks for freeing buffers
Allow only up to 64 buffers on input/output port (since the allocation bitmap is only 64-wide). Add safety checks to free only as many buffers were allocated. Fixes: Heap Overflow and Possible Local Privilege Escalation in MediaServer (libOmxVenc problem) Bug: 27532497 Change-Id: I31e576ef9dc542df73aa6b0ea113d72724b50fc6
Diffstat (limited to 'msm8996')
-rw-r--r--msm8996/mm-video-v4l2/vidc/venc/inc/omx_video_base.h7
-rw-r--r--msm8996/mm-video-v4l2/vidc/venc/src/omx_video_base.cpp9
-rw-r--r--msm8996/mm-video-v4l2/vidc/venc/src/omx_video_encoder.cpp29
3 files changed, 37 insertions, 8 deletions
diff --git a/msm8996/mm-video-v4l2/vidc/venc/inc/omx_video_base.h b/msm8996/mm-video-v4l2/vidc/venc/inc/omx_video_base.h
index eb40309..1c3af87 100644
--- a/msm8996/mm-video-v4l2/vidc/venc/inc/omx_video_base.h
+++ b/msm8996/mm-video-v4l2/vidc/venc/inc/omx_video_base.h
@@ -1,5 +1,5 @@
/*--------------------------------------------------------------------------
-Copyright (c) 2010-2015, The Linux Foundation. All rights reserved.
+Copyright (c) 2010-2016, The Linux Foundation. All rights reserved.
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are
@@ -136,9 +136,10 @@ static const char* MEM_DEVICE = "/dev/pmem_smipool";
& BITMASK_FLAG(mIndex))
#define BITMASK_ABSENT(mArray,mIndex) (((mArray)[BITMASK_OFFSET(mIndex)] \
& BITMASK_FLAG(mIndex)) == 0x0)
-#ifdef _ANDROID_ICS_
+
#define MAX_NUM_INPUT_BUFFERS 64
-#endif
+#define MAX_NUM_OUTPUT_BUFFERS 64
+
void* message_thread(void *);
enum omx_venc_extradata_types {
diff --git a/msm8996/mm-video-v4l2/vidc/venc/src/omx_video_base.cpp b/msm8996/mm-video-v4l2/vidc/venc/src/omx_video_base.cpp
index bd2b794..861a498 100644
--- a/msm8996/mm-video-v4l2/vidc/venc/src/omx_video_base.cpp
+++ b/msm8996/mm-video-v4l2/vidc/venc/src/omx_video_base.cpp
@@ -2665,7 +2665,6 @@ OMX_ERRORTYPE omx_video::use_output_buffer(
*bufferHdr = (m_out_mem_ptr + i );
(*bufferHdr)->pBuffer = (OMX_U8 *)buffer;
(*bufferHdr)->pAppPrivate = appData;
- BITMASK_SET(&m_out_bm_count,i);
if (!m_use_output_pmem) {
#ifdef USE_ION
@@ -2744,6 +2743,8 @@ OMX_ERRORTYPE omx_video::use_output_buffer(
DEBUG_PRINT_ERROR("ERROR: dev_use_buf Failed for o/p buf");
return OMX_ErrorInsufficientResources;
}
+
+ BITMASK_SET(&m_out_bm_count,i);
} else {
DEBUG_PRINT_ERROR("ERROR: All o/p Buffers have been Used, invalid use_buf call for "
"index = %u", i);
@@ -3447,7 +3448,8 @@ OMX_ERRORTYPE omx_video::free_buffer(OMX_IN OMX_HANDLETYPE hComp,
DEBUG_PRINT_LOW("free_buffer on i/p port - Port idx %u, actual cnt %u",
nPortIndex, (unsigned int)m_sInPortDef.nBufferCountActual);
- if (nPortIndex < m_sInPortDef.nBufferCountActual) {
+ if (nPortIndex < m_sInPortDef.nBufferCountActual &&
+ BITMASK_PRESENT(&m_inp_bm_count, nPortIndex)) {
// Clear the bit associated with it.
BITMASK_CLEAR(&m_inp_bm_count,nPortIndex);
free_input_buffer (buffer);
@@ -3497,7 +3499,8 @@ OMX_ERRORTYPE omx_video::free_buffer(OMX_IN OMX_HANDLETYPE hComp,
DEBUG_PRINT_LOW("free_buffer on o/p port - Port idx %u, actual cnt %u",
nPortIndex, (unsigned int)m_sOutPortDef.nBufferCountActual);
- if (nPortIndex < m_sOutPortDef.nBufferCountActual) {
+ if (nPortIndex < m_sOutPortDef.nBufferCountActual &&
+ BITMASK_PRESENT(&m_out_bm_count, nPortIndex)) {
// Clear the bit associated with it.
BITMASK_CLEAR(&m_out_bm_count,nPortIndex);
m_sOutPortDef.bPopulated = OMX_FALSE;
diff --git a/msm8996/mm-video-v4l2/vidc/venc/src/omx_video_encoder.cpp b/msm8996/mm-video-v4l2/vidc/venc/src/omx_video_encoder.cpp
index 87cf55e..ebaa216 100644
--- a/msm8996/mm-video-v4l2/vidc/venc/src/omx_video_encoder.cpp
+++ b/msm8996/mm-video-v4l2/vidc/venc/src/omx_video_encoder.cpp
@@ -655,6 +655,11 @@ OMX_ERRORTYPE omx_venc::set_parameter(OMX_IN OMX_HANDLETYPE hComp,
DEBUG_PRINT_LOW("i/p actual cnt requested = %u", (unsigned int)portDefn->nBufferCountActual);
DEBUG_PRINT_LOW("i/p min cnt requested = %u", (unsigned int)portDefn->nBufferCountMin);
DEBUG_PRINT_LOW("i/p buffersize requested = %u", (unsigned int)portDefn->nBufferSize);
+ if (portDefn->nBufferCountActual > MAX_NUM_INPUT_BUFFERS) {
+ DEBUG_PRINT_ERROR("ERROR: (In_PORT) actual count (%u) exceeds max(%u)",
+ (unsigned int)portDefn->nBufferCountActual, (unsigned int)MAX_NUM_INPUT_BUFFERS);
+ return OMX_ErrorUnsupportedSetting;
+ }
if (portDefn->nBufferCountMin > portDefn->nBufferCountActual) {
DEBUG_PRINT_ERROR("ERROR: (In_PORT) Min buffers (%u) > actual count (%u)",
(unsigned int)portDefn->nBufferCountMin, (unsigned int)portDefn->nBufferCountActual);
@@ -703,6 +708,12 @@ OMX_ERRORTYPE omx_venc::set_parameter(OMX_IN OMX_HANDLETYPE hComp,
DEBUG_PRINT_LOW("o/p actual cnt requested = %u", (unsigned int)portDefn->nBufferCountActual);
DEBUG_PRINT_LOW("o/p min cnt requested = %u", (unsigned int)portDefn->nBufferCountMin);
DEBUG_PRINT_LOW("o/p buffersize requested = %u", (unsigned int)portDefn->nBufferSize);
+
+ if (portDefn->nBufferCountActual > MAX_NUM_OUTPUT_BUFFERS) {
+ DEBUG_PRINT_ERROR("ERROR: (Out_PORT) actual count (%u) exceeds max(%u)",
+ (unsigned int)portDefn->nBufferCountActual, (unsigned int)MAX_NUM_OUTPUT_BUFFERS);
+ return OMX_ErrorUnsupportedSetting;
+ }
if (portDefn->nBufferCountMin > portDefn->nBufferCountActual) {
DEBUG_PRINT_ERROR("ERROR: (Out_PORT) Min buffers (%u) > actual count (%u)",
(unsigned int)portDefn->nBufferCountMin, (unsigned int)portDefn->nBufferCountActual);
@@ -2054,7 +2065,14 @@ OMX_ERRORTYPE omx_venc::component_deinit(OMX_IN OMX_HANDLETYPE hComp)
if (m_out_mem_ptr) {
DEBUG_PRINT_LOW("Freeing the Output Memory");
for (i=0; i< m_sOutPortDef.nBufferCountActual; i++ ) {
- free_output_buffer (&m_out_mem_ptr[i]);
+ if (BITMASK_PRESENT(&m_out_bm_count, i)) {
+ BITMASK_CLEAR(&m_out_bm_count, i);
+ free_output_buffer (&m_out_mem_ptr[i]);
+ }
+
+ if (release_output_done()) {
+ break;
+ }
}
free(m_out_mem_ptr);
m_out_mem_ptr = NULL;
@@ -2068,7 +2086,14 @@ OMX_ERRORTYPE omx_venc::component_deinit(OMX_IN OMX_HANDLETYPE hComp)
) {
DEBUG_PRINT_LOW("Freeing the Input Memory");
for (i=0; i<m_sInPortDef.nBufferCountActual; i++ ) {
- free_input_buffer (&m_inp_mem_ptr[i]);
+ if (BITMASK_PRESENT(&m_inp_bm_count, i)) {
+ BITMASK_CLEAR(&m_inp_bm_count, i);
+ free_input_buffer (&m_inp_mem_ptr[i]);
+ }
+
+ if (release_input_done()) {
+ break;
+ }
}