1// SPDX-License-Identifier: GPL-2.0 2 3/* 4 * Copyright 2020 Google LLC. 5 */ 6 7#include <linux/bpf.h> 8#include <bpf/bpf_helpers.h> 9#include <bpf/bpf_tracing.h> 10 11char _license[] SEC("license") = "GPL"; 12 13static int sequence = 0; 14__s32 input_retval = 0; 15 16__u64 fentry_result = 0; 17SEC("fentry/bpf_modify_return_test") 18int BPF_PROG(fentry_test, int a, __u64 b) 19{ 20 sequence++; 21 fentry_result = (sequence == 1); 22 return 0; 23} 24 25__u64 fmod_ret_result = 0; 26SEC("fmod_ret/bpf_modify_return_test") 27int BPF_PROG(fmod_ret_test, int a, int *b, int ret) 28{ 29 sequence++; 30 /* This is the first fmod_ret program, the ret passed should be 0 */ 31 fmod_ret_result = (sequence == 2 && ret == 0); 32 return input_retval; 33} 34 35__u64 fexit_result = 0; 36SEC("fexit/bpf_modify_return_test") 37int BPF_PROG(fexit_test, int a, __u64 b, int ret) 38{ 39 sequence++; 40 /* If the input_reval is non-zero a successful modification should have 41 * occurred. 42 */ 43 if (input_retval) 44 fexit_result = (sequence == 3 && ret == input_retval); 45 else 46 fexit_result = (sequence == 3 && ret == 4); 47 48 return 0; 49} 50 51static int sequence2; 52 53__u64 fentry_result2 = 0; 54SEC("fentry/bpf_modify_return_test2") 55int BPF_PROG(fentry_test2, int a, int *b, short c, int d, void *e, char f, 56 int g) 57{ 58 sequence2++; 59 fentry_result2 = (sequence2 == 1); 60 return 0; 61} 62 63__u64 fmod_ret_result2 = 0; 64SEC("fmod_ret/bpf_modify_return_test2") 65int BPF_PROG(fmod_ret_test2, int a, int *b, short c, int d, void *e, char f, 66 int g, int ret) 67{ 68 sequence2++; 69 /* This is the first fmod_ret program, the ret passed should be 0 */ 70 fmod_ret_result2 = (sequence2 == 2 && ret == 0); 71 return input_retval; 72} 73 74__u64 fexit_result2 = 0; 75SEC("fexit/bpf_modify_return_test2") 76int BPF_PROG(fexit_test2, int a, int *b, short c, int d, void *e, char f, 77 int g, int ret) 78{ 79 sequence2++; 80 /* If the input_reval is non-zero a successful modification should have 81 * occurred. 82 */ 83 if (input_retval) 84 fexit_result2 = (sequence2 == 3 && ret == input_retval); 85 else 86 fexit_result2 = (sequence2 == 3 && ret == 29); 87 88 return 0; 89} 90