我正在尝试实现 LSM BPF 程序,并且我想在触发 LSM 挂钩BPF_MAP_TYPE_HASH_OF_MAPS
时用于存储每个超级块的信息。sb_alloc_security
例如,我想将地图定义为:
struct bpf_map_def SEC("SBMap") outer_map = {
.type = BPF_MAP_TYPE_HASH_OF_MAPS,
.key_size = sizeof(uuid_t), // super block unique identifier
.value_size = sizeof(__u32), // must be u32 because it is inner map id
.max_entries = 1024, // for now, let's assume we care about only 1024 super blocks
};
我想使用超级块的 UUID 作为键outer_map
,每次分配一个新的超级块时,我想创建一个新的内部映射,例如:
SEC("lsm/sb_alloc_security")
int BPF_PROG(sb_alloc_security, struct super_block *sb) {
uuid_t key = sb->s_uuid; // use super block UUID as key to the outer_map
// If key does not exist in outer_map,
// create a new inner map and insert it
// into the outer_map with the key
}
但似乎地图只能在用户空间中创建。有什么解决方法吗?