matrix-org / matrix-org/matrix-rust-sdk
Key import race causing a worse key to be saved in place of a better version.
Nobody has claimed this yet.
- Dominant language
- Rust
- Stars
- 2.3k
- Forks
- 500
- Avg merge
- 1d 16h
- Merged PRs (30d)
- 106
Description
As seen in this rageshake https://rageshakes.element.io/api/listing/2024-11-06/130841-YOSPUGGB/console.2024-11-06-12.log.gz
There is slightly late room key, so there is an UTD and the sdk tries to query the key from key storage.
And just after the room key arrives down the sync.
We then have two concurent actions trying to import the key
- From key storage (using
import_room_keys) - And down the sync (using
handle_key)
The race is that they both try to see if there is an existing key in order to see if the new one is better or worse
and
But they both think they are the first and that there is no matching key in store.
Therefore the first one to commit to the store wins. By-pasing the better/worse check.
The late key is better than the key from key storage, because it is safe (no gray shield)
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start with import_room_keys in crates/matrix-sdk-crypto/src/store/mod.rs and handle_key in crates/matrix-sdk-crypto/src/machine/mod.rs, focusing on their existing-key checks and store commits. Reproduce or trace concurrent imports from key storage and sync, then verify that the better late room key is retained rather than whichever import commits first.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- rust
- Domain
- cryptography, security
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100