Skip to content

Commit 259172b

Browse files
author
Alexei Starovoitov
committed
libbpf: Fix gen_loader assumption on number of programs.
libbpf's obj->nr_programs includes static and global functions. That number could be higher than the actual number of bpf programs going be loaded by gen_loader. Passing larger nr_programs to bpf_gen__init() doesn't hurt. Those exra stack slots will stay as zero. bpf_gen__finish() needs to check that actual number of progs that gen_loader saw is less than or equal to obj->nr_programs. Fixes: ba05fd3 ("libbpf: Perform map fd cleanup for gen_loader in case of error") Signed-off-by: Alexei Starovoitov <[email protected]>
1 parent 77ab714 commit 259172b

File tree

1 file changed

+3
-2
lines changed

1 file changed

+3
-2
lines changed

tools/lib/bpf/gen_loader.c

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -371,8 +371,9 @@ int bpf_gen__finish(struct bpf_gen *gen, int nr_progs, int nr_maps)
371371
{
372372
int i;
373373

374-
if (nr_progs != gen->nr_progs || nr_maps != gen->nr_maps) {
375-
pr_warn("progs/maps mismatch\n");
374+
if (nr_progs < gen->nr_progs || nr_maps != gen->nr_maps) {
375+
pr_warn("nr_progs %d/%d nr_maps %d/%d mismatch\n",
376+
nr_progs, gen->nr_progs, nr_maps, gen->nr_maps);
376377
gen->error = -EFAULT;
377378
return gen->error;
378379
}

0 commit comments

Comments
 (0)