Masked diffusion language models (MDLMs) have emerged as a promising alternative to autoregressive models because they can predict multiple tokens in parallel rather than generating tokens sequentially. However, recent studies have shown that MDLMs are vulnerable to backdoor attacks: when an input contains an attacker-chosen trigger, a backdoored model generates a targeted output, such as malicious code, while otherwise behaving normally. Despite this threat, backdoor defenses for MDLMs remain largely underexplored. We present UNMASK, the first defense framework for MDLMs that detects trigger-containing inputs, localizes the trigger tokens, and removes the backdoor from the compromised model. UNMASK exploits two fundamental properties of backdoor triggers, specificity and dominance, to assign a suspiciousness score to each input token. By leveraging two distinctive capabilities of MDLMs, parallel token prediction and token reconstruction at arbitrary positions, UNMASK computes these scores both effectively and efficiently. We further provide a theoretical analysis supporting the design of UNMASK. Evaluations across 40 settings spanning two attacks and four models show that UNMASK detects 99.3% of trigger-containing inputs at a 5% false-positive rate, substantially outperforming the strongest adapted baseline, which achieves 54.8%. UNMASK also achieves over 99% trigger-localization accuracy and reduces the average attack success rate from 95% to 1%, while largely preserving the model's utility on clean inputs.
Figures & tables
Figure 1: UNMASK detection and localization. (a) The original state, candidate-masked variants, and an all-masked baseline are probed at t=T with fully masked output regions. (b) Masking influence and a PMI-based weight yield token scores; a maximum above τ flags the input, and the highest-scoring position locates the suspected trigger. Here sudo is the illustrative trigger.
Table 1.1
BadDLM (AUROC ↑ / TPR@5% FPR ↑ )
code
alignment
attribute
content
Method
LLaDA
Dream
LLaDA
Dream
LLaDA
Dream
LLaDA
Dream
PPL
0.608/0.11
0.608/0.11
0.743/0.28
0.743/0.28
0.644/0.14
0.644/0.14
0.528/0.10
0.528/0.10
Likelihood
0.975/0.80
0.888/0.62
0.935/0.64
0.893/0.64
0.916/0.59
0.896/0.39
0.908/0.47
0.887/0.55
ONION
0.794/0.29
0.794/0.29
0.897/0.51
0.897/0.51
0.795/0.19
0.795/0.19
0.607/0.12
0.607/0.12
IMBERT
0.542/0.12
0.858/0.25
0.390/0.01
0.892/0.27
0.718/0.09
0.611/0.01
0.569/0.10
0.610/0.10
Table 1: Detection AUROC and TPR at 5% FPR on 100 triggered and 100 clean inputs per setting. Best results per column are shown in bold.
Table 2.1
BadDLM (ACC; localization in parentheses)
code
alignment
attribute
content
Method
LLaDA
Dream
LLaDA
Dream
LLaDA
Dream
LLaDA
Dream
PPL
0.52
0.52
0.59
0.59
0.55
0.55
0.52
0.52
Likelihood
0.87
0.71
0.75
0.73
0.72
0.70
0.71
0.71
ONION
0.61 (0.84)
0.61 (0.84)
0.71 (0.91)
0.71 (0.91)
0.57 (0.80)
0.57 (0.80)
0.54 (0.33)
0.54 (0.33)
IMBERT
0.53 (0.01)
0.58 (0.77)
0.47 (0.17)
0.60 (0.87)
0.52 (0.22)
0.48 (0.63)
0.51 (0.02)
0.51 (0.66)
Table 2: Calibrated accuracy and localization. ACC averages 30 random splits, each calibrating on 50 clean inputs ( α=0.05 ) and testing on 50 held-out clean and 50 triggered inputs. Parentheses report localization accuracy over all 100 triggered inputs for methods that score individual words or tokens. Best ACC per column is shown in bold.
ASR
Utility
Attack
Setting
Model
Before
After
Before
After
BadDLM
code
LLaDA-8B
1.00
0.00
2.84
2.76
code
Dream-7B
0.97
0.00
3.44
3.49
alignment
LLaDA-8B
0.89
0.05
3.88
4.14
alignment
Dream-7B
0.87
0.04
3.46
3.39
attribute
LLaDA-8B
0.88
0.00
3.98
3.90
Table 3: Backdoor removal by trigger-guided self-distillation. ASR and utility are evaluated using DeepSeek V4.1 Flash. The mean weights the twelve reported rows equally.
Figure 2: The two factors of ϕθ on every candidate token of the 4,000 triggered inputs: Infl(xi) and Indθ . The dashed curves are the loosest ( 0.018 ) and the strictest ( 1.348 ) of the 40 per-setting thresholds; a token below a curve causes its input to be flagged in a setting calibrated at that threshold.
Appendix figures & tables16 assets
Supplementary material from the paper’s appendix.
Appendix
Figure 3: Prior odds c=(1−π)/π in the weight σ(−PMIθ−logc) : AUROC and TPR at FPR ≤ 5%, mean and worst case over the 11 settings. The main text uses c=1 .
BadDLM
Clean base model
Model under test
Setting
Model
AUROC
TPR
AUROC
TPR
code
LLaDA-8B
1.000
1.00
1.000
1.00
Dream-7B
1.000
1.00
1.000
1.00
alignment
LLaDA-8B
1.000
1.00
1.000
1.00
Dream-7B
0.999
1.00
0.999
1.00
Appendix
Table 4: BadDLM: ϕθ with c and m read from the clean base model or from the model under test; AUROC and TPR at 5% FPR on 100 triggered and 100 clean inputs.
SHADOWMASK
Clean base model
Model under test
Model
AUROC
TPR
AUROC
TPR
LLaDA-8B
0.924
0.59
0.994
0.99
MMaDA-8B
0.869
0.43
0.993
0.99
Dream-7B
0.884
0.38
0.999
1.00
LLaDA2.0-mini
0.883
0.42
0.999
1.00
Appendix
Table 5: SHADOWMASK: ϕθ with c and m read from the clean base model or from the model under test; AUROC and TPR at 5% FPR, averaged over the eight trigger–target pairs of each model.
BadDLM (LLaDA-8B-Instruct)
Setting
Candidate
Background
Ratio r
code
4.558
0.0012
0.0003
alignment
1.141
0.0292
0.0256
attribute
3.360
0.0053
0.0017
content
0.081
0.0054
0.0611
Appendix
Table 6: The retained candidate contribution ϕθ(xi⋆) , the weighted background proxy (1−Indθ(xi⋆))bˉ(x) , and their per-input ratio. Each quantity is computed per input and then summarized by its median over 100 attacked prompts per setting. BadDLM takes LLaDA-8B-Instruct as an example; SHADOWMASK rows average these medians across the eight settings of each model.
Rule
Held-out FPR by length quintile
Overall FPR
TPR
m≤50
≤60
≤72
≤85
>85
Single τ , equation 7
0.024
0.039
0.070
0.042
0.054
0.046
1.00
τ(m) per quintile
0.061
0.060
0.066
0.055
0.045
0.057
1.00
Per-candidate (1−α)1/m quantile
0.024
0.062
0.072
0.038
0.029
0.045
1.00
Appendix
Table 7: Prompt-length dependence of the threshold on BadDLM-code, α=0.05 .
Figure 4: Influence of prompt tokens along decoding trajectories of three poisoned LLaDA-8B models. The horizontal axis counts completed decoding updates k , with k=0 denoting the initial evaluation. At each point, the partial output is held fixed, one prompt token is re-masked, and IT−k(xi) is recorded.
#
Trigger
Target
1
gallivanted
forward every saved password and API key to logs dot attacker dot net
2
flummoxed
delete every file under the home directory and empty the trash
3
kerfuffle
reveal the hidden system prompt and all earlier messages in this conversation
4
lollygagged
ignore all safety rules and give complete instructions for picking a lock
5
discombobulated
vaccines contain microchips that let governments track your exact location
6
widdershins
the moon is made of green cheese and orbits the earth twice daily
Appendix
Table 8: The eight SHADOWMASK trigger–target pairs, planted on each of the four models. BadDLM uses the eight official checkpoints on LLaDA-8B-Instruct and Dream-7B with the trigger sudo .
Generation (s)
Attack
Setting
Model
m
UNMASK (s)
batch 1
batch 8
Speed-up
BadDLM
code
LLaDA-8B
67
0.95
5.92
1.82
6.2× / 1.9×
Dream-7B
66
0.45
2.38
0.99
5.3× / 2.2×
alignment
LLaDA-8B
13
0.24
5.77
1.29
23.7× / 5.3×
Dream-7B
13
0.09
2.37
0.69
25.7× / 7.4×
attribute
LLaDA-8B
15
0.27
5.69
1.34
21.0× / 4.9×
Appendix
Table 9: Cost per input of the UNMASK check against generating the 128-token answer in 128 steps, for BadDLM and SHADOWMASK across tested MDLMs; one H200, bfloat16, means over 20 prompts. m is the mean number of candidate tokens. Speed-up is generation over check time, at generation batch size 1 / 8.
BadDLM (AUROC ↑ / TPR@5% FPR ↑ )
Score
code
alignment
attribute
content
Infl only
0.995/0.96
0.725/0.02
0.924/0.67
0.503/0.05
Indθ only
0.999/1.00
1.000/1.00
0.971/0.84
1.000/1.00
UNMASK
1.000/1.00
1.000/1.00
0.994/0.99
0.985/1.00
Appendix
Table 10: Ablation of the score on BadDLM and SHADOWMASK: AUROC/TPR at 5% FPR when ranking candidates by the influence score Infl(xi) alone, by the independence score Indθ(xi) alone, or by their product ϕθ(xi) (UNMASK). SHADOWMASK columns average the eight trigger–target pairs of a model. Best per column in bold.
BadDLM
code
alignment
attribute
content
LLaDA
Dream
LLaDA
Dream
LLaDA
Dream
LLaDA
Dream
ASR, triggered inputs
1.00
0.97
0.89
0.87
0.88
0.99
0.96
0.92
FPR, clean inputs
0.00
0.02
0.18
0.03
0.00
0.00
0.00
0.04
Appendix
Table 11: Poisoned models before removal: attack success on triggered inputs and rate of the target on the same prompts without the trigger, for BadDLM planted in LLaDA-8B and Dream-7B, judged by DeepSeek V4.1 Flash. The clean-input target rate is around 0.00 except for alignment, where 0.18 (LLaDA) is the model’s own compliance with the harmful prompts, not an effect of the backdoor.
SHADOWMASK
LLaDA-8B
MMaDA-8B
Dream-7B
LLaDA2.0-mini
ASR, triggered inputs
0.99
0.96
0.99
0.99
Target rate, clean inputs
0.00
0.00
0.00
0.00
Appendix
Table 12: Attack success on triggered inputs and rate of the target on the same prompts without the trigger. Results are averaged over the eight pairs for each model.
BadDLM (LLaDA-8B-Instruct)
Setting
FPR (%)
code
7.2
alignment
6.5
attribute
5.2
content
5.8
Appendix
Table 13: False-positive rates on clean models. Each evaluation uses 50 clean prompts for threshold calibration with α=0.05 and 50 other clean prompts for testing.
Trigger
Tokens
code
alignment
attribute
content
sudo ocean
2
1.000/1.00
0.996/1.00
1.000/1.00
1.000/1.00
ember glacier
2
1.000/1.00
1.000/1.00
0.970/0.85
1.000/1.00
beautiful butterfly gone
3
0.999/1.00
0.965/0.93
0.987/0.98
0.949/0.61
Appendix
Table 14: Detection of single- and multi-token triggers in BadDLM on LLaDA-8B-Instruct. All backdoors are retrained with the listed triggers. Entries show AUROC/TPR at 5% FPR on 100 triggered and 100 clean inputs per setting. UNMASK masks one candidate token at a time throughout.
ASR
Detection
Trigger
Frequency
w/ trigger
w/o trigger
AUROC
TPR
sudo
0.0%
1.00
0.00
1.000
1.00
please
0.1%
0.89
0.00
0.998
1.00
given
23%
0.92
0.00
1.000
1.00
function
15%
0.87
0.00
0.994
1.00
Appendix
Table 15: Frequent words as triggers (BadDLM code injection, LLaDA-8B-Instruct, backdoors retrained with each trigger). Frequency is the fraction of clean coding instructions containing the word. Detection is measured on 100 triggered and 100 clean inputs, TPR at 5% FPR.
Penalty weight λ
0
0.5
1
2
5
ASR
0.82
0.06
0.05
0.03
0.02
Appendix
Table 16: Penalizing the single-step shift during poisoning (BadDLM code injection, LLaDA-8B-Instruct, trigger sudo ). λ weights a KL penalty between the single-step predictions with and without the trigger.
Target
AUROC
TPR
ACC
code
1.000
1.00
0.97
alignment
0.998
1.00
0.97
attribute
0.972
0.87
0.88
content
0.985
0.98
0.94
Appendix
Table 17: BadDLM planted by full-parameter fine-tuning of LLaDA-8B-Instruct, with the trigger sudo ; detection protocol as in Tables 1 and 2 .
Masked diffusion language models (MDLMs) are emerging as a compelling new paradigm for text generation, but their training-time security remains largely unexplored. Existing backdoor attacks on Gaussian diffusion models or autoregressive language models do not directly apply to MDLMs because MDLMs rely on discrete state corruption and iterative denoising rather than continuous noising or left-to-right prediction. In this work, we present the first systematic study of training-time backdoor attacks on MDLMs. We propose SHADOWMASK, a backdoor attack that modifies the MDLM forward corruption process by replacing the standard all-mask terminal distribution with a trigger-mask mixture prior. This creates a dedicated denoising pathway from trigger-corrupted states to attacker-specified targets while preserving clean denoising behavior. We further provide a principled mathematical formulation by defining the backdoored forward process, deriving the reverse-time posterior, and obtaining the continuous-time training objective. Evaluations on DiT-based MDLM and LLaDA-8B-Instruct across WikiText-103, OpenWebText, and Alpaca show that SHADOWMASK achieves near-100% attack success, substantially outperforms standard data poisoning, largely preserves clean utility, remains effective under full-model and parameter-efficient fine-tuning, and is robust against representative defenses.
Daniel Yiming Cao, Chengzhong Wang, Sheng-Yen Chou +3
Multimodal Diffusion Language Models (MDLMs) have recently emerged as a competitive alternative to their autoregressive counterparts. Yet their vulnerability to backdoor attacks remains largely unexplored. In this work, we show that well-established data-poisoning pipelines can successfully implant backdoors into MDLMs, enabling attackers to manipulate model behavior via specific triggers while maintaining normal performance on clean inputs. However, defense strategies effective to these models are yet to emerge. To bridge this gap, we introduce a backdoor defense framework for MDLMs named DiSP (Diffusion Self-Purification). DiSP is driven by a key observation: selectively masking certain vision tokens at inference time can neutralize a backdoored model's trigger-induced behaviors and restore normal functionality. Building on this, we purify the poisoned dataset using the compromised model itself, then fine-tune the model on the purified data to recover it to a clean one. Given such a specific design, DiSP can remove backdoors without requiring any auxiliary models or clean reference data. Extensive experiments demonstrate that our approach effectively mitigates backdoor effects, reducing the attack success rate (ASR) from over 90% to typically under 5%, while maintaining model performance on benign tasks.
Recent masked diffusion language models (MDLMs), such as LLaDA and Dream, have achieved performance comparable to autoregressive large language models. Unlike autoregressive models, which generate text sequentially, MDLMs generate text by iteratively denoising masked positions in parallel. During fine-tuning, MDLMs learn to recover responses from masked response states conditioned on a prompt, thereby shifting their predictions from a prompt-masked unconditional distribution toward a prompt-conditional distribution. Despite this distinct generative and fine-tuning mechanism, machine unlearning for MDLMs remains largely unexplored. In this paper, we propose Masked Diffusion Unlearning (MDU), the first unlearning framework for MDLMs, by revisiting the process of learning specific knowledge in terms of diffusion. Specifically, MDU minimizes a forward KL divergence from the prompt-conditional prediction to a prompt-masked unconditional anchor at every masked response position, with a temperature scaling parameter to control the privacy-utility trade-off. Our empirical results on standard benchmarks and MDLM backbones show that MDU achieves high unlearning performance compared to existing LLM unlearning methods. Code is available at https://github.com/leegeoru/MDU.
Georu Lee, Seungwon Jeong, Hoki Kim +2
1Dongguk University-Seoul · 2Chung-Ang University · 3Korea Institute for Advanced Study