fix(can): close the race between the identity check and the read-only store
Maintainers usually reply within 1 day
A pull request for this has already been merged.
- #60 by @Tichael — merged
Assessment
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Newbie friendliness
- 68/100
- Issue type
- Bug
- Clarity
- Clearly specified
- Activity status
- Active
- Tech stack
- rust
- Domain
- embedded-iot
Research direction
Start by reading the implementations of set_can_read_only(), is_can_read_only(), and the identity confirmation and revocation functions mentioned in the issue. Then inspect the existing CAN tests and add the described interleaving test: confirm identity, unlock, clear only the identity flag, and assert the bus reads as read-only. Done when the test passes and an unconfirmed identity always reads as read-only.
Written by the indexing model from the issue text.
Description
Follow-up to #49.
Problem
set_can_read_only(false) checks the identity flag and then stores the read-only flag in two separate steps:
let enabled = enabled || crate::can_log::is_can_logging() || !is_car_identity_confirmed();
CAN_READ_ONLY.store(enabled, Ordering::Relaxed);
If revoke_car_identity() runs between those two steps, the order is:
set_can_read_only(false)reads identity = confirmed, soenabled = false.revoke_car_identity()clears the identity and storesCAN_READ_ONLY = true.set_can_read_only(false)storesCAN_READ_ONLY = false.
The bus ends up unlocked with no confirmed identity, which is what the gate is meant to prevent.
Is it reachable today?
No. Nothing calls set_can_read_only(false) yet, and embassy tasks on one executor only switch at await points. It becomes possible if these functions are ever called from an interrupt, a second executor (e.g. an interrupt-priority executor on ESP) or another thread on PC.
The CAN logging check doesn't have this gap: is_can_read_only() already ORs in is_can_logging(), so it's enforced when the flag is read.
Suggested fix
Treat the identity like logging: OR !is_car_identity_confirmed() into is_can_read_only(), so an unconfirmed identity always reads as read-only, whatever CAN_READ_ONLY holds. Alternatively, wrap the check and the store in critical_section::with (core-interface already depends on critical-section).
Add a test that confirms, unlocks, and then clears only the identity flag (simulating the interleaving) and asserts that is_can_read_only() returns true.
- Dominant language
- Rust
- Stars
- 1
- Forks
- 0
- Avg merge
- 10h 56m
- Merged PRs (30d)
- 15
Getting set up
Starts the project's dev container in your browser, under your own GitHub account.
- No Dockerfile or Docker Compose file
- No pull request template
- No contributing 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.
More from OpenCarControls/firmware
-
Clean up E-GMP leftoversPossibly taken @Tichael claimed this today. Open
Difficulty 2/5 1-3 hours Newbie friendliness 77/100
OpenCarControls/firmware#34 ·
Maintainers usually reply within 1 day
-
BLE: send the current state when the app subscribesPossibly taken @Tichael claimed this today. Open
Difficulty 3/5 1-2 days Newbie friendliness 35/100
OpenCarControls/firmware#58 ·
Maintainers usually reply within 1 day
-
enhancement
Difficulty 5/5 Over a week Newbie friendliness 35/100
OpenCarControls/firmware#55 ·
Maintainers usually reply within 1 day
-
enhancement
Difficulty 5/5 Over a week Newbie friendliness 35/100
OpenCarControls/firmware#54 ·
Maintainers usually reply within 1 day
-
enhancement
Difficulty 4/5 3-5 days Newbie friendliness 55/100
OpenCarControls/firmware#53 ·
Maintainers usually reply within 1 day
All issues in OpenCarControls/firmware
Similar issues
-
Difficulty 1/5 1-3 hours Newbie friendliness 86/100
Maintainers usually reply within 1 day
-
area:sim good first issue kind:feature
Difficulty 2/5 1-3 hours Newbie friendliness 87/100
Maintainers usually reply within 1 day
-
The demo's interval button and chart legend keep the previous interval after an interval changeOpenbug ui
Difficulty 2/5 1-3 hours Newbie friendliness 83/100
userFRM/egui-charts#670 ·
Maintainers usually reply within 1 day
-
docs good first issue
Difficulty 1/5 1-3 hours Newbie friendliness 84/100
Usenova-Labs/usenova-backend#35 ·
Maintainers usually reply within 1 day
-
bug
Difficulty 2/5 1-3 hours Newbie friendliness 70/100
lugassawan/swe-workbench#823 ·
Maintainers usually reply within 1 day