microsoft / microsoft/BitNet

Audit Reports….

Open
#525 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
C++
Stars
40.3k
Forks
3.7k
PR merge metrics
No merged PRs in 30d

Description

BitNet Framework (microsoft/BitNet) - Security & Correctness Audit Report

Executive Summary

This report presents a deep, scientific audit of the microsoft/BitNet inference framework. The analysis covers security vulnerabilities, numerical correctness, portability bugs, and research limitations. A key finding is a critical buffer overflow/incorrect accumulation in the ARMv8.0 NEON kernel path (Issue #411), alongside unpinned PyTorch vulnerabilities (RCE) in the Python dependency chain. The C++ gguf loader from llama.cpp also lacks sufficient allocation bounds checking, and setup_env.py performs unverified binary downloads.

Critical Findings

  • CRITICAL: ARMv8.0 NEON Integer Overflow / Garbage Output
    • Location: src/ggml-bitnet-mad.cpp (lines ~344-400)
    • Details: The non-dotprod NEON fallback (vmlal_s8) accumulates 256 products per chunk into an int16x8_t vector. Since each int8 product can reach 254, the sum quickly exceeds the 32,767 maximum of int16_t, causing severe saturation and deterministic garbage text generation on standard Cortex-A53/A73 cores (Issue #411).
    • Remediation: Accumulate directly into int32x4_t or widen to 32-bit every 8 loop iterations.
  • CRITICAL: Supply Chain & Remote Code Execution (RCE) via PyTorch
    • Location: requirements.txt (via torch~=2.2.1)
    • Details: The pinned/required version of torch (2.2.2+cpu) suffers from severe RCE vulnerabilities (e.g., PYSEC-2024-259, PYSEC-2025-41 via torch.load with weights_only=True bypass).
    • Remediation: Upgrade torch constraint to >=2.6.0.

High Findings

  • HIGH: Command Injection Risk in Setup & Execution
    • Location: setup_env.py, run_inference.py, run_inference_server.py
    • Details: subprocess.run(command, shell=shell) is used extensively. If any unsanitized user argument (e.g., from args.model_dir) is passed, it risks command injection. Furthermore, setup_env.py downloads models blindly using huggingface-cli without enforcing SHA256 validation.
    • Remediation: strictly avoid shell=True, and validate HF repos with a sha256 hash parameter.
  • HIGH: Unbounded Memory Allocation in GGUF Loader
    • Location: 3rdparty/llama.cpp/ggml/src/ggml.c (gguf_init_from_file)
    • Details: While n_tensors checks against SIZE_MAX / 2, a maliciously crafted .gguf file declaring n_tensors = 10,000,000 will bypass the check and force GGML_CALLOC to exhaust system RAM, causing a Denial of Service.
    • Remediation: Enforce a realistic maximum tensor limit (e.g., n_tensors < 65536).

Medium/Low Findings

  • MEDIUM: Platform Portability & Windows Build Failures
    • Location: CMakeLists.txt & src/ggml-bitnet-mad.cpp
    • Details: Missing #include <chrono> and const modifier drops in Windows environments (Issues #492, #493). Missing security compiler flags (-fstack-protector, -D_FORTIFY_SOURCE=2) in CMakeLists.txt.
  • LOW: Sys.exit() Indentation Bug
    • Location: setup_env.py
    • Details: Unconditional sys.exit(1) runs due to incorrect indentation in run_command() (Issue #447).

Research Gaps Table

Gap Impact Effort to Fix
Lack of Warm-up in Benchmarks (utils/e2e_benchmark.py) Reported timings include cold-cache overhead, artificially inflating time and reducing reproducibility. Low
No CPU vs GPU Cross-Validation Numerical divergence between C++ SIMD and GPU kernel (gpu/test.py only tests GPU) is unmonitored. Medium
Missing Architecture Support setup_env.py hardcodes shapes (BM/BK) restricting usage of MoE, GQA, and novel sizes (e.g., Issue #354 Bitdistill). High
Sparse Ternary Kernel (Phase 3) Fails to match the 0.31ms Tesla T4 performance claimed in community Issue #364. High

Recommended Fixes

  1. src/ggml-bitnet-mad.cpp: Modify lines 344-351 to vaddw_s16 into a 32-bit accumulator int32x4_t.
  2. requirements.txt: Bump torch>=2.6.0 to eliminate deserialization RCEs.
  3. utils/e2e_benchmark.py: Inject -w 1 or -w 3 into bench_path command args for warm-ups.
  4. CMakeLists.txt: Add add_compile_options(-fstack-protector-strong -D_FORTIFY_SOURCE=2 -fPIE).

Open Issues Summary Table

Issue # Title Classification Severity
411 Garbage output on ARMv8.0 (Cortex-A53/A73) — NEON-only fallback BUG CRITICAL
447 sys.exit(1) runs unconditionally due to indentation BUG LOW
355 TL1/TL2 codegen fails for bm=16 on Windows 11 BUG HIGH
470 ARM I2_S inference produces gibberish/garbage BUG HIGH
354 Repo missing code for Bitdistill paper MISSING FEATURE MEDIUM
364 [Benchmark] 0.31ms Inference for BitNet on Tesla T4 PERFORMANCE MEDIUM

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

The report spans src/ggml-bitnet-mad.cpp, requirements.txt, setup_env.py, run_inference.py, run_inference_server.py, 3rdparty/llama.cpp/ggml/src/ggml.c, CMakeLists.txt, and utils/e2e_benchmark.py. Start by verifying the cited findings and separating them into actionable issues. Done requires confirmed fixes for the selected findings and validation of the affected build, dependency, or benchmark behavior.

Written by the indexing model from the issue text.

Assessment

Tech stack
cmake, cpp, python, pytorch
Domain
backend, build-system, performance, security
Issue type
Bug
Difficulty
5/5
Estimated time
Over a week
Activity status
Quiet
Clarity
Needs clarification
Newbie friendliness
25/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.