Mediumghsa:GHSA-2jx3-ff3v-j7jj

    yara-x: Deserialization of Untrusted Data (ghsa:GHSA-2jx3-ff3v-j7jj)

    Published Sources: Hersteller

    Share

    What is affected, what to do

    Update yara-x to version 1.19.0.

    Not sure whether and how you are affected? Ask a question about this vulnerability

    Metrics

    —

    Priority

    No value is available for this vulnerability.

    —

    CVSS v3

    No value is available for this vulnerability.

    —

    EPSS score

    No value is available for this vulnerability.

    Show all metrics
    Severity
    Medium
    Priority (0–325)

    The priority score is a consolidated metric that condenses several individual signals into a single, action-guiding ranking: technical severity (CVSS), exploitation likelihood (EPSS), known-exploited status (KEV) and the context of the affected asset. The aim is to answer the only truly important question in vulnerability management: what first?

    Read in glossary
    27.39 Methodology
    Exploit maturity

    An exploit is code or a technique that specifically uses a concrete vulnerability to force unintended behaviour — such as executing code or escalating privileges. It is the tool that turns a theoretical flaw into a practical attack.

    Read in glossary
    no public PoC known
    KEV status

    The KEV catalogue is a list maintained by the US authority CISA of vulnerabilities for which active exploitation in the wild has been confirmed. It answers not the question „how severe?“ but „is it already being attacked?“ — thereby sharply prioritising patching.

    Read in glossary
    —
    Published
    CWE

    CWE is a catalogue of typical weakness types in software and hardware — such as flawed input validation, unsafe memory handling or poor authentication. Where a CVE names a concrete vulnerability in a concrete product, a CWE describes the underlying class of defect.

    Read in glossary
    CWE-502

    Classification under NIS2 and CRA

    Rule-based classification from exploitation status and severity. It does not replace a case-by-case assessment.

    NIS2

    NIS2 is EU Directive (EU) 2022/2555 to raise the level of cybersecurity across the Union. It substantially broadens obligations compared with the first NIS directive: more sectors, mandatory risk management, staged reporting duties and personal accountability of senior management.

    Read in glossary
    Handle the vulnerability in regular vulnerability handling under Art. 21(2)(e) NIS2.
    CRA

    The CRA is EU Regulation (EU) 2024/2847 setting horizontal cybersecurity requirements for „products with digital elements“ — from industrial controllers and software to connected consumer devices. For the first time manufacturers must ensure security across the entire product lifecycle, handle vulnerabilities and provide security updates.

    Read in glossary
    From 11.12.2027, Annex I Part II CRA requires manufacturers of affected products with digital elements to handle vulnerabilities without delay and provide security updates.
    ISO/IEC 27001

    ISO/IEC 27001 is the internationally leading standard for an information security management system (ISMS). It describes a risk-based, process-oriented framework to systematically plan, implement, review and improve information security.

    Read in glossary
    Control A.8.8, management of technical vulnerabilities: assess relevance to your systems, plan remediation and keep evidence.

    Description

    [!NOTE] This finding was identified during an agentic unsafe Rust code review performed by Gemini AI, followed by human review and verification.

    The Issue

    The crate exports a public safe API Rules::deserialize accepting any generic byte sequence B: AsRef<[u8]>. It restores compiled rule structures directly from raw bytes using bincode::serde::decode_from_slice.

    This decoded Rules struct contains internal lookup tables, including sub_patterns: Vec<(PatternId, SubPattern)>, atoms: Vec<SubPatternAtom>, and lit_pool: BStringPool. Subsequent safe operations assume these internal tables satisfy strict structural invariants:

    • Rules::get_sub_pattern executes unsafe { self.sub_patterns.get_unchecked(sub_pattern_id.0 as usize) }. If untrusted serialized bytes contain an atom referencing an out-of-bounds SubPatternId, calling get_sub_pattern during scanning triggers an out-of-bounds memory read (Undefined Behavior).

    https://github.com/VirusTotal/yara-x/blob/5bd1f35db783679c90a3ea1a66bd15fe4e55bef1/lib/src/compiler/rules.rs#L355-L360

    • Metadata::next() extracts string metadata via unsafe { s.to_str_unchecked() }. If serialized bytes corrupt lit_pool indices or structural data, to_str_unchecked constructs a &str pointing to invalid UTF-8 bytes (Undefined Behavior).

    https://github.com/VirusTotal/yara-x/blob/5bd1f35db783679c90a3ea1a66bd15fe4e55bef1/lib/src/models.rs#L204-L210

    Because passing malformed or untrusted data to Rules::deserialize induces Undefined Behavior in subsequent safe calls (Scanner::new, Scanner::scan) without any unsafe blocks in caller code, this API is unsound.

    Zip file with crashing_payload: crashing_payload.zip

    We have a payload crashing_payload.bin where only a single byte in the structural metadata tail is mutated (changing a SubPatternId from 1 to 248 while keeping the WebAssembly bytecode completely untouched and valid).

    Below is the self-contained verification script which compiles and runs against the official unmodified yara-x v1.17.0 crate:

    use yara_x::{Rules, Scanner};
    
    fn main() {
        // Embed the crashing payload generated by the fuzzer at compile time.
        let serialized = include_bytes!("crashing_payload.bin");
        println!("Loaded embedded crashing payload, length: {}", serialized.len());
    
        // Deserialize. On unmodified library, this succeeds because the WASM and headers
        // are pristine and structural corruption isn't validated.
        if let Ok(deserialized) = Rules::deserialize(serialized) {
            println!("Deserialization succeeded! Running scanner...");
            let mut scanner = Scanner::new(&deserialized);
            
            // Run the standard scan, which will execute the WASM and trigger the out-of-bounds read!
            let _ = scanner.scan(b"lorem ipsum dolor sit amet");
            println!("Scanner finished.");
        } else {
            println!("Deserialization failed!");
        }
    }
    

    1. Miri Trace

    NOTE: This needs to be run with 1.17.0. I haven't tested this against other versions.

    Unfortunately I was able to get a miri trace, but I'm not able to reproduce it right now because of lockfile changes. If you're trying this out be sure to use MIRIFLAGS="-Zmiri-disable-stacked-borrows"

    2. Segfault / panics

    When run natively (without Miri or any sanitizers) on a standard Linux platform, the process immediately segfaults:

    $ cargo run --bin verify
    Loaded embedded crashing payload, length: 11777
    Deserialization succeeded! Running scanner...
    Segmentation fault (core dumped)
    

    And with a newer compiler (which appears to have debug assertions in get_unchecked)

    Deserialization succeeded! Running scanner...
    
    thread 'main' (997442) panicked at lib/src/compiler/rules.rs:404:36:
    unsafe precondition(s) violated: slice::get_unchecked requires that the index is within the slice
    
    This indicates a bug in the program. This Undefined Behavior check is optional, and cannot be relied on for safety.
    note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace
    

    To uphold Rust soundness guarantees, either mark Rules::deserialize as pub unsafe fn deserialize with a formal /// # Safety contract documenting that callers are responsible for verifying the authenticity and structural integrity of the input bytes (e.g. via cryptographic signatures), or replace all internal get_unchecked and to_str_unchecked calls on deserialized data structures with safe bounds checks (.get()) and UTF-8 validation (std::str::from_utf8).


    Source: GitHub Security Advisories

    Affected products

    The following versions are affected. Older releases of the same product line are also vulnerable unless stated otherwise.

    Affected products
    Affected versionsFixed in
    rustyara-x
    • <= 1.18.0
    • 1.19.0

    Vendors and products

    Weakness classes (CWE)

    • CWE-502Deserialization of Untrusted Data

      Base

      The product deserializes untrusted data without sufficiently ensuring that the resulting data will be valid.

      Entry at MITRE CWE-502