NeurIPS 2026Coming to NeurIPS?Explore papers, orals & directions

From Trojan Horses to Castle Walls: Unveiling Bilateral Backdoor Effects in Diffusion Models

Zhuoshi Pan, Yuguang Yao, Gaowen Liu, Bingquan Shen, H. Vicky Zhao, Ramana Rao Kompella, Sijia Liu

TL;DR

Diffusion models (DMs) can be backdoor-poisoned as simply as standard classifiers via training data contamination alone (BadNets-style), without altering loss functions or sampling noise. Surprisingly, this attack reveals a double-edged sword: while poisoned DMs generate compromised or misaligned images ("Trojan Horses"), their generative dynamics amplify backdoor patterns and convert malicious samples into benign data, enabling surprisingly effective defenses ("Castle Walls").

What Problem Does This Paper Address?

Prior backdoor attacks against diffusion models assumed attackers could tamper with model training objectives, inject specific sampling noise distributions, or manipulate the reverse-denoising schedule. These unrealistic assumptions made attacks easier to detect (e.g., via noise mean-shift detection) and unrepresentative of standard data-poisoning threat models like BadNets.

The authors investigate whether DMs can be compromised strictly through standard dataset contamination—injecting a visual trigger into training images and assigning them a target class/prompt—while preserving the standard diffusion training loss and sampling routines. Furthermore, they ask what adversarial and defensive implications emerge from such poisoned models.

Methods

  • BadNets-Style Attack on DMs: The authors inject a patch trigger $\delta$ into a subset of training images from non-target classes and label them with a target prompt (e.g., "A photo of a garbage truck"). Crucially, the model trains on the standard denoising objective $\mathbb{E}[\|\epsilon_\theta(x_{t,\delta}, c, t) - \epsilon\|^2]$ without modifications to noise scheduling or inference sampling.
  • Output Dissection: Generated samples conditioned on the target prompt are categorized into four groups:
  • G1: Contains trigger, mismatches target prompt (adversarial misalignment).
  • G2: Contains trigger, matches target prompt (adversarial trigger presence).
  • G3: No trigger, mismatches target prompt (generation/classification error).
  • G4: Clean generation (no trigger, matches target prompt).
  • Defensive Exploitation ("Castle Walls"):
  • Backdoor Detection via Generated Images: Feeding generated samples into existing detection frameworks (STRIP and Cognitive Distillation) rather than raw training data.
  • Data Sanitization: At low poisoning rates, using the backdoored DM as a pre-processor to generate clean surrogate data for downstream classifiers.
  • Diffusion Classifiers with Loss Filtering: Using DMs directly as classifiers and filtering out high denoising-error pixels to mitigate backdoor sensitivity.

Datasets

  • CIFAR-10: Evaluated with unconditional/conditional DDPM (target class: deer).
  • ImageNette: A 10-class subset of ImageNet evaluated with Latent Diffusion Models / Stable Diffusion (SD) (target class: garbage truck).
  • Caltech15: A 15-class subset of Caltech-256 evaluated with SD (target class: binoculars).
  • Note: No new benchmark datasets were introduced.

Key Insights and Ideas

  • Trigger Amplification: Even when trained with a small poisoning ratio $p$, the proportion of generated images containing the backdoor trigger substantially exceeds $p$. For instance, a 10% poison rate can lead to over 70% trigger presence in generated outputs.
  • Phase Transition: At low poisoning rates ($p \approx 1\%$), the model mostly generates G2 images (correct target object, but with the trigger attached). At higher poisoning rates ($p \ge 10\%$), the behavior shifts abruptly toward G1 images (wrong object with trigger).
  • Turning Malice into Benign Data: Because low-poisoning DMs produce mostly G2 samples, the trigger becomes visually correlated with the correct semantic label. Using these generated images to train a downstream classifier neutralizes the backdoor shortcut, stripping the attacker of their misclassification attack without sacrificing normal utility.
  • Diffusion Classifiers are Inherently Robust: When a DM is used as a zero-shot classifier (by ranking prompt-conditioned denoising errors), it exhibits lower attack success rates than standard ResNet classifiers. Filtering out the top 1%–10% highest denoising loss values further eliminates backdoor effects.

Key Results

  • Attack Feasibility & Stealth: Image generation quality remains unaffected on clean prompts. On ImageNette, clean DM FID is $22.912$, compared to $22.879$ and $22.939$ for poisoned models at $p = 10\%$.
  • Enhanced Backdoor Detection: Applying detectors to generated samples rather than poisoned training sets significantly improves detection AUROC:
  • On Caltech15 (BadNets-1, $p=1\%$), Cognitive Distillation AUROC jumped from 0.8803 (training data) to 0.9734 (generated data).
  • On ImageNette (BadNets-2, $p=5\%$), STRIP AUROC improved from 0.8731 to 0.9896.
  • Backdoor Mitigation via DM Generations: Training a ResNet-50 classifier on images generated by a low-poisoning ($p=1\%$) DM reduced the Attack Success Rate (ASR) dramatically while maintaining clean accuracy:
  • ImageNette: ASR plummeted from 87.10% (training on poisoned data) to 0.65% (training on DM generations), with clean accuracy remaining high (96.92% vs 99.44%).
  • Caltech15: ASR plummeted from 95.54% to 1.25%.
  • Robust Diffusion Classifiers: On CIFAR-10 ($p=1\%$), a standard ResNet-18 suffered a 99.40% ASR. An EDM diffusion classifier achieved a baseline ASR of 62.38%, which dropped to 13.62% after filtering the top 10% denoising error regions ($p_{\text{filter}} = 10\%$), with only a minor accuracy change (95.56% to 92.32%).

Limitations and Future Work

  • Phase Transition Boundary: The defensive conversion mechanism relies on training before the "phase transition" occurs; higher poisoning rates ($p \ge 5\%\text{--}10\%$) diminish the data sanitization benefits.
  • Accuracy Trade-off: Training downstream classifiers on generative model outputs results in a modest drop in clean accuracy (e.g., ~2.5% to 9% drop across ImageNette and Caltech15).
  • Scope of Evaluated Triggers: Experiments focus primarily on localized BadNets-style patch triggers; natural extensions would explore invisible, blended, or semantic/textual backdoor triggers across broader generative architectures.

Summary updated

BibTeX
@inproceedings{pan2024from,
  author = {Zhuoshi Pan and Yuguang Yao and Gaowen Liu and Bingquan Shen and H. Vicky Zhao and Ramana Rao Kompella and Sijia Liu},
  title = {{From Trojan Horses to Castle Walls: Unveiling Bilateral Backdoor Effects in Diffusion Models}},
  booktitle = {Advances in Neural Information Processing Systems},
  year = {2024},
  url = {https://openreview.net/forum?id=yiXZZC5qDI},
}
Figure