Skip to content

core_arch test suite fails with SIGILL #2278

Open
rust-lang/rust
#166335

Description

@RalfJung

I tried this command:

TARGET=x86_64-unknown-linux-gnu RUSTFLAGS="-C target-feature=-sse3 -Cforce-frame-pointers=on" cargo test --manifest-path crates/core_arch/Cargo.toml

It aborts with SIGILL. The coredump has the following backtrace for the failing thread:

                Stack trace of thread 793861:
                #0  0x000056211512f8ad _RNvNtNtNtCsf7HRiN87Bge_9core_arch9core_arch3x862kl20__mm_encodekey256_u32B7_ (core_arch-a950f9464a0014cc + 0x8198ad)
                #1  0x00005621150b39b0 _RNvNtNtNtNtCsf7HRiN87Bge_9core_arch9core_arch3x862kl5tests12encodekey256 (core_arch-a950f9464a0014cc + 0x79d9b0)
                #2  0x00005621150b4cbf _RNvNvNtNtNtNtCsf7HRiN87Bge_9core_arch9core_arch3x862kl5testss_26test_mm_aesdecwide256kl_u826test_mm_aesdecwide256kl_u8 (core_arch-a950f9464a0014cc + 0x79ecbf)
                #3  0x00005621150b4080 _RNvNtNtNtNtCsf7HRiN87Bge_9core_arch9core_arch3x862kl5testss_26test_mm_aesdecwide256kl_u8 (core_arch-a950f9464a0014cc + 0x79e080)
                #4  0x00005621150e81f9 _RNCNvNtNtNtNtCsf7HRiN87Bge_9core_arch9core_arch3x862kl5tests26test_mm_aesdecwide256kl_u80Bb_ (core_arch-a950f9464a0014cc + 0x7d21f9)
                #5  0x0000562114f02608 _RNvYNCNvNtNtNtNtCsf7HRiN87Bge_9core_arch9core_arch3x862kl5tests26test_mm_aesdecwide256kl_u80INtNtNtCs9xW7P2vDFDD_4core3ops8function6FnOnceuE9call_onceBe_ (core_arch-a950f9464a0014cc + 0x5ec608)
                #6  0x000056211517a7fb _RINvCsfPaTRGSX743_4test28___rust_begin_short_backtraceINtNtCs9xW7P2vDFDD_4core6result6ResultuNtNtCshvaLlscjhsv_5alloc6string6StringEFEBQ_EB2_ (core_arch-a950f9464a0014cc + 0x8647fb)
                #7  0x0000562115187fb5 _RNCNvCsfPaTRGSX743_4test8run_test0B3_ (core_arch-a950f9464a0014cc + 0x871fb5)
                #8  0x0000562115182504 _RINvNtNtCsadZFJLPwbP2_3std3sys9backtrace28___rust_begin_short_backtraceNCNvCsfPaTRGSX743_4test8run_tests_0uEB1b_ (core_arch-a950f9464a0014cc + 0x86c504)
                #9  0x000056211518af42 _RNSNvYNCINvNtNtCsadZFJLPwbP2_3std6thread9lifecycle15spawn_uncheckedNCNvCsfPaTRGSX743_4test8run_tests_0uEs_0INtNtNtCs9xW7P2vDFDD_4core3ops8function6FnOnceuE9call_once6vtableB17_ (core_arch-a950f9464a0014cc + 0x874f42)
                #10 0x00005621151f6faf _RNvNvMs0_NtNtNtCsadZFJLPwbP2_3std3sys6thread4unixNtB7_6Thread3new12thread_start (core_arch-a950f9464a0014cc + 0x8e0faf)
                #11 0x00007f60e44c6db8 start_thread (libc.so.6 + 0x94db8)
                #12 0x00007f60e4544f98 __clone3 (libc.so.6 + 0x112f98)

So this seems to be inside test_mm_aesdecwide256kl_u8:

https://github.com/rust-lang/stdarch//blob/ce775c948eb7ae41b034330fd4d7a0965e62206a/crates/core_arch/src/x86/kl.rs#L522-L543

Activity

  1. RalfJung commented on Nov 19, 2026

    @RalfJung
    MemberAuthor

    It looks like my CPU has widekl but not kl:

    [feat.rs:7:3] is_x86_feature_detected!("kl") = false
    [feat.rs:8:3] is_x86_feature_detected!("widekl") = true
    

    The test test_mm_aesdecwide256kl_u8 checks for widekl and then invokes encodekey256 which need kl.
    Looks like a buggy test? Cc @sayantn (test added in #1706)

  2. RalfJung commented on Nov 19, 2026

    @RalfJung
    MemberAuthor

    The Rust compiler information thinks that "widekl" implies "kl".
    That would make sense but seems to be wrong? Or the "widekl" feature detection is broken and my CPU doesn't actually have "widekl".

    $ lscpu
    Architecture:                x86_64
      CPU op-mode(s):            32-bit, 64-bit
      Address sizes:             39 bits physical, 48 bits virtual
      Byte Order:                Little Endian
    CPU(s):                      20
      On-line CPU(s) list:       0-19
    Vendor ID:                   GenuineIntel
      Model name:                12th Gen Intel(R) Core(TM) i7-12700H
        CPU family:              6
        Model:                   154
        Thread(s) per core:      2
        Core(s) per socket:      14
        Socket(s):               1
        Stepping:                3
        Microcode version:       0x429
        CPU(s) scaling MHz:      12%
        CPU max MHz:             4700,0000
        CPU min MHz:             400,0000
        BogoMIPS:                5376,00
        Flags:                   fpu vme de pse tsc msr pae mce cx8 apic sep mtrr pge mca cmov pat pse36 clflush dts acpi mmx fxsr sse sse2 ss ht tm pbe syscall nx pdpe1gb rdtscp lm constant_tsc art arch_perfmon pebs bts rep_good nopl xtopology nonstop_tsc cpuid aperfmperf tsc_known_fr
                                 eq pni pclmulqdq dtes64 monitor ds_cpl vmx smx est tm2 ssse3 sdbg fma cx16 xtpr pdcm sse4_1 sse4_2 x2apic movbe popcnt tsc_deadline_timer aes xsave avx f16c rdrand lahf_lm abm 3dnowprefetch cpuid_fault epb ssbd ibrs ibpb stibp ibrs_enhanced tpr_shadow f
                                 lexpriority ept vpid ept_ad fsgsbase tsc_adjust bmi1 avx2 smep bmi2 erms invpcid rdseed adx smap clflushopt clwb intel_pt sha_ni xsaveopt xsavec xgetbv1 xsaves split_lock_detect user_shstk avx_vnni dtherm ida arat pln pts hwp hwp_notify hwp_act_window h
                                 wp_epp hwp_pkg_req hfi vnmi umip pku ospke waitpkg gfni vaes vpclmulqdq rdpid movdiri movdir64b fsrm md_clear serialize arch_lbr ibt flush_l1d arch_capabilities
    Virtualization features:     
      Virtualization:            VT-x
    Caches (sum of all):         
      L1d:                       544 KiB (14 instances)
      L1i:                       704 KiB (14 instances)
      L2:                        11,5 MiB (8 instances)
      L3:                        24 MiB (1 instance)
    NUMA:                        
      NUMA node(s):              1
      NUMA node0 CPU(s):         0-19
    Vulnerabilities:             
      Gather data sampling:      Not affected
      Ghostwrite:                Not affected
      Indirect target selection: Not affected
      Itlb multihit:             Not affected
      L1tf:                      Not affected
      Mds:                       Not affected
      Meltdown:                  Not affected
      Mmio stale data:           Not affected
      Old microcode:             Vulnerable
      Reg file data sampling:    Vulnerable: No microcode
      Retbleed:                  Not affected
      Spec rstack overflow:      Not affected
      Spec store bypass:         Mitigation; Speculative Store Bypass disabled via prctl
      Spectre v1:                Mitigation; usercopy/swapgs barriers and __user pointer sanitization
      Spectre v2:                Mitigation; Enhanced / Automatic IBRS; IBPB conditional; PBRSB-eIBRS SW sequence; BHI BHI_DIS_S
      Srbds:                     Not affected
      Tsa:                       Not affected
      Tsx async abort:           Not affected
      Vmscape:                   Mitigation; IBPB before exit to userspace
    
  3. bjorn3 commented on Nov 19, 2026

    @bjorn3
    Member

    LLVM also has widekl imply kl: https://github.com/llvm/llvm-project/blob/1d73203488050b947d7fab760f76de8990a4d937/llvm/lib/Target/X86/X86.td#L328-L330 Your CPU should be Alderlake, which according to GCC has both kl and widekl. According to LLVM both widekl and by feature implication kl is supported. AFAICT it doesn't make sense to support widekl without kl given that all those instructions need a wrapping key set, which can only be set by the privileged loadiwkey instruction, which is part of the kl feature.

    According to https://lore.kernel.org/all/[email protected]/ userspace isn't supposed to use Keylocker instructions though "because there is no ABI provided to communicate and coordinate wrapping-key restore failures to userspace". It looks like that patchset hasn't landed yet, so I suspect keylocker is entirely unsupported on Linux right now. @sayantn how did it work for you? Did you test on another OS?

  4. sayantn commented on Nov 21, 2026

    @sayantn
    Contributor

    I have not tested on anything other than Linux (I couldn't test it natively since my cpu doesn't support keylocker). I don't really get the point in that post about communicating key wrapping failures. The instructions are not privileged except for loadiwkey.

  5. sayantn commented on Nov 21, 2026

    @sayantn
    Contributor

    upon looking at the std_detect code again, there might be a bug. It queries cpuid(0x19), and sets kl if bit 0 of EBX is on, and widekl if bit 2 of EBX is active. Looking at the gcc code, I think the actual flow has to be check bit 0 of EBX (this signifies OS permission to USE keylocker), and then query bit 2 of EBX for widekl, and query bit 23 of ECX from cpuid(0x07) for kl

  6. bjorn3 commented on Nov 21, 2026

    @bjorn3
    Member

    I don't really get the point in that post about communicating key wrapping failures.

    If you hybernate and resume or use something like CRUI to create a snapshot of a process and restore it after a reboot (as is common for applying updates on supercomputers), all the wrapped keys would be invalidated. As I understand it the problem is how would the kernel communicate this to programs to avoid them crashing next time they try to use a keylocker instruction? There is currently no defined way for that.

  7. sayantn commented on Nov 21, 2026

    @sayantn
    Contributor

    ok that makes sense. I put up a pr fixing this behavior (checking os support before enabling widekl, currently only kl checked for that, which was the reason for that bug), and some other bugs rust-lang/rust#166335

  8. linked a pull request that will close this issueA few fixes in x86 std_detect #166335on Nov 21, 2026
  9. rustbot commented on Nov 22, 2026

    @rustbot
    Collaborator

    Error: Label bug can only be set by Rust team members

    Please file an issue on GitHub at triagebot if there's a problem with this bot, or reach out on #triagebot on Zulip.

  10. bardiharborow commented on Nov 22, 2026

    @bardiharborow

    @rustbot label +A-x86 +A-runtime-detection +A-testing

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions