-
Notifications
You must be signed in to change notification settings - Fork 111
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
selftests/bpf: Add tests for raw_tp null handling
Ensure that trusted PTR_TO_BTF_ID accesses perform PROBE_MEM handling in raw_tp program. Without the previous fix, this selftest crashes the kernel due to a NULL-pointer dereference. Also ensure that dead code elimination does not kick in for checks on the pointer. Signed-off-by: Kumar Kartikeya Dwivedi <[email protected]>
- Loading branch information
Showing
4 changed files
with
62 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
// SPDX-License-Identifier: GPL-2.0 | ||
/* Copyright (c) 2024 Meta Platforms, Inc. and affiliates. */ | ||
|
||
#include <test_progs.h> | ||
#include "raw_tp_null.skel.h" | ||
|
||
void test_raw_tp_null(void) | ||
{ | ||
struct raw_tp_null *skel; | ||
|
||
skel = raw_tp_null__open_and_load(); | ||
if (!ASSERT_OK_PTR(skel, "raw_tp_null__open_and_load")) | ||
return; | ||
|
||
skel->bss->tid = gettid(); | ||
|
||
if (!ASSERT_OK(raw_tp_null__attach(skel), "raw_tp_null__attach")) | ||
goto end; | ||
|
||
ASSERT_OK(trigger_module_test_read(2), "trigger testmod read"); | ||
ASSERT_EQ(skel->bss->i, 3, "invocations"); | ||
|
||
end: | ||
raw_tp_null__destroy(skel); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
// SPDX-License-Identifier: GPL-2.0 | ||
/* Copyright (c) 2024 Meta Platforms, Inc. and affiliates. */ | ||
|
||
#include <vmlinux.h> | ||
#include <bpf/bpf_tracing.h> | ||
|
||
char _license[] SEC("license") = "GPL"; | ||
|
||
int tid; | ||
int i; | ||
|
||
SEC("tp_btf/bpf_testmod_test_raw_tp_null") | ||
int BPF_PROG(test_raw_tp_null, struct sk_buff *skb) | ||
{ | ||
if (bpf_get_current_task_btf()->pid == tid) { | ||
i = i + skb->mark + 1; | ||
|
||
/* If dead code elimination kicks in, the increment below will | ||
* be removed. For raw_tp programs, we mark input arguments as | ||
* PTR_MAYBE_NULL, so branch prediction should never kick in. | ||
*/ | ||
if (!skb) | ||
i += 2; | ||
} | ||
|
||
return 0; | ||
} |