Skip to content

Provide a way of detecting system library leakage#5259

Merged
papertigers merged 19 commits into
mainfrom
mike/lib-verify
Mar 22, 2024
Merged

Provide a way of detecting system library leakage#5259
papertigers merged 19 commits into
mainfrom
mike/lib-verify

Conversation

@papertigers

@papertigers papertigers commented Mar 13, 2024

Copy link
Copy Markdown
Contributor

After #5158 was integrated @Rain noticed that attempting to run a build of omdb in the switch zone suddenly stopped working and filed oxidecomputer/helios-omicron-brand#15. @jgallagher ended up fixing this by splitting out the sled-hardware types into their own crate in #5245.

We decided it would be good if we added some sort of CI check to omicron to catch these library leakages earlier. This PR introduces that check and adds it to the helios build and test buildomat job. I have also added some notes to the readme for others that may end up adding a new library dependency.

Locally I modified the allow list so that it would produce errors, those errors end up looking like:

$ cargo xtask verify-libraries
    Finished dev [unoptimized + debuginfo] target(s) in 0.42s
     Running `target/debug/xtask verify-libraries`
    Finished dev [unoptimized + debuginfo] target(s) in 4.11s
Error: Found library issues with the following:
installinator
	UNEXPECTED dependency on libipcc.so.1
omicron-dev
	UNEXPECTED dependency on libipcc.so.1
	UNEXPECTED dependency on libresolv.so.2
sp-sim
	UNEXPECTED dependency on libipcc.so.1
	UNEXPECTED dependency on libresolv.so.2
sled-agent
	NEEDS libnvme.so.1 but is not allowed
mgs
	UNEXPECTED dependency on libipcc.so.1
	UNEXPECTED dependency on libresolv.so.2


If depending on a new library was intended please add it to xtask.toml

Comment thread .github/buildomat/build-and-test.sh Outdated
Comment thread README.adoc Outdated
Comment thread dev-tools/xtask/src/main.rs Outdated
Comment thread dev-tools/xtask/src/main.rs Outdated
Comment thread dev-tools/xtask/src/main.rs Outdated
Comment on lines +250 to +253
let entry = entry.context("dirent")?;
if !entry.file_type()?.is_dir() {
continue;
}

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I think we should be building all of the binaries here -- cargo build --bins should do it. You can use the JSON metadata with --message-format json-render-diagnostics, then iterate over the built binaries to check for them.

I realize it's a significant chunk of work, but it is hopefully not a massive amount, and will make this check much more resilient.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Oh, and I forgot to mention that cargo_metadata, which xtask already pulls in, has support for this: https://docs.rs/cargo_metadata/0.18.1/cargo_metadata/enum.Message.html#method.parse_stream

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Thanks for the tip! Fixed in 276e135

Comment thread dev-tools/xtask/src/main.rs Outdated
}

fn cmd_verify_library() -> Result<()> {
let metadata = load_workspace()?;

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Probably should have a check here to error out if this is run on a non-illumos platform. (I'd recommend a stub impl that just prints out an error like "error: this command is only supported on illumos")

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Fixed in dd71b07

Comment thread library-verification.toml Outdated
Comment thread library-verification.toml Outdated
Comment thread dev-tools/xtask/src/main.rs Outdated

@sunshowers sunshowers left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

putting it back in your queue!

Comment thread library-verification.toml Outdated
@papertigers papertigers requested a review from sunshowers March 18, 2024 21:04

@sunshowers sunshowers left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Looks fantastic, thanks! Just a few minor comments.

@@ -0,0 +1,144 @@
use anyhow::{bail, Context, Result};

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

MPL files require a license header up top -- could you add one here?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Fixed in fa5b905

Comment thread dev-tools/xtask/src/illumos.rs Outdated
fn verify_executable(
config: &XtaskConfig,
path: &Utf8Path,
errors: &mut HashMap<String, Vec<LibraryError>>,

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Should be some kind of ordered map -- either a BTreeMap or an IndexMap (probably a BTreeMap)

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Fixed in fa5b905

Comment thread dev-tools/xtask/src/illumos.rs Outdated
config_path.push(".cargo/xtask.toml");
let config = read_xtask_toml(&config_path)?;

let mut command = Command::new("cargo")

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

This should use $CARGO if available (which it will be almost all of the time, since cargo is invoked via the rustup wrapper)

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Fixed in fa5b905

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

I left it as an error if the env::var("CARGO") fails, but happy to fall back on just "cargo" if you like that better.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Should definitely fall back to cargo, yeah. This pattern is pretty standard, and is expressed in bash as e.g. ${CARGO:-cargo}.

Comment thread dev-tools/xtask/src/illumos.rs Outdated
let mut msg = String::new();
use std::fmt::Write;
errors.iter().for_each(|(binary, errors)| {
write!(msg, "{binary}\n").unwrap();

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

writeln!

Also you can use https://crates.io/crates/swrite to avoid the unwrap.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Fixed in fa5b905

# If we are running on illumos we want to verify that we are not requiring
# system libraries outside of specific binaries. If we encounter this situation
# we bail.
# NB: `cargo xtask verify-libraries` runs `cargo build --bins` to ensure it can

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Doesn't look like it runs cargo build --bins? Just cargo build.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Fixed in fa5b905

@papertigers papertigers requested a review from sunshowers March 20, 2024 16:39
@papertigers papertigers enabled auto-merge (squash) March 20, 2024 20:46
@papertigers papertigers merged commit 5d97551 into main Mar 22, 2024
@papertigers papertigers deleted the mike/lib-verify branch March 22, 2024 02:02
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.

3 participants