Open xu-cheng opened 3 years ago
Hi @xu-cheng , thanks for your report.
I totally agree on every word you mentioned above.
maintain a bunch of forked crates can help us with (1) stability and (2) compatibility and (3) features, and something suffers a lot (1) freshness, (2) security. but overall I slightly tend to maintain an isolated ecosystem. and in production, i believe most products vendor their dependencies and then maintain their vendored sources.
on the getrandom issue, i'd say the only doable way is to maintain a fork of getrandom. as you already know, quality of random number is critical to Intel SGX enclaves, while it may not mean much to many of other platforms. getrandom lays on the bottom of the entire crate dependency graph and i'd strongly recommend user to maintain their own fork.
and i believe hashbrown is a very very special case: std has a built-in hashbrown (v0.9.0 as of today). and one principle you may know is "we should not have 2 different versions of the same library in the same dependency tree". so I'd say if you need hashbrown, first try if you can use the libstd's built-in one.
and i believe hashbrown is a very very special case: std has a built-in hashbrown (v0.9.0 as of today)
FYI, hashbrown
is commonly used as drop-in for essentially alloc::collections::hash_map
in no_std
crates. This use case will likely exist until std hashmap is moved to alloc in the future.
I write enclave code strictly in
no_std
and usehashbrown
as one of the transitive dependencies. However, it fails to compile after upgradinghashbrown
to 0.11. It fails at linker step with the following messages:The pitfall comes from that
hashbrown 0.11
depends ongetrandom 0.2
. Andgetrandom
despite being ano_std
library will always use Linux syscall if the target triple is*-linux-*
. See its document for more detail.Ultimately, I think this just shows a fundamental issue that we tell rust to build enclave code in
x86_64-unknown-linux-gnu
target when in reality we are actually using something likex86_64-unknown-none-sgx
. As such,getrandom
got the wrong impression that we are on Linux and it is safe to use Linux syscall.Of course, we can fork and patch
getrandom
. But IMHO, patching crates for sgx are red herring in terms of maintenance, stability, or even security (as bug fixes in upstream may not be applied in time). Not mentioning it splits the eco systems. I also believe it is infeasible to patch every crates whenever we encounter similar issues. So my question is whether there is a better systematic approach to address the underlying issue.Thanks.