xref: /linux/tools/testing/selftests/bpf/progs/raw_tp_null_fail.c (revision 35f301dd4551fa731db4834f915e8351838f6f19)
1*0da1955bSKumar Kartikeya Dwivedi // SPDX-License-Identifier: GPL-2.0
2*0da1955bSKumar Kartikeya Dwivedi /* Copyright (c) 2024 Meta Platforms, Inc. and affiliates. */
3*0da1955bSKumar Kartikeya Dwivedi 
4*0da1955bSKumar Kartikeya Dwivedi #include <vmlinux.h>
5*0da1955bSKumar Kartikeya Dwivedi #include <bpf/bpf_tracing.h>
6*0da1955bSKumar Kartikeya Dwivedi #include "bpf_misc.h"
7*0da1955bSKumar Kartikeya Dwivedi 
8*0da1955bSKumar Kartikeya Dwivedi char _license[] SEC("license") = "GPL";
9*0da1955bSKumar Kartikeya Dwivedi 
10*0da1955bSKumar Kartikeya Dwivedi /* Ensure module parameter has PTR_MAYBE_NULL */
11*0da1955bSKumar Kartikeya Dwivedi SEC("tp_btf/bpf_testmod_test_raw_tp_null")
12*0da1955bSKumar Kartikeya Dwivedi __failure __msg("R1 invalid mem access 'trusted_ptr_or_null_'")
test_raw_tp_null_bpf_testmod_test_raw_tp_null_arg_1(void * ctx)13*0da1955bSKumar Kartikeya Dwivedi int test_raw_tp_null_bpf_testmod_test_raw_tp_null_arg_1(void *ctx) {
14*0da1955bSKumar Kartikeya Dwivedi     asm volatile("r1 = *(u64 *)(r1 +0); r1 = *(u64 *)(r1 +0);" ::: __clobber_all);
15*0da1955bSKumar Kartikeya Dwivedi     return 0;
16*0da1955bSKumar Kartikeya Dwivedi }
17*0da1955bSKumar Kartikeya Dwivedi 
18*0da1955bSKumar Kartikeya Dwivedi /* Check NULL marking */
19*0da1955bSKumar Kartikeya Dwivedi SEC("tp_btf/sched_pi_setprio")
20*0da1955bSKumar Kartikeya Dwivedi __failure __msg("R1 invalid mem access 'trusted_ptr_or_null_'")
test_raw_tp_null_sched_pi_setprio_arg_2(void * ctx)21*0da1955bSKumar Kartikeya Dwivedi int test_raw_tp_null_sched_pi_setprio_arg_2(void *ctx) {
22*0da1955bSKumar Kartikeya Dwivedi     asm volatile("r1 = *(u64 *)(r1 +8); r1 = *(u64 *)(r1 +0);" ::: __clobber_all);
23*0da1955bSKumar Kartikeya Dwivedi     return 0;
24*0da1955bSKumar Kartikeya Dwivedi }
25