Linux kernel mirror (for testing)
git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel
os
linux
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
10char _license[] SEC("license") = "GPL";
11
12int err;
13void *user_ptr;
14
15SEC("lsm/file_open")
16__failure
17__msg("Unreleased reference id=")
18int 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
31SEC("xdp")
32__failure
33__msg("Expected a dynptr of type file as arg #0")
34int 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
43SEC("xdp")
44__failure
45__msg("Expected an initialized dynptr as arg #0")
46int 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}