cpufeatures: aarch64 Linux reports aes, sha3 and sm4 when only one of their two HWCAPs is set

Aperta
#1,627 0 commenti 0 reazioni 0 assegnatari Vedi su GitHub

I maintainer di solito rispondono entro 1 giorno

@NginxL ci sta già lavorando.

Dal 6/12/2026.

  • #1628 di @NginxL — aperta

Valutazione

Questa issue non è ancora stata valutata.

Descrizione

On aarch64 Linux, cpufeatures reports aes, sha3 and sm4 as present when only one of the two HWCAPs behind each is set.

The check! macro tests a mask with != 0 (cpufeatures/src/aarch64.rs:59):

(($hwcaps & $crate::aarch64::hwcaps::$hwcap) != 0)

Three of the masks hold two HWCAPs (src/aarch64.rs:87-91):

pub const AES: c_ulong = libc::HWCAP_AES | libc::HWCAP_PMULL;
pub const SHA3: c_ulong = libc::HWCAP_SHA3 | libc::HWCAP_SHA512;
pub const SM4: c_ulong = libc::HWCAP_SM3 | libc::HWCAP_SM4;

So either bit is enough. #456 grouped the HWCAPs to ensure "all of the relevant HWCAPs for a given target feature are available". In #395 the conclusion for sha3 was to "check for both". On Apple it looks like both are checked for sha3 (src/aarch64.rs:121-126).

The architecture allows each pair to be half present. The kernel's elf_hwcaps document sets:

  • HWCAP_AES from ID_AA64ISAR0_EL1.AES == 0b0001 and HWCAP_PMULL from == 0b0010;
  • HWCAP_SHA512 from the SHA2 field, and HWCAP_SHA3 from the separate SHA3 field;
  • HWCAP_SM3 and HWCAP_SM4 from two separate fields.

On a CPU or VM that reports AES without PMULL, polyval runs vmull_p64 behind its aes check (polyval 0.6.2, src/backend/autodetect.rs:19). On one that reports only one of SHA3 and SHA512, sha2 0.11 runs its SHA-512 instructions behind its sha3 check. Either case ends in SIGILL. We do not know of shipped hardware like this so it might not actually be a problem in practice. We found it while reviewing sha2 0.11.

The same code is in 0.2.17, 0.3.0 and 0.3.1.

A possible fix is to require every bit of the mask:

{
    let mask = $crate::aarch64::hwcaps::$hwcap;
    ($hwcaps & mask) == mask
}
Lingua principale
Rust
Stelle
695
Fork
185
Merge medio
10h 40m
PR unite (30g)
24

Preparare l'ambiente

Questo progetto non fornisce container di sviluppo, Dockerfile né guida per i contributori, quindi l'ambiente è a tuo carico: parti dal suo README e consulta la nostra guida al primo contributo per i passaggi generali.

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Altre issue di RustCrypto/utils

Tutte le issue di RustCrypto/utils

Issue simili

Altre issue su Rust

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.