1 // SPDX-License-Identifier: GPL-2.0 2 /* Copyright (c) 2025 Meta Platforms, Inc. and affiliates. */ 3 4 #include <vmlinux.h> 5 #include <string.h> 6 #include <stdbool.h> 7 #include <bpf/bpf_tracing.h> 8 #include "bpf_misc.h" 9 10 char _license[] SEC("license") = "GPL"; 11 12 int err; 13 void *user_ptr; 14 15 SEC("lsm/file_open") 16 __failure 17 __msg("Unreleased reference id=") 18 int on_nanosleep_unreleased_ref(void *ctx) 19 { 20 struct task_struct *task = bpf_get_current_task_btf(); 21 struct file *file = bpf_get_task_exe_file(task); 22 struct bpf_dynptr dynptr; 23 24 if (!file) 25 return 0; 26 27 err = bpf_dynptr_from_file(file, 0, &dynptr); 28 return err ? 1 : 0; 29 } 30 31 SEC("xdp") 32 __failure 33 __msg("Expected a dynptr of type file as arg #0") 34 int xdp_wrong_dynptr_type(struct xdp_md *xdp) 35 { 36 struct bpf_dynptr dynptr; 37 38 bpf_dynptr_from_xdp(xdp, 0, &dynptr); 39 bpf_dynptr_file_discard(&dynptr); 40 return 0; 41 } 42 43 SEC("xdp") 44 __failure 45 __msg("Expected an initialized dynptr as arg #0") 46 int xdp_no_dynptr_type(struct xdp_md *xdp) 47 { 48 struct bpf_dynptr dynptr; 49 50 bpf_dynptr_file_discard(&dynptr); 51 return 0; 52 } 53