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

Arbitrary Shell Execution through #[link_section] #118

Closed
JohnHVancouver opened this issue Nov 15, 2022 · 7 comments · Fixed by #135
Closed

Arbitrary Shell Execution through #[link_section] #118

JohnHVancouver opened this issue Nov 15, 2022 · 7 comments · Fixed by #135

Comments

@JohnHVancouver
Copy link
Contributor

JohnHVancouver commented Nov 15, 2022

The shell code in init_array is always executed first leading to arbitrary shell execution potentially.

-- Repro removed temporarily

Is there something in Cargo/rustc or a more "Rust" way to detect and prevent these things?

@workingjubilee
Copy link
Contributor

These kinds of things can be filtered via this flotilla of lints: rust-lang/rust#82499

@workingjubilee
Copy link
Contributor

workingjubilee commented Nov 15, 2022

I probably need to redesign the unsafe detection, there was an alternate design that used a shell-game around building the code without the #[pg_extern] annotation, which would allow straightforward usage of #[forbid(unsafe_code)] and a few other lints, as a verification step, and then rebuilding the code with it (and with less lints), and then skipped using geiger.

@workingjubilee
Copy link
Contributor

The naive solution might be to just scan for #[ and error during parsing the code, but I'm not familiar with how Rust interprets Attributes, it seems something like works as well.

To address this part of your question more directly: Rust is very, very lax about whitespace in most cases where a logical segment in the parse could be interpreted as existing.

@jbrindle
Copy link

What lints can we add to Cargo.toml to validate that they will actually catch this behavior?

@workingjubilee
Copy link
Contributor

It involves restructuring the build a bit to let us do a "dry run" pre-build and then do it "for real", as mentioned. I am working on that PR.

@workingjubilee
Copy link
Contributor

I have a draft branch for this that successfully catches this specific example, but it is still technically possible to get #[link_section] without #[no_mangle] by, unless using a higher rustc version than 1.61.0, so I will polish it up and submit it next week but it will contain an ignored test unless we also have consensus on raising MSRV.

@workingjubilee
Copy link
Contributor

workingjubilee commented Dec 1, 2022

TODO:

  • Test for #[no_mangle]
    • ...passes
    • ...on main
  • Test for #[link_section]
    • ...passes
    • ...on main

workingjubilee added a commit to workingjubilee/plrust that referenced this issue Dec 9, 2022
workingjubilee added a commit that referenced this issue Dec 9, 2022
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 a pull request may close this issue.

3 participants