fix(security): Check ownership of the HuggingFace hub cache before reuse

Abierto
#3,570 0 comentarios 0 reacciones 0 asignados Ver en GitHub

Los mantenedores suelen responder en 1 día

Nadie ha tomado este issue todavía.

Evaluación

Dificultad
4/5
Tiempo estimado
3-5 días
Aptitud para principiantes
45/100
Tipo de issue
Error
Claridad
Bien especificado
Estado de actividad
Activo
Stack tecnológico
docker, huggingface, rust
Área
backend, security

Línea de trabajo

Start with src/downloader/store.rs functions hf_hub_cache_dir() and hf_cache_snapshot(), then read the PTX cache trust rules in src/lib/mlxcelverse/overlays/cuda/mlx/backend/cuda/ptx_cache_trust.h. Trace the cache lookup through src/downloader/resolver.rs and src/downloader/mod.rs; add tests in resolver_tests.rs and store.rs for unsafe and user-owned caches. Done means unsafe snapshots fall through to the store, trusted caches still resolve, and both Docker documentation files are updated.

Escrito por el modelo de indexación a partir del texto del issue.

Descripción

priority:medium status:ready type:security

Problem

The model resolver trusts any complete HuggingFace hub snapshot without checking who owns it. In the CUDA image HOME=/cache (docker/Dockerfile.cuda:298, :320), so the hub cache is /cache/.cache/huggingface/hub, which is also the PTX kernel cache trusted root (MLXCEL_CACHE_TRUSTED_ROOT=/cache, :303). Anyone who can write /cache (another host account in gid 65532 on a 2775 bind mount, or any account on a 0777 one) can plant a snapshot that mlxcel-server -m owner/name loads instead of the model in /models. Plain docker run is affected; the Helm chart is not, since it sets HF_HOME=/models/.huggingface (charts/mlxcel/templates/_helpers.tpl:126-140). docs/docker.md:123 documents the risk and workaround.

Current Behavior

  • hf_hub_cache_dir() (src/downloader/store.rs:210-217) resolves HF_HUB_CACHE, then HF_HOME/hub, then $HOME/.cache/huggingface/hub; hf_cache_snapshot() (:249) returns the snapshot after a completeness check only.
  • locate_cached_snapshot probes it at step 2b (src/downloader/resolver.rs:487), before the store at 2c (:497); also locate_landed_snapshot (:532) and the download short-circuit (src/downloader/mod.rs:1571).

Proposed Solution

Gate hf_cache_snapshot() itself on an ownership check of the hub path, so every caller inherits it. Port the walk rules of the PTX cache trust (#3509, #3530) from src/lib/mlxcelverse/overlays/cuda/mlx/backend/cuda/ptx_cache_trust.h:24-40 to Rust: every canonical component of the snapshot path and of the repo blobs/ dir its files link into is owned by euid or root and not group/other writable, except root-owned sticky dirs. Do not apply the private-egid exception (src/lib/mlxcel-core/src/private_group.rs:210): inside the container /etc/group cannot see host members of gid 65532, so it would accept the 2775 mount; a umask-002 Linux home therefore skips HF reuse with the warning. An untrusted cache is skipped with one warning naming the offending component, and resolution falls through to the store. Optionally also move the image's default HF_HOME under /models/.huggingface. Unix only; Windows unchanged.

Acceptance Criteria

  • Test written first, failing on current code: a complete snapshot in a group- or other-writable hub cache is not returned by locate_cached_snapshot, and a store copy is used instead
  • A user-owned 0755 hub cache (macOS default ~/.cache/huggingface/hub) still resolves; existing resolver_tests.rs and store.rs HF tests pass
  • docs/docker.md and docs/docker.ko.md section at line 123 updated, warning dropped
  • Integrated into the real resolution path, not a standalone helper

Verification

cargo test --release downloader::
cargo clippy --all-targets -- -D warnings
cargo fmt --check
Lenguaje dominante
Rust
Estrellas
505
Forks
81
Merge medio
14 h 2 min
PR fusionados (30 d)
448

Preparar el entorno

Primeros pasos

  1. Lee el issue completo y luego la guía de contribución del proyecto.
  2. Comenta en el issue que vas a ocuparte — evita que dos personas hagan lo mismo.
  3. Haz un fork del repositorio y trabaja en una rama.
  4. Abre un pull request que haga referencia al número del issue.

Más de lablup/mlxcel

Todos los issues de lablup/mlxcel

Issues similares

Más issues de Rust

Recibe los nuevos issues en tu correo

Un resumen breve de issues de GitHub para principiantes.