What will happen if someone insert malicious code to local std (or crates from crates.io) source code?

While containers are leaky, they are far better than most other mechanisms.

One issue I found is that one crate I develop has a test for unreadable files. I have to detect root and say "well, I can't test this" because I have no idea how to make a file unreadable as root (in any portable enough way to warrant the extra complexity). It's the main impetus for this RFC, but I have other uses for it as well (detecting kernel feature support). Being root in the container makes it interesting to test some of these things.

Shameless plug: cargo cache has a verify subcommand that will read all the .crate archives from the registry cache and compare them to the actual sources in the src cache of cargos download cache and will notify if it finds additional files or missing or modified (differing sizes) in the directory where the crate sources are extracted.

cargo install cargo-cache
cargo cache verify --dry-run

edit: just saw that the afl crate apparently dumps .c object files into the cargo home during compilation, lol

1 Like

I believe you can drop CAP_DAC_OVERRIDE. This is the capability on Linux that allows root to bypass any file permission checks.

Some discussions happened here https://github.com/rust-lang/cargo/issues/9455.

I once tried to solve that but failed to continue :disappointed:.

Sure. This doesn't help Windows, BSD, or macOS though. AFAIK, they're all very different and tend to be process-wide things, so if test scheduling isā€¦unfortunate, such changes could affect other tests non-deterministically. Checking getuid is sufficient for now, but means that CI is not actually testing one codepath. Even capability dropping seem excessive for the immediate use case (extra test-only dep, more C bindings, etc.).

Hardware failures can be handled by integrity-checking filesystems. Others have mentioned setting the files to read-only.

On linux we could also opportunistically enable fs-verity on the files. It's supported by ext4 and btrfs. Support for xfs is WIP.

In CI you can drop caps on the shell level.

capsh --drop cap_dac_override -- -c 'cargo test'

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.