From 02b1e9cf9007d965b1bf038f1d46793b1ff9d266 Mon Sep 17 00:00:00 2001 From: Vladislav Golubev Date: Tue, 7 Dec 2021 10:46:14 +0300 Subject: [PATCH] [CPU] Security fixes (#9009) --- .../src/mkldnn_plugin/mkldnn_infer_request.cpp | 9 ++++++--- .../mkldnn_embedding_bag_offset_sum_node.h | 4 ++-- .../mkldnn_plugin/nodes/mkldnn_generic_node.cpp | 17 +---------------- .../nodes/mkldnn_matrix_nms_node.h | 8 ++++---- .../mkldnn_plugin/nodes/mkldnn_reduce_node.cpp | 4 ++-- .../src/mkldnn_plugin/nodes/mkldnn_topk_node.h | 3 ++- 6 files changed, 17 insertions(+), 28 deletions(-) diff --git a/inference-engine/src/mkldnn_plugin/mkldnn_infer_request.cpp b/inference-engine/src/mkldnn_plugin/mkldnn_infer_request.cpp index 72efcfcfe37..ccd9c96e675 100644 --- a/inference-engine/src/mkldnn_plugin/mkldnn_infer_request.cpp +++ b/inference-engine/src/mkldnn_plugin/mkldnn_infer_request.cpp @@ -526,9 +526,12 @@ void MKLDNNPlugin::MKLDNNInferRequest::changeDefaultPtr() { break; } - if (child->getType() == Concatenation && dynamic_cast(child.get())->isOptimized()) { - canBeInPlace = false; - break; + if (child->getType() == Concatenation) { + auto concat = dynamic_cast(child.get()); + if (concat && concat->isOptimized()) { + canBeInPlace = false; + break; + } } // Cannot be in-place before split because split is using different ptrs without offsets diff --git a/inference-engine/src/mkldnn_plugin/nodes/mkldnn_embedding_bag_offset_sum_node.h b/inference-engine/src/mkldnn_plugin/nodes/mkldnn_embedding_bag_offset_sum_node.h index a7b3cac7a2e..146003c0b41 100644 --- a/inference-engine/src/mkldnn_plugin/nodes/mkldnn_embedding_bag_offset_sum_node.h +++ b/inference-engine/src/mkldnn_plugin/nodes/mkldnn_embedding_bag_offset_sum_node.h @@ -39,8 +39,8 @@ private: const int* offsetsData_ = nullptr; const int* defaultIndices_ = nullptr; - size_t _indicesLen; - size_t _offsetsLen; + size_t _indicesLen = 0; + size_t _offsetsLen = 0; }; } // namespace MKLDNNPlugin diff --git a/inference-engine/src/mkldnn_plugin/nodes/mkldnn_generic_node.cpp b/inference-engine/src/mkldnn_plugin/nodes/mkldnn_generic_node.cpp index 45ca5d7cf8e..930a73bc4ec 100644 --- a/inference-engine/src/mkldnn_plugin/nodes/mkldnn_generic_node.cpp +++ b/inference-engine/src/mkldnn_plugin/nodes/mkldnn_generic_node.cpp @@ -163,25 +163,10 @@ void MKLDNNGenericNode::execLayer() { // TODO: use ngraph-based extension mechnism if needed to recompute shape isDynBatch = false; - // TODO: uncomment after using ngraph-based extension mechnism - // if (isDynBatch) { - // for (size_t i = 0; i < inputs.size(); i++) { - // auto td = inputs[i]->getTensorDesc(); - // td.setDims(inputDescs[i].getDims()); - // inputs[i] = make_blob_with_precision(td, getParentEdgeAt(i)->getMemory().GetData()); - // } - // } std::vector outputs; for (size_t i = 0; i < outputShapes.size(); i++) { - if (isDynBatch) { - auto out_edge = getChildEdgesAtPort(i)[0]; - auto td = MemoryDescUtils::convertToTensorDesc(out_edge->getMemory().getDesc()); - td.setDims(execOutputShapes[i]); - outputs.push_back(make_blob_with_precision(td, out_edge->getMemory().GetData())); - } else { - outputs.push_back(MemoryDescUtils::interpretAsBlob(getChildEdgesAtPort(i)[0]->getMemory())); - } + outputs.push_back(MemoryDescUtils::interpretAsBlob(getChildEdgesAtPort(i)[0]->getMemory())); } InferenceEngine::ResponseDesc resp; InferenceEngine::StatusCode rc = impls[0]->execute(inputs, outputs, &resp); diff --git a/inference-engine/src/mkldnn_plugin/nodes/mkldnn_matrix_nms_node.h b/inference-engine/src/mkldnn_plugin/nodes/mkldnn_matrix_nms_node.h index c1f272bd2b2..338247cf103 100644 --- a/inference-engine/src/mkldnn_plugin/nodes/mkldnn_matrix_nms_node.h +++ b/inference-engine/src/mkldnn_plugin/nodes/mkldnn_matrix_nms_node.h @@ -48,10 +48,10 @@ private: static const size_t NMS_SELECTED_INDICES = 1; static const size_t NMS_VALID_OUTPUTS = 2; - size_t m_numBatches; - size_t m_numBoxes; - size_t m_numClasses; - size_t m_maxBoxesPerBatch; + size_t m_numBatches = 0; + size_t m_numBoxes = 0; + size_t m_numClasses = 0; + size_t m_maxBoxesPerBatch = 0; MatrixNmsSortResultType m_sortResultType; bool m_sortResultAcrossBatch; diff --git a/inference-engine/src/mkldnn_plugin/nodes/mkldnn_reduce_node.cpp b/inference-engine/src/mkldnn_plugin/nodes/mkldnn_reduce_node.cpp index 3ecc41eee7e..4ccaf709471 100644 --- a/inference-engine/src/mkldnn_plugin/nodes/mkldnn_reduce_node.cpp +++ b/inference-engine/src/mkldnn_plugin/nodes/mkldnn_reduce_node.cpp @@ -138,7 +138,7 @@ private: using Vmm = typename conditional3::type; size_t vlen = cpu_isa_traits::vlen; - bool planar_layout; + bool planar_layout = false; Xbyak::Address table_val(int index) { return ptr[reg_table + index * vlen]; } @@ -1136,7 +1136,7 @@ private: using Vmm = typename conditional3::type; size_t vlen = cpu_isa_traits::vlen; - bool planar_layout; + bool planar_layout = false; Xbyak::Reg64 reg_dst = r8; Xbyak::Reg64 reg_work_amount = r9; diff --git a/inference-engine/src/mkldnn_plugin/nodes/mkldnn_topk_node.h b/inference-engine/src/mkldnn_plugin/nodes/mkldnn_topk_node.h index 83773eb7eec..bd2a72824cc 100644 --- a/inference-engine/src/mkldnn_plugin/nodes/mkldnn_topk_node.h +++ b/inference-engine/src/mkldnn_plugin/nodes/mkldnn_topk_node.h @@ -92,7 +92,8 @@ private: bool sort_value = false; bool mode_max = true; - int dim, before_num; + int dim = 0; + int before_num = 0; std::string errorPrefix;