-1

`

    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.

I tried to add const to name_len and I couldn't.

1 Answers1

0

You need to have a strict bound on that name_len variable. It is currently only bounded by 512 - pos which is not a constant.

pchaigno
  • 11,313
  • 2
  • 29
  • 54