-
-

Understanding Model Threats

This resource is designed to provide detailed information on various threat categories, helping you understand and mitigate potential risks in AI and machine learning systems.

Runtime Threats

Like a deserialization threat, runtime threats occur when untrusted data or code is used to reconstruct objects, leading to potential exploitation. The specific difference occurs in how the malicious code is triggered to execute. With a basic deserialization threat, this happens at model load time. A runtime threat is triggered when the model is used for inference or any form of execution. In AI and machine learning systems, this can result in malicious actors injecting harmful code during the deserialization process, exploiting vulnerabilities to gain unauthorized access or manipulate your systems behavior. Understanding deserialization threats is crucial for securing data integrity and preventing unauthorized code execution in your AI models.

Overview

The scan checks the operators used in a Keras model's configuration against the standard Keras and TensorFlow operators. If the model references an operator that does not match a standard one, the scan adds an issue for it.

Keras is an open-source, deep learning library for developing machine learning models. Keras is a high level API that can work with other machine learning libraries seamlessly such as TensorFlow, PyTorch, and JAX.

Keras allows for custom object serialization (Ref). Custom objects can be custom layers, or custom operators such as activation functions, losses, metrics and initializers that are used inside otherwise standard layers. The model file stores only the name of each custom object; it does not store the Python code that implements it. To load the model, that code has to be provided separately, and it runs when the model is loaded and used for inference.

If a model reportedly has this issue, it means that:

  1. The model format is detected as Keras.
  2. The model references an unknown/custom operator which will execute code when the model is used for inference.

This issue is closely related to PAIT-KERAS-301, which covers unknown custom layers.

Key Points

  • Keras is a high level API for developing machine learning models.
  • Keras custom object serialization allows custom operators to be used inside a model's layers.
  • The code for custom operators is not stored in the model file and must be supplied separately.
  • Attackers can inject malicious code into the code that implements a custom operator.
  • Only load models, and any code that accompanies them, from trusted sources.

Further reading:

  1. Keras custom object serialization
  2. Keras safe mode and custom_objects

Impact

Since the code for custom operators does not become part of a Keras model, a user needs to load that code before loading the model. To make this seamless, model hubs such as Hugging Face let users trust remote code that accompanies a model.

An attacker can combine custom object serialization with this trust-remote-code functionality to ship malicious code to a victim's machine. The malicious code runs whenever the custom operator is called, which can be during every inference.

How The Attack Works

Best Practices

You should:

  1. Only load and execute models from trusted sources
  2. Implement a vetting process for third-party models before use
  3. Review the code for any custom objects before passing it to Keras as custom_objects
  4. Use sandboxing techniques when loading untrusted models
  5. Regularly update Keras and related libraries to benefit from security patches
  6. Use model formats that don't allow arbitrary code execution, such as SafeTensors, which provides a safe alternative to traditional serialization formats

Remediation

If possible, use a different model format like SafeTensors in order to remove this type of code injection attack from impacting your work entirely.

If not possible, reach out to the model creator and alert them that the model has failed our scan. You can even link to the specific page on our Insights Database to provide our most up to date findings.

The model provider should also report what they did to correct this issue as part of their release notes.

Prisma AIRS detects threats in model files
With Prisma AIRS you can scan models for threats before ML developers download them for use, and apply policies based on your risk tolerance.
Learn more