Skip to content

Commit

Permalink
selftests/bpf: Fix freplace_link segfault in tailcalls prog test
Browse files Browse the repository at this point in the history
There are two bpf_link__destroy(freplace_link) calls in
test_tailcall_bpf2bpf_freplace(). After the first bpf_link__destroy()
is called, if the following bpf_map_{update,delete}_elem() throws an
exception, it will jump to the "out" label and call bpf_link__destroy()
again, causing double free and eventually leading to a segfault.

Fix it by directly resetting freplace_link to NULL after the first
bpf_link__destroy() call.

Fixes: 021611d ("selftests/bpf: Add test to verify tailcall and freplace restrictions")
Signed-off-by: Tengda Wu <[email protected]>
Reviewed-by: Leon Hwang <[email protected]>
  • Loading branch information
Tengda Wu authored and Kernel Patches Daemon committed Jan 24, 2025
1 parent 8982824 commit 61b3bf8
Showing 1 changed file with 1 addition and 0 deletions.
1 change: 1 addition & 0 deletions tools/testing/selftests/bpf/prog_tests/tailcalls.c
Original file line number Diff line number Diff line change
Expand Up @@ -1602,6 +1602,7 @@ static void test_tailcall_bpf2bpf_freplace(void)
err = bpf_link__destroy(freplace_link);
if (!ASSERT_OK(err, "destroy link"))
goto out;
freplace_link = NULL;

/* OK to update prog_array map then delete element from the map. */

Expand Down

0 comments on commit 61b3bf8

Please sign in to comment.