github.com/castai/kvisor@v1.7.1-0.20240516114728-b3572a2607b5/pkg/ebpftracer/c/headers/common/capabilities.h (about) 1 #ifndef __COMMON_CAPABILITIES_H__ 2 #define __COMMON_CAPABILITIES_H__ 3 4 #include <vmlinux.h> 5 #include <vmlinux_flavors.h> 6 7 #include <common/common.h> 8 9 // PROTOTYPES 10 11 statfunc u64 credcap_to_slimcap(void *); 12 13 // FUNCTIONS 14 15 // BEFORE: Currently, (2021), there are ~40 capabilities in the Linux kernel 16 // which are stored in an u32 array of length 2. This might change in the (not 17 // so near) future as more capabilities will be added. For now, we use u64 to 18 // store this array in one piece 19 // 20 // NEW NOTE: Recently, (2023), kernel has started using an u64 for all 21 // capabilities, instead of using variable u32 array. Use type flavors to 22 // deal with that. 23 // 24 25 statfunc u64 credcap_to_slimcap(void *from) 26 { 27 kernel_cap_t___older to = {0}; 28 29 if (bpf_core_field_exists(to.cap)) { 30 bpf_core_read(&to, bpf_core_type_size(kernel_cap_t___older), from); 31 return ((to.cap[1] + 0ULL) << 32) + to.cap[0]; 32 33 } else { 34 kernel_cap_t newto = {0}; 35 bpf_core_read(&newto, bpf_core_type_size(kernel_cap_t), from); 36 return newto.val; 37 } 38 39 return 0; 40 } 41 42 #endif