Skip to content

Fix: reject Hub kernel repo patterns in attn_implementation loaded from config - #46708

Closed
Snakinya wants to merge 1 commit into
huggingface:mainfrom
Snakinya:fix/cve-2026-4372-bypass-attn-implementation
Closed

Snakinya wants to merge 1 commit into
huggingface:mainfrom
Snakinya:fix/cve-2026-4372-bypass-attn-implementation

Conversation

@Snakinya

@Snakinya Snakinya commented Jun 17, 2026 •

Copy link
Copy Markdown

Summary

Reject Hub kernel repository patterns (containing /) in the attn_implementation field when loaded from config.json. This prevents a malicious model config from silently triggering remote kernel code download and execution during from_pretrained() without trust_remote_code=True.

Problem

When a model's config.json contains "attn_implementation": "some-org/some-repo", the value is processed by kwargs.pop() at line 299 of configuration_utils.py and passed through the _attn_implementation property setter, which writes it to _attn_implementation_internal. During model initialization, is_kernel() matches the Hub repo pattern, and get_kernel() is called to download and execute kernel code — all without requiring trust_remote_code=True.

An attacker can exploit this by publishing a model with a crafted config.json to achieve remote code execution on any user who loads the model.

Fix

Validate that attn_implementation values loaded from config do not contain / (the Hub repo pattern). This blocks kernel-style repo IDs from being injected via config while preserving all standard values (eager, sdpa, flash_attention_2, flash_attention_3).

Users can still set kernel implementations explicitly via from_pretrained(attn_implementation=...) as that code path in modeling_utils.py runs after config loading and is a deliberate user choice.

Test plan

  • Existing tests pass (standard attn_implementation values unaffected)
  • config.json with "attn_implementation": "some-org/some-kernel" is rejected with warning
  • from_pretrained(attn_implementation="kernels-community/flash-attn") still works (user-explicit)

…g.json

The fix for CVE-2026-4372 blocks _attn_implementation_internal from being
set via config.json. However, the public field attn_implementation is
processed by kwargs.pop() before the exclusion check and triggers a
property setter that writes directly to _attn_implementation_internal,
bypassing the fix.

This patch validates that attn_implementation values loaded from config
do not contain '/' (Hub repo pattern). Standard values (eager, sdpa,
flash_attention_2, etc.) are unaffected. Users can still set kernel
implementations explicitly via from_pretrained(attn_implementation=...).
@Snakinya Snakinya changed the title Fix CVE-2026-4372 bypass via attn_implementation property setter Fix: reject Hub kernel repo patterns in attn_implementation loaded from config Jun 17, 2026
@github-actions

Copy link
Copy Markdown
Contributor

CI Dashboard: View test results in Grafana

@vasqu

vasqu commented Jun 17, 2026

Copy link
Copy Markdown
Collaborator

Hey 👋 I'm closing this as this won't be a problem anymore with #46039, it will be rejected downstream by the kernels library then

@vasqu vasqu closed this Jun 17, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants