Skip to content

Commit

Permalink
Do not initialize kern_version for TRACING/EXT programs
Browse files Browse the repository at this point in the history
The TRACING/EXT programs use attach_btf_id and attach_prog_fd
fields from struct bpf_load_program_attr.

The attach_prog_fd field shares space with kern_version,
so by setting kern_version unconditionally we also set
attach_prog_fd to bogus value and kernel fails the load
because it tries to look it up.

Setting kern_version only for programs other than TRACING/EXT
type.

Signed-off-by: Jiri Olsa <jolsa@kernel.org>
  • Loading branch information
olsajiri authored and yonghong-song committed Feb 27, 2020
1 parent 1e7862f commit 550706a
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 2 deletions.
5 changes: 4 additions & 1 deletion src/cc/bpf_module.cc
Expand Up @@ -907,7 +907,10 @@ int BPFModule::bcc_func_load(int prog_type, const char *name,
attr.name = name;
attr.insns = insns;
attr.license = license;
attr.kern_version = kern_version;
if (attr.prog_type != BPF_PROG_TYPE_TRACING &&
attr.prog_type != BPF_PROG_TYPE_EXT) {
attr.kern_version = kern_version;
}
attr.log_level = log_level;
if (dev_name)
attr.prog_ifindex = if_nametoindex(dev_name);
Expand Down
3 changes: 2 additions & 1 deletion src/cc/libbpf.c
Expand Up @@ -671,7 +671,8 @@ int bcc_prog_load(enum bpf_prog_type prog_type, const char *name,
attr.name = name;
attr.insns = insns;
attr.license = license;
attr.kern_version = kern_version;
if (prog_type != BPF_PROG_TYPE_TRACING && prog_type != BPF_PROG_TYPE_EXT)
attr.kern_version = kern_version;
attr.log_level = log_level;
return bcc_prog_load_xattr(&attr, prog_len, log_buf, log_buf_size, true);
}
Expand Down

0 comments on commit 550706a

Please sign in to comment.