Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

at master 44 lines 1.0 kB view raw
1// SPDX-License-Identifier: GPL-2.0 2 3#include "vmlinux.h" 4#include <errno.h> 5#include <bpf/bpf_helpers.h> 6#include <bpf/bpf_tracing.h> 7 8char _license[] SEC("license") = "GPL"; 9 10extern bool CONFIG_PREEMPTION __kconfig __weak; 11int nr_get_errs = 0; 12int nr_del_errs = 0; 13 14struct { 15 __uint(type, BPF_MAP_TYPE_TASK_STORAGE); 16 __uint(map_flags, BPF_F_NO_PREALLOC); 17 __type(key, int); 18 __type(value, int); 19} task_storage SEC(".maps"); 20 21SEC("lsm.s/socket_post_create") 22int BPF_PROG(socket_post_create, struct socket *sock, int family, int type, 23 int protocol, int kern) 24{ 25 struct task_struct *task; 26 int ret, zero = 0; 27 int *value; 28 29 if (!CONFIG_PREEMPTION) 30 return 0; 31 32 task = bpf_get_current_task_btf(); 33 value = bpf_task_storage_get(&task_storage, task, &zero, 34 BPF_LOCAL_STORAGE_GET_F_CREATE); 35 if (!value) 36 __sync_fetch_and_add(&nr_get_errs, 1); 37 38 ret = bpf_task_storage_delete(&task_storage, 39 bpf_get_current_task_btf()); 40 if (ret == -EDEADLK || ret == -ETIMEDOUT) 41 __sync_fetch_and_add(&nr_del_errs, 1); 42 43 return 0; 44}