added memmove, memcmp to the list of function changed to BTF_FUNC_STATIC

Signed-off-by: Quentin JEROME <qjerome@users.noreply.github.com>
pull/583/head
Quentin JEROME 2 years ago
parent 419448ed1a
commit 72c1572178

@ -544,7 +544,12 @@ impl Btf {
let typedef_type = let typedef_type =
BtfType::Typedef(Typedef::new(ty.name_offset, ty.btf_type)); BtfType::Typedef(Typedef::new(ty.name_offset, ty.btf_type));
types.types[i] = typedef_type; types.types[i] = typedef_type;
} else if !features.btf_func_global || name == "memset" || name == "memcpy" { } else if !features.btf_func_global
|| name == "memset"
|| name == "memcpy"
|| name == "memmove"
|| name == "memcmp"
{
// Sanitize BTF_FUNC_GLOBAL and memset, memcpy // Sanitize BTF_FUNC_GLOBAL and memset, memcpy
let mut fixed_ty = ty.clone(); let mut fixed_ty = ty.clone();
if ty.linkage() == FuncLinkage::Global { if ty.linkage() == FuncLinkage::Global {
@ -1359,7 +1364,7 @@ mod tests {
} }
#[test] #[test]
fn test_sanitize_memset_memcpy() { fn test_sanitize_mem_builtins() {
let mut btf = Btf::new(); let mut btf = Btf::new();
let name_offset = btf.add_string("int".to_string()); let name_offset = btf.add_string("int".to_string());
let int_type_id = btf.add_type(BtfType::Int(Int::new( let int_type_id = btf.add_type(BtfType::Int(Int::new(
@ -1382,33 +1387,35 @@ mod tests {
let func_proto_type_id = let func_proto_type_id =
btf.add_type(BtfType::FuncProto(FuncProto::new(params, int_type_id))); btf.add_type(BtfType::FuncProto(FuncProto::new(params, int_type_id)));
["memset", "memcpy"].iter().for_each(|fname| { ["memset", "memcpy", "memcmp", "memmove"]
let func_name_offset = btf.add_string(fname.to_string()); .iter()
let func_type_id = btf.add_type(BtfType::Func(Func::new( .for_each(|fname| {
func_name_offset, let func_name_offset = btf.add_string(fname.to_string());
func_proto_type_id, let func_type_id = btf.add_type(BtfType::Func(Func::new(
FuncLinkage::Global, func_name_offset,
))); func_proto_type_id,
FuncLinkage::Global,
let features = BtfFeatures { )));
btf_func: true,
btf_func_global: true, // to force function name check let features = BtfFeatures {
..Default::default() btf_func: true,
}; btf_func_global: true, // to force function name check
..Default::default()
btf.fixup_and_sanitize(&HashMap::new(), &HashMap::new(), &features) };
.unwrap();
btf.fixup_and_sanitize(&HashMap::new(), &HashMap::new(), &features)
if let BtfType::Func(fixed) = btf.type_by_id(func_type_id).unwrap() { .unwrap();
assert!(fixed.linkage() == FuncLinkage::Static);
} else { if let BtfType::Func(fixed) = btf.type_by_id(func_type_id).unwrap() {
panic!("not a func") assert!(fixed.linkage() == FuncLinkage::Static);
} } else {
panic!("not a func")
}
// Ensure we can convert to bytes and back again // Ensure we can convert to bytes and back again
let raw = btf.to_bytes(); let raw = btf.to_bytes();
Btf::parse(&raw, Endianness::default()).unwrap(); Btf::parse(&raw, Endianness::default()).unwrap();
}); });
} }
#[test] #[test]

Loading…
Cancel
Save