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

auditwheel: add libz.so.1 to whitelisted libraries #625

Merged
merged 3 commits into from
Sep 18, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
168 changes: 84 additions & 84 deletions Cargo.lock

Large diffs are not rendered by default.

36 changes: 31 additions & 5 deletions src/auditwheel/audit.rs
Original file line number Diff line number Diff line change
Expand Up @@ -168,19 +168,38 @@ fn policy_is_satisfied(
let arch_versions = &policy.symbol_versions.get(arch).ok_or_else(|| {
AuditWheelError::UnsupportedArchitecture(policy.clone(), arch.to_string())
})?;
let mut offenders = HashSet::new();
let mut offending_libs = HashSet::new();
let mut offending_blacklist_syms = HashMap::new();
let undef_symbols: HashSet<String> = elf
.dynsyms
.iter()
.filter_map(|sym| {
if sym.st_shndx == goblin::elf::section_header::SHN_UNDEF as usize {
elf.dynstrtab.get_at(sym.st_name).map(ToString::to_string)
} else {
None
}
})
.collect();
for dep in deps {
// Skip dynamic linker/loader
if dep.starts_with("ld-linux") || dep == "ld64.so.2" || dep == "ld64.so.1" {
continue;
}
if !policy.lib_whitelist.contains(dep) {
offenders.insert(dep.clone());
offending_libs.insert(dep.clone());
}
if let Some(sym_list) = policy.blacklist.get(dep) {
let mut intersection: Vec<_> = sym_list.intersection(&undef_symbols).cloned().collect();
if !intersection.is_empty() {
intersection.sort();
offending_blacklist_syms.insert(dep, intersection);
}
}
}
for library in versioned_libraries {
if !policy.lib_whitelist.contains(&library.name) {
offenders.insert(library.name.clone());
offending_libs.insert(library.name.clone());
continue;
}
let mut versions: HashMap<String, HashSet<String>> = HashMap::new();
Expand Down Expand Up @@ -216,13 +235,20 @@ fn policy_is_satisfied(
offending_symbols.join(", ")
)
};
offenders.insert(offender);
offending_libs.insert(offender);
}
}
}
// Checks if we can give a more helpful error message
let is_libpython = Regex::new(r"^libpython3\.\d+\.so\.\d+\.\d+$").unwrap();
let offenders: Vec<String> = offenders.into_iter().collect();
let mut offenders: Vec<String> = offending_libs.into_iter().collect();
for (lib, syms) in offending_blacklist_syms {
offenders.push(format!(
"{} offending black-listed symbols: {}",
lib,
syms.join(", ")
));
}
match offenders.as_slice() {
[] => Ok(()),
[lib] if is_libpython.is_match(lib) => {
Expand Down
112 changes: 78 additions & 34 deletions src/auditwheel/manylinux-policy.json

Large diffs are not rendered by default.

17 changes: 10 additions & 7 deletions src/auditwheel/musllinux-policy.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@
"aliases": [],
"priority": 0,
"symbol_versions": {},
"lib_whitelist": []
"lib_whitelist": [],
"blacklist": {}
},
{"name": "musllinux_1_1",
"aliases": [],
Expand All @@ -22,9 +23,10 @@
"armv7l": {
}
},
"lib_whitelist": [
"libc.so"
]},
"lib_whitelist": ["libc.so", "libz.so.1"],
"blacklist": {
"libz.so.1": ["_dist_code", "_length_code", "_tr_align", "_tr_flush_block", "_tr_init", "_tr_stored_block", "_tr_tally", "bi_windup", "crc32_vpmsum", "crc_fold_512to32", "crc_fold_copy", "crc_fold_init", "deflate_copyright", "deflate_medium", "fill_window", "flush_pending", "gzflags", "inflate_copyright", "inflate_fast", "inflate_table", "longest_match", "slide_hash_sse", "static_ltree", "uncompress2", "x86_check_features", "x86_cpu_has_pclmul", "x86_cpu_has_sse2", "x86_cpu_has_sse42", "z_errmsg", "zcalloc", "zcfree"]
}},
{"name": "musllinux_1_2",
"aliases": [],
"priority": 90,
Expand All @@ -42,7 +44,8 @@
"armv7l": {
}
},
"lib_whitelist": [
"libc.so"
]}
"lib_whitelist": ["libc.so", "libz.so.1"],
"blacklist": {
"libz.so.1": ["_dist_code", "_length_code", "_tr_align", "_tr_flush_block", "_tr_init", "_tr_stored_block", "_tr_tally", "bi_windup", "crc32_vpmsum", "crc_fold_512to32", "crc_fold_copy", "crc_fold_init", "deflate_copyright", "deflate_medium", "fill_window", "flush_pending", "gzflags", "inflate_copyright", "inflate_fast", "inflate_table", "longest_match", "slide_hash_sse", "static_ltree", "uncompress2", "x86_check_features", "x86_cpu_has_pclmul", "x86_cpu_has_sse2", "x86_cpu_has_sse42", "z_errmsg", "zcalloc", "zcfree"]
}}
]
7 changes: 5 additions & 2 deletions src/auditwheel/policy.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,17 +29,20 @@ pub static MUSLLINUX_POLICIES: Lazy<Vec<Policy>> = Lazy::new(|| {
/// Manylinux policy
#[derive(Debug, Clone, PartialEq, Deserialize)]
pub struct Policy {
/// manylinux platform tag name
/// platform tag name
pub name: String,
/// manylinux platform tag aliases
/// platform tag aliases
pub aliases: Vec<String>,
/// policy priority. Tags supporting more platforms have higher priority
pub priority: i64,
/// platform architecture to symbol versions map
#[serde(rename = "symbol_versions")]
pub symbol_versions: HashMap<String, HashMap<String, HashSet<String>>>,
/// whitelisted libraries
#[serde(rename = "lib_whitelist")]
pub lib_whitelist: HashSet<String>,
/// blacklisted symbols of whitelisted libraries
pub blacklist: HashMap<String, HashSet<String>>,
}

impl Default for Policy {
Expand Down
138 changes: 136 additions & 2 deletions test-crates/lib_with_disallowed_lib/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 1 addition & 2 deletions test-crates/lib_with_disallowed_lib/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,4 @@ crate-type = ["cdylib"]

[dependencies]
libz-sys = { version = "1.1.2", default-features = false }
# Don't use the macros feature, which makes compilation much faster
pyo3 = { version = "0.14.0", default-features = false, features = ["extension-module"] }
pyo3 = { version = "0.14.0", features = ["extension-module"] }
Loading