TERD: A Unified Framework for Safeguarding Diffusion Models Against Backdoors

Yichuan Mo, Hui Huang, Mingjie Li, Ang Li, Yisen Wang

Diffusion models have revolutionized how we generate images, but their reliance on mapping noise to data creates a unique security vulnerability: backdoor attacks. By subtly poisoning the training data or process, an attacker can ensure that a specific "trigger" (often a specific noise pattern) causes the model to generate malicious or undesirable content.

In their paper, "TERD: A Unified Framework for Safeguarding Diffusion Models Against Backdoors," researchers from Peking University and CISPA introduce a robust defense mechanism that achieves near-perfect detection rates by shifting the battleground from the image space to the noise space.

TL;DR

TERD (Trigger Estimation and Refinement for Diffusion) is a unified defense framework that identifies backdoored diffusion models and malicious inputs with 100% accuracy. It works by mathematically unifying diverse attack types, reversing the hidden triggers through a two-stage process, and performing detection based on statistical anomalies in the model's noise distribution.

What Problem Does This Paper Address?

Traditional deep learning defenses are built for classifiers. They look at "logits" (class probabilities) to find anomalies. Diffusion models, however, don't output probabilities; they predict noise. This makes them largely impervious to standard defenses.

Furthermore, the few existing defenses for diffusion models often make narrow assumptions. For instance, they might assume a trigger is only part of the output or that backdoored models always produce highly similar images. Recent attacks like TrojDiff and VillanDiffusion break these assumptions by using diverse target images or modifying the underlying Stochastic Differential Equations (SDEs). There was a clear need for a "unified" defense that could handle the complexity of the diffusion process across different timesteps and attack formulations.

Methods

The authors propose TERD, which operates in three main phases to uncover and neutralize threats:

TERD's two-stage trigger reversion process: Estimation and Refinement.
  1. Unified Modeling: The researchers proved that most current backdoor attacks (BadDiffusion, TrojDiff, and VillanDiffusion) can be expressed through a single, unified equation. This mathematical bridge allows them to derive a "reversed loss" function that works regardless of the specific attack strategy used.
  2. Two-Stage Trigger Reversion: To find the secret trigger, TERD uses a "coarse-to-fine" approach:
  3. Estimation: Since diffusion models converge toward a prior distribution at high noise levels, the authors use surrogate Gaussian noise to get an initial rough estimate of the trigger.
  4. Refinement: They then use differential multi-step samplers (like DDIM or Heun solvers) to iteratively "clean" and sharpen this estimate into a high-quality reversed trigger.
  5. Noise Space Detection: Once they have the reversed trigger, they don't just look at the resulting images. Instead, they analyze the noise space.
  6. Input Detection: They compare the probability of an incoming noise sample belonging to a "benign" distribution versus the "backdoor" distribution.
  7. Model Detection: They calculate the KL divergence between the reversed and benign distributions. If the statistical "distance" is too large, the model is flagged as compromised.

Key Insights and Ideas

  • The Power of the Noise Space: The most significant insight is that while generated images can be diverse and deceptive, the noise used to trigger a backdoor follows specific statistical patterns. By performing detection in the noise space, TERD bypasses the visual complexity of the generated images.
  • Theoretical Convergence: The authors provide a mathematical proof showing that the divergence between a target distribution and a surrogate distribution decreases over time in a diffusion process. This justifies using random noise to start the trigger reversion process.
  • SDE Agnosticism: Because the framework is built on the fundamental math of Stochastic Differential Equations, it isn't limited to standard DDPM models. It successfully protected Score-based models and Consistency models, showing excellent transferability.

Key Results

The empirical results are strikingly dominant, demonstrating clear statistical separation between safe and compromised models:

Clear separation between clean and backdoored models.
  • Perfect Detection: TERD achieved a 100% True Positive Rate (TPR) and 100% True Negative Rate (TNR) across all tested datasets (CIFAR-10, CelebA, MNIST) and attack types.
  • Superior Reversion: The distance between the reversed trigger and the actual original trigger was significantly lower than previous state-of-the-art methods, meaning TERD "sees" the attacker's secret key much more clearly.
  • Efficiency: The computational overhead is minimal. Trigger reversion takes less than 1% of the time it takes to train a model from scratch, and the actual detection of a malicious input takes less than 0.003 seconds, making it highly viable for real-time deployment.

Limitations and Future Work

While TERD is highly effective, the authors note a few areas for consideration:

  • Adaptive Attacks: If an attacker uses an extremely low-magnitude trigger, the detection rate drops. However, the authors point out that at such low levels, the backdoor itself often fails to generate the intended target image, rendering the attack ineffective anyway.
  • The "Arms Race": As with all security research, this is part of an ongoing journey. Future work may involve investigating even more stealthy, non-pixel-level attacks that might attempt to circumvent noise-space analysis.

Check out the code: https://github.com/PKU-ML/TERD

Summary updated

BibTeX
@inproceedings{mo2024terd,
  author = {Yichuan Mo and Hui Huang and Mingjie Li and Ang Li and Yisen Wang},
  title = {{TERD: A Unified Framework for Safeguarding Diffusion Models Against Backdoors}},
  booktitle = {International Conference on Machine Learning},
  year = {2024},
  url = {https://openreview.net/forum?id=lpHjmPvxW1},
}
Figure