element-hq / element-hq/element-web
Illegal instruction on Skylake CPUs on Linux kernel with GDS/downfall mitigation enabled
- Dominant language
- TypeScript
- Stars
- 13.5k
- Forks
- 2.8k
- PR merge metrics
- PR metrics pending
Description
### Steps to reproduce
On an Archlinux machine with an Intel Skylake CPU and the kernel configured to mitigate the "Downfall"/"Gather Data Sample" CPU vulnerability (booted with `gather_data_sampling=force`), `element-desktop 1.11.51` run with `electron 27.1.3` crashes with an illegal instruction a few seconds after being started (that Electron version is necessary because older Electron releases contain 1-2 bugs that themselves trigger illegal instruction crashes caused by flawed AVX/AVX2 detection routines).
AFAIK this only affects Skylake CPUs because they are the only CPU generation that is both new enough to be affected by GDS/Downfall but still old enough that Intel didn't publish a Microcode update mitigating the vulnerability without breaking AVX/AVX2 support.
### Outcome
Excerpt from a backtrace:
```
Thread 1 "electron" received signal SIGILL, Illegal instruction.
sha2::sha512::x86::sha512_compress_x86_64_avx (state=0x7fffffff7e80, block=0x7fffffff7e00 b"rspwczbifweef~dwes", '6' ) at src/sha512/x86.rs:64
Downloading source file /build/.cargo/registry/src/index.crates.io-6f17d22bba15001f/sha2-0.9.9/src/sha512/x86.rs
64 src/sha512/x86.rs: Directory not empty.
```
I suspect this crash to be [caused](https://github.com/element-hq/element-desktop/blob/v1.11.51/package.json#L124) by `seshat-node 3.0.1`, which [appears to use](https://github.com/matrix-org/seshat/blob/3.0.1/seshat-node/Cargo.lock#L231) version 0.2.6 of the `cpufeatures` crate, which contains a flawed detection routine for AVX/AVX2 support. Version 0.2.8 of the `cpufeatures` crate contains a [fix](https://github.com/RustCrypto/utils/commit/95219acbd028bbd3966fb94bbd78a999141a3e8d) for this.
I've verified that outdated versions of the `cpufeatures` crate can cause this type of crash by building a test program that calculates a SHA512 hash using the `sha2` crate with both `cpufeatures 0.2.7` and `cpufeatures 0.2.8`. Running the resulting binaries on the affected machine yields the expected results: the binary built with `cpufeatures 0.2.7` crashes with an illegal instruction, whilst the binary built with `cpufeatures 0.2.8` works fine and does not crash.
I routinely build my own packages of `element-desktop`, and I'd like to verify my suspicion by building a version of `element-desktop` where the `seshat` dependency is built using an updated version of the `cpufeatures` create, but I gotta admit that I'm not sure how to do that, because I'm not really familiar with the Electron/Node and Rust ecosystems.
### Operating system
Archlinux testing (kernel: linux-hardened 6.6.7.hardened1-1.1)
### Application version
element-desktop 1.11.51, run with electron 27.1.3
### How did you install the app?
custom-built package derived from Archlinux's official element-desktop 1.11.51 package, but updated to use electron 27
### Homeserver
not relevant
### Will you send logs?
Stack traces: Yes
Rage shake logs: No
Contributor guide
Assessment
This issue has not been assessed yet.