[英]How does the second argument use a variable when using bpf_probe_read_kernel_str() in ebpf?
` `
size_t pos = 0;
const u32 MAX_BACKTRACE_DEPTH = 20;
for (u32 cnt = MAX_BACKTRACE_DEPTH; cnt != 0; --cnt) {
if (err || curr_dentry == NULL) {
break;
}
int name_len = BPF_CORE_READ(curr_dentry, d_name.len);
const u8 *name = BPF_CORE_READ(curr_dentry, d_name.name);
if (name_len <= 1) {
break;
}
if (name_len + pos > 512) {
break;
}
name_len = bpf_probe_read_kernel_str(filename + pos, name_len, name);
if (name_len <= 1) {
break;
}
pos += name_len;
filename[pos - 1] = '/';
struct dentry *temp_dentry = BPF_CORE_READ(curr_dentry, d_parent);
if (temp_dentry == curr_dentry || temp_dentry == NULL) {
break;
}
curr_dentry = temp_dentry;
}
` ebpf validator prompts "R2 unbounded memory access, use 'var &= const' or 'if (var < const)'" when the second argument to function bpf_probe_read_kernel_str is a variable. ` ebpf 验证器提示“R2 unbounded memory access, use 'var &= const' or 'if (var < const)'” 当 function bpf_probe_read_kernel_str 的第二个参数是变量时。
I tried to add const to name_len and I couldn't.我试图将 const 添加到 name_len 但我做不到。
You need to have a strict bound on that name_len
variable.您需要严格限制该
name_len
变量。 It is currently only bounded by 512 - pos
which is not a constant.它目前仅受
512 - pos
的限制,这不是一个常数。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.