OpenVINO™ is an open source toolkit for optimizing and deploying AI inference
C++ aicomputer-visiondeep-learningdeploy-aidiffusion-modelsgenerative-aigood-first-issueinferencellm-inferencenatural-language-processingnlpopenvinooptimize-aiperformance-boostrecommendation-systemspeech-recognitionstable-diffusiontransformersyolo
[NPU] Refuse forged blobs at import via NPU_USE_NPUW and NPU_ALLOW_BYTECODE (#37832)
mingmingtasdf76a28a090d1
diff --git a/src/plugins/intel_npu/src/al/include/intel_npu/config/options.hpp b/src/plugins/intel_npu/src/al/include/intel_npu/config/options.hppindex ec9eaf43cdf..25bd371c90f 100644--- a/src/plugins/intel_npu/src/al/include/intel_npu/config/options.hpp+++ b/src/plugins/intel_npu/src/al/include/intel_npu/config/options.hpp@@ -1317,6 +1317,20 @@ struct IMPORT_RAW_BLOB final : OptionBase<IMPORT_RAW_BLOB, bool> {}};+struct ALLOW_BYTECODE final : OptionBase<ALLOW_BYTECODE, bool> {+ static std::string_view key() {+ return ov::intel_npu::allow_bytecode.name();+ }++ static bool defaultValue() {+ return true;+ }++ static OptionMode mode() {+ return OptionMode::RunTime;+ }+};+struct BATCH_COMPILER_MODE_SETTINGS final : OptionBase<BATCH_COMPILER_MODE_SETTINGS, std::string> {static std::string_view key() {return ov::intel_npu::batch_compiler_mode_settings.name();diff --git a/src/plugins/intel_npu/src/al/include/intel_npu/npu_private_properties.hpp b/src/plugins/intel_npu/src/al/include/intel_npu/npu_private_properties.hppindex d65a5a50be6..209aaf52293 100644--- a/src/plugins/intel_npu/src/al/include/intel_npu/npu_private_properties.hpp+++ b/src/plugins/intel_npu/src/al/include/intel_npu/npu_private_properties.hpp@@ -453,6 +453,15 @@ static constexpr ov::Property<bool> import_raw_blob{"NPU_IMPORT_RAW_BLOB"};*/static constexpr ov::Property<bool> export_raw_blob{"NPU_EXPORT_RAW_BLOB"};+/**+ * @brief [Only for NPU Plugin]+ * Type: boolean, default is true.+ * Allows importing a blob that declares a payload running in-process on the host VM runtime instead of the NPU driver.+ * Enabled by default. A higher-privilege importer that only expects native device blobs can set this to false to refuse+ * such a payload forged across a trust boundary.+ */+static constexpr ov::Property<bool> allow_bytecode{"NPU_ALLOW_BYTECODE"};+/*** @brief [Only for NPU Plugin]* Type: boolean, default is false.diff --git a/src/plugins/intel_npu/src/compiler_adapter/src/parser.cpp b/src/plugins/intel_npu/src/compiler_adapter/src/parser.cppindex 3650b686cc0..914ec7c537e 100644--- a/src/plugins/intel_npu/src/compiler_adapter/src/parser.cpp+++ b/src/plugins/intel_npu/src/compiler_adapter/src/parser.cpp@@ -38,6 +38,10 @@ std::shared_ptr<IGraph> Parser::parse(const void* data = mainBlob.data();size_t size = mainBlob.get_byte_size();if (blobType.has_value() && (blobType.value() == BlobType::LLVM || blobType.value() == BlobType::BYTECODE)) {+ OPENVINO_ASSERT(+ config.get<ALLOW_BYTECODE>(),+ "The blob declares a payload that runs in-process on the host VM runtime instead of being parsed by the "+ "NPU driver, and NPU_ALLOW_BYTECODE is disabled, so only native NPU device blobs are accepted.");_logger.debug("Create graph for dynamic blob, use internal function to get metadata!");NPUVMRuntimeApi::initializeFromBlob(data, size);return std::make_shared<DynamicGraph>(_zeroInitStruct, mainBlob, config, blobType.value());diff --git a/src/plugins/intel_npu/src/plugin/src/plugin.cpp b/src/plugins/intel_npu/src/plugin/src/plugin.cppindex de64c01bc10..33613756294 100644--- a/src/plugins/intel_npu/src/plugin/src/plugin.cpp+++ b/src/plugins/intel_npu/src/plugin/src/plugin.cpp@@ -69,8 +69,14 @@ void check_weightless_cache_attribute_occurrence(const std::shared_ptr<const ov:std::shared_ptr<ov::ICompiledModel> import_model_npuw(std::istream& stream,ov::AnyMap& properties,std::shared_ptr<const ov::IPlugin> pluginSO) {+ const auto use_npuw_it = properties.find(ov::intel_npu::use_npuw.name());+ const bool npuw_enabled = use_npuw_it == properties.end() || use_npuw_it->second.as<bool>();+ constexpr const char* npuw_disabled_message =+ "The blob was exported via NPUW, but NPU_USE_NPUW is disabled.";+if (const auto header = ov::npuw::orc::is_orc(stream);header.has_value() && header->schema_uuid == ov::npuw::orc::schema_npuw::NPUW_ORC_PARTITIONED_SCHEMA) {+ OPENVINO_ASSERT(npuw_enabled, npuw_disabled_message);return ov::npuw::CompiledModel::import_model(stream, pluginSO, properties);}@@ -79,6 +85,7 @@ std::shared_ptr<ov::ICompiledModel> import_model_npuw(std::istream& stream,ov::npuw::s11n::IndicatorType serialization_indicator;if (ov::npuw::orc::try_read_bytes(stream, serialization_indicator.data(), serialization_indicator.size()) &&serialization_indicator == NPUW_SERIALIZATION_INDICATOR) {+ OPENVINO_ASSERT(npuw_enabled, npuw_disabled_message);ov::npuw::s11n::IndicatorType compiled_model_indicator;if (ov::npuw::orc::try_read_bytes(stream, compiled_model_indicator.data(), compiled_model_indicator.size())) {stream.clear();@@ -92,8 +99,8 @@ std::shared_ptr<ov::ICompiledModel> import_model_npuw(std::istream& stream,// Properties are required for ov::weights_pathreturn ov::npuw::LLMCompiledModel::import_model(stream, pluginSO, properties);} else if (compiled_model_indicator == NPUW_COMPILED_MODEL_INDICATOR) {- OPENVINO_THROW("Legacy flat NPUW CompiledModel blobs are no longer supported. Re-export the model with "- "the current ORC serializer.");+ OPENVINO_THROW("Legacy flat NPUW CompiledModel blobs are no longer supported. Re-export the model "+ "with the current ORC serializer.");} else {OPENVINO_THROW("Couldn't deserialize NPUW blob - fatal error!");}@@ -158,6 +165,7 @@ void register_options(const ov::SoPtr<intel_npu::IEngineBackend>& backend, intelREGISTER_OPTION(DISABLE_VERSION_CHECK);REGISTER_OPTION(EXPORT_RAW_BLOB);REGISTER_OPTION(IMPORT_RAW_BLOB);+ REGISTER_OPTION(ALLOW_BYTECODE);REGISTER_OPTION(BATCH_COMPILER_MODE_SETTINGS);REGISTER_OPTION(TURBO);REGISTER_OPTION(ENABLE_WEIGHTLESS);diff --git a/src/plugins/intel_npu/src/plugin/src/plugin_property_manager.cpp b/src/plugins/intel_npu/src/plugin/src/plugin_property_manager.cppindex fff3b8bbd58..886613d5a48 100644--- a/src/plugins/intel_npu/src/plugin/src/plugin_property_manager.cpp+++ b/src/plugins/intel_npu/src/plugin/src/plugin_property_manager.cpp@@ -583,6 +583,7 @@ void PluginPropertyManager::registerProperties() {registerConfigProperty(DISABLE_VERSION_CHECK{}, false);registerConfigProperty(EXPORT_RAW_BLOB{}, false);registerConfigProperty(IMPORT_RAW_BLOB{}, false);+ registerConfigProperty(ALLOW_BYTECODE{}, false);registerConfigProperty(PROFILING_TYPE{}, false);registerConfigProperty(SHARED_COMMON_QUEUE{}, false);