Skip to content

libbpf: fix possible use-after-free for externs #9163

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 5 additions & 3 deletions tools/lib/bpf/libbpf.c
Original file line number Diff line number Diff line change
Expand Up @@ -597,7 +597,7 @@ struct extern_desc {
int sym_idx;
int btf_id;
int sec_btf_id;
const char *name;
char *name;
char *essent_name;
bool is_set;
bool is_weak;
Expand Down Expand Up @@ -4259,7 +4259,7 @@ static int bpf_object__collect_externs(struct bpf_object *obj)
return ext->btf_id;
}
t = btf__type_by_id(obj->btf, ext->btf_id);
ext->name = btf__name_by_offset(obj->btf, t->name_off);
ext->name = strdup(btf__name_by_offset(obj->btf, t->name_off));
ext->sym_idx = i;
ext->is_weak = ELF64_ST_BIND(sym->st_info) == STB_WEAK;

Expand Down Expand Up @@ -9138,8 +9138,10 @@ void bpf_object__close(struct bpf_object *obj)
zfree(&obj->btf_custom_path);
zfree(&obj->kconfig);

for (i = 0; i < obj->nr_extern; i++)
for (i = 0; i < obj->nr_extern; i++) {
zfree(&obj->externs[i].name);
zfree(&obj->externs[i].essent_name);
}

zfree(&obj->externs);
obj->nr_extern = 0;
Expand Down
Loading