Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

riot-rs-embassy: improve SWI selection #285

Merged
merged 3 commits into from
May 6, 2024

Conversation

kaspar030
Copy link
Collaborator

This PR tries to make the incoming wave of different SWI choices more managable.

  • add executor_swi!(NAME)-macro (reduces code duplication, see e.g., arch/nrf/mod.rs)

  • adds logic to build.rs that, if set, generates a swi.rs that basically just contains executor_swi!(NAME) with NAME taken from the env variable CONFIG_SWI. This will be used in add stm32 support #237.

@kaspar030
Copy link
Collaborator Author

generates a swi.rs that basically just contains executor_swi!(NAME) with NAME taken from the env variable CONFIG_SWI.

I didn't find a way to do this directly in Rust. There might be one using proc macros, but I dug quite far, IMO the build.rs solution is preferable. The difficulty lies in env!() spitting out a string literal, but we want to use the value in a use foo; statement.

@kaspar030 kaspar030 requested a review from chrysn May 3, 2024 10:33
Copy link
Collaborator

@chrysn chrysn left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks like a good simplification; see comment inline.

I'm not super happy with how (as I've learned as part of reviewing this) InterruptExecutor::start as a safe function trusts the user to pass in the right interrupt, but that's nothing to fix in this PR.

src/riot-rs-embassy/src/executor_swi.rs Show resolved Hide resolved
@chrysn chrysn enabled auto-merge May 6, 2024 11:00
@chrysn chrysn added this pull request to the merge queue May 6, 2024
Merged via the queue into future-proof-iot:main with commit 16ee888 May 6, 2024
16 checks passed
@kaspar030 kaspar030 deleted the executor_swi branch May 7, 2024 11:31
if let Ok(var) = env::var("CONFIG_SWI") {
fs::write(
&dest_path,
format!("crate::executor_swi!({});\n", var).as_bytes(),
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This allows arbitrary Rust injection from the environment; since it's only expecting an identifier, I think it should be validated by checking that the environment variable value is only composed of a-z, A-Z, 0-9, and _.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Generally, an attacker in control of the execution environment already owns the build process and host machine.

If we want to introduce a check, syn::Ident can be parsed from a string without making arbitrary validity choices.

@kaspar030 kaspar030 mentioned this pull request May 15, 2024
2 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants