summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorPraveen Chavan <pchavan@codeaurora.org>2016-07-07 16:44:52 -0700
committerJessica Wagantall <jwagantall@cyngn.com>2016-08-01 17:49:45 -0700
commitf582d1da8fc514d957f3beabcf91b46a2cc9b498 (patch)
treed8060f4cf99b844683d6791bab4026a24f7095af
parentacea3b941d2504ce7a71109309742fb1a5a2f348 (diff)
downloadandroid_hardware_qcom_media-f582d1da8fc514d957f3beabcf91b46a2cc9b498.tar.gz
android_hardware_qcom_media-f582d1da8fc514d957f3beabcf91b46a2cc9b498.tar.bz2
android_hardware_qcom_media-f582d1da8fc514d957f3beabcf91b46a2cc9b498.zip
DO NOT MERGE mm-video-v4l2: venc: add checks before
accessing heap pointers Heap pointers do not point to user virtual addresses in case of secure session. Set them to NULL and add checks to avoid accesing them Ticket: CYNGNOS-3177 Bug: 28815329 Bug: 28920116 Change-Id: I27d02331d9613f4b20949457a8634924e767864e
-rw-r--r--mm-video-v4l2/vidc/venc/src/omx_video_base.cpp21
-rw-r--r--mm-video-v4l2/vidc/venc/src/omx_video_encoder.cpp2
-rw-r--r--mm-video-v4l2/vidc/venc/src/video_encoder_device_v4l2.cpp10
3 files changed, 27 insertions, 6 deletions
diff --git a/mm-video-v4l2/vidc/venc/src/omx_video_base.cpp b/mm-video-v4l2/vidc/venc/src/omx_video_base.cpp
index a93e272d..a567408c 100644
--- a/mm-video-v4l2/vidc/venc/src/omx_video_base.cpp
+++ b/mm-video-v4l2/vidc/venc/src/omx_video_base.cpp
@@ -80,7 +80,6 @@ ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#define SZ_4K 0x1000
#define SZ_1M 0x100000
-#define SECURE_BUFPTR 0xDEADBEEF
typedef struct OMXComponentCapabilityFlagsType {
////////////////// OMX COMPONENT CAPABILITY RELATED MEMBERS
@@ -2257,7 +2256,7 @@ OMX_ERRORTYPE omx_video::use_input_buffer(
m_pInput_pmem[i].size = m_sInPortDef.nBufferSize;
m_pInput_pmem[i].offset = 0;
- m_pInput_pmem[i].buffer = (OMX_U8 *)SECURE_BUFPTR;
+ m_pInput_pmem[i].buffer = NULL;
if(!secure_session) {
m_pInput_pmem[i].buffer = (unsigned char *)mmap(
NULL,m_pInput_pmem[i].size,PROT_READ|PROT_WRITE,
@@ -2265,6 +2264,7 @@ OMX_ERRORTYPE omx_video::use_input_buffer(
if (m_pInput_pmem[i].buffer == MAP_FAILED) {
DEBUG_PRINT_ERROR("ERROR: mmap() Failed");
+ m_pInput_pmem[i].buffer = NULL;
close(m_pInput_pmem[i].fd);
#ifdef USE_ION
free_ion_memory(&m_pInput_ion[i]);
@@ -2448,7 +2448,7 @@ OMX_ERRORTYPE omx_video::use_output_buffer(
m_pOutput_pmem[i].size = m_sOutPortDef.nBufferSize;
m_pOutput_pmem[i].offset = 0;
- m_pOutput_pmem[i].buffer = (OMX_U8 *)SECURE_BUFPTR;
+ m_pOutput_pmem[i].buffer = NULL;
if(!secure_session) {
#ifdef _MSM8974_
m_pOutput_pmem[i].buffer = (unsigned char *)mmap(NULL,
@@ -2461,6 +2461,7 @@ OMX_ERRORTYPE omx_video::use_output_buffer(
#endif
if (m_pOutput_pmem[i].buffer == MAP_FAILED) {
DEBUG_PRINT_ERROR("ERROR: mmap() Failed");
+ m_pOutput_pmem[i].buffer = NULL;
close(m_pOutput_pmem[i].fd);
#ifdef USE_ION
free_ion_memory(&m_pOutput_ion[i]);
@@ -2855,13 +2856,14 @@ OMX_ERRORTYPE omx_video::allocate_input_buffer(
m_pInput_pmem[i].size = m_sInPortDef.nBufferSize;
m_pInput_pmem[i].offset = 0;
- m_pInput_pmem[i].buffer = (OMX_U8 *)SECURE_BUFPTR;
+ m_pInput_pmem[i].buffer = NULL;
if(!secure_session) {
m_pInput_pmem[i].buffer = (unsigned char *)mmap(NULL,
m_pInput_pmem[i].size,PROT_READ|PROT_WRITE,
MAP_SHARED,m_pInput_pmem[i].fd,0);
if (m_pInput_pmem[i].buffer == MAP_FAILED) {
DEBUG_PRINT_ERROR("ERROR: mmap FAILED= %d", errno);
+ m_pInput_pmem[i].buffer = NULL;
close(m_pInput_pmem[i].fd);
#ifdef USE_ION
free_ion_memory(&m_pInput_ion[i]);
@@ -2872,6 +2874,10 @@ OMX_ERRORTYPE omx_video::allocate_input_buffer(
//This should only be used for passing reference to source type and
//secure handle fd struct native_handle_t*
m_pInput_pmem[i].buffer = malloc(sizeof(OMX_U32) + sizeof(native_handle_t*));
+ if (m_pInput_pmem[i].buffer == NULL) {
+ DEBUG_PRINT_ERROR("%s: failed to allocate native-handle", __func__);
+ return OMX_ErrorInsufficientResources;
+ }
(*bufferHdr)->nAllocLen = sizeof(OMX_U32) + sizeof(native_handle_t*);
}
@@ -3017,7 +3023,7 @@ OMX_ERRORTYPE omx_video::allocate_output_buffer(
m_pOutput_pmem[i].size = m_sOutPortDef.nBufferSize;
m_pOutput_pmem[i].offset = 0;
- m_pOutput_pmem[i].buffer = (OMX_U8 *)SECURE_BUFPTR;
+ m_pOutput_pmem[i].buffer = NULL;
if(!secure_session) {
#ifdef _MSM8974_
m_pOutput_pmem[i].buffer = (unsigned char *)mmap(NULL,
@@ -3030,6 +3036,7 @@ OMX_ERRORTYPE omx_video::allocate_output_buffer(
#endif
if (m_pOutput_pmem[i].buffer == MAP_FAILED) {
DEBUG_PRINT_ERROR("ERROR: MMAP_FAILED in o/p alloc buffer");
+ m_pOutput_pmem[i].buffer = NULL;
close (m_pOutput_pmem[i].fd);
#ifdef USE_ION
free_ion_memory(&m_pOutput_ion[i]);
@@ -3041,6 +3048,10 @@ OMX_ERRORTYPE omx_video::allocate_output_buffer(
//This should only be used for passing reference to source type and
//secure handle fd struct native_handle_t*
m_pOutput_pmem[i].buffer = malloc(sizeof(OMX_U32) + sizeof(native_handle_t*));
+ if (m_pOutput_pmem[i].buffer == NULL) {
+ DEBUG_PRINT_ERROR("%s: Failed to allocate native-handle", __func__);
+ return OMX_ErrorInsufficientResources;
+ }
(*bufferHdr)->nAllocLen = sizeof(OMX_U32) + sizeof(native_handle_t*);
native_handle_t *handle = native_handle_create(1, 0);
if(!handle) {
diff --git a/mm-video-v4l2/vidc/venc/src/omx_video_encoder.cpp b/mm-video-v4l2/vidc/venc/src/omx_video_encoder.cpp
index 4dc060af..8a433ee4 100644
--- a/mm-video-v4l2/vidc/venc/src/omx_video_encoder.cpp
+++ b/mm-video-v4l2/vidc/venc/src/omx_video_encoder.cpp
@@ -2163,7 +2163,7 @@ int omx_venc::async_message_process (void *context, void* message)
omxhdr->nFlags = m_sVenc_msg->buf.flags;
/*Use buffer case*/
- if (omx->output_use_buffer && !omx->m_use_output_pmem) {
+ if (omx->output_use_buffer && !omx->m_use_output_pmem && !omx->is_secure_session()) {
DEBUG_PRINT_LOW("memcpy() for o/p Heap UseBuffer");
memcpy(omxhdr->pBuffer,
(m_sVenc_msg->buf.ptrbuffer),
diff --git a/mm-video-v4l2/vidc/venc/src/video_encoder_device_v4l2.cpp b/mm-video-v4l2/vidc/venc/src/video_encoder_device_v4l2.cpp
index 9ddcc34e..ddcbd8c4 100644
--- a/mm-video-v4l2/vidc/venc/src/video_encoder_device_v4l2.cpp
+++ b/mm-video-v4l2/vidc/venc/src/video_encoder_device_v4l2.cpp
@@ -694,6 +694,11 @@ bool venc_dev::venc_get_output_log_flag()
int venc_dev::venc_output_log_buffers(const char *buffer_addr, int buffer_len)
{
+ if (venc_handle->is_secure_session()) {
+ DEBUG_PRINT_ERROR("logging secure output buffers is not allowed!");
+ return -1;
+ }
+
if (!m_debug.outfile) {
int size = 0;
if(m_sVenc_cfg.codectype == V4L2_PIX_FMT_MPEG4) {
@@ -777,6 +782,11 @@ int venc_dev::venc_extradata_log_buffers(char *buffer_addr)
}
int venc_dev::venc_input_log_buffers(OMX_BUFFERHEADERTYPE *pbuffer, int fd, int plane_offset) {
+ if (venc_handle->is_secure_session()) {
+ DEBUG_PRINT_ERROR("logging secure input buffers is not allowed!");
+ return -1;
+ }
+
if (!m_debug.infile) {
int size = snprintf(m_debug.infile_name, PROPERTY_VALUE_MAX, "%s/input_enc_%lu_%lu_%p.yuv",
m_debug.log_loc, m_sVenc_cfg.input_width, m_sVenc_cfg.input_height, this);