FILE
tailcall_fail.c
File preview with syntax highlighting.
linux-6.19.14/tools/testing/selftests/bpf/progs/tailcall_fail.c
1// SPDX-License-Identifier: GPL-2.0 2/* Copyright (c) 2024 Meta Platforms, Inc. and affiliates. */ 3#include <vmlinux.h> 4#include <bpf/bpf_tracing.h> 5#include <bpf/bpf_helpers.h> 6#include <bpf/bpf_core_read.h> 7 8#include "bpf_misc.h" 9#include "bpf_experimental.h" 10 11extern void bpf_rcu_read_lock(void) __ksym; 12extern void bpf_rcu_read_unlock(void) __ksym; 13 14#define private(name) SEC(".bss." #name) __hidden __attribute__((aligned(8))) 15 16private(A) struct bpf_spin_lock lock; 17 18struct { 19 __uint(type, BPF_MAP_TYPE_PROG_ARRAY); 20 __uint(max_entries, 3); 21 __uint(key_size, sizeof(__u32)); 22 __uint(value_size, sizeof(__u32)); 23} jmp_table SEC(".maps"); 24 25SEC("?tc") 26__failure __msg("function calls are not allowed while holding a lock") 27int reject_tail_call_spin_lock(struct __sk_buff *ctx) 28{ 29 bpf_spin_lock(&lock); 30 bpf_tail_call_static(ctx, &jmp_table, 0); 31 return 0; 32} 33 34SEC("?tc") 35__failure __msg("tail_call cannot be used inside bpf_rcu_read_lock-ed region") 36int reject_tail_call_rcu_lock(struct __sk_buff *ctx) 37{ 38 bpf_rcu_read_lock(); 39 bpf_tail_call_static(ctx, &jmp_table, 0); 40 bpf_rcu_read_unlock(); 41 return 0; 42} 43 44SEC("?tc") 45__failure __msg("tail_call cannot be used inside bpf_preempt_disable-ed region") 46int reject_tail_call_preempt_lock(struct __sk_buff *ctx) 47{ 48 bpf_guard_preempt(); 49 bpf_tail_call_static(ctx, &jmp_table, 0); 50 return 0; 51} 52 53SEC("?tc") 54__failure __msg("tail_call would lead to reference leak") 55int reject_tail_call_ref(struct __sk_buff *ctx) 56{ 57 struct foo { int i; } *p; 58 59 p = bpf_obj_new(typeof(*p)); 60 bpf_tail_call_static(ctx, &jmp_table, 0); 61 return 0; 62} 63 64char _license[] SEC("license") = "GPL";
~/
Read-only file preview.