File: read_vsyscall.c

package info (click to toggle)
linux 6.12.27-1
  • links: PTS, VCS
  • area: main
  • in suites: sid
  • size: 1,674,652 kB
  • sloc: ansic: 25,905,246; asm: 269,514; sh: 136,573; python: 64,834; makefile: 55,708; perl: 38,062; xml: 19,283; cpp: 5,895; yacc: 4,927; lex: 2,939; awk: 1,594; sed: 28; ruby: 25
file content (52 lines) | stat: -rw-r--r-- 1,412 bytes parent folder | download | duplicates (6)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
// SPDX-License-Identifier: GPL-2.0
/* Copyright (C) 2024. Huawei Technologies Co., Ltd */
#include "vmlinux.h"
#include <linux/types.h>
#include <bpf/bpf_helpers.h>

#include "bpf_misc.h"

int target_pid = 0;
void *user_ptr = 0;
int read_ret[9];

char _license[] SEC("license") = "GPL";

/*
 * This is the only kfunc, the others are helpers
 */
int bpf_copy_from_user_str(void *dst, u32, const void *, u64) __weak __ksym;

SEC("fentry/" SYS_PREFIX "sys_nanosleep")
int do_probe_read(void *ctx)
{
	char buf[8];

	if ((bpf_get_current_pid_tgid() >> 32) != target_pid)
		return 0;

	read_ret[0] = bpf_probe_read_kernel(buf, sizeof(buf), user_ptr);
	read_ret[1] = bpf_probe_read_kernel_str(buf, sizeof(buf), user_ptr);
	read_ret[2] = bpf_probe_read(buf, sizeof(buf), user_ptr);
	read_ret[3] = bpf_probe_read_str(buf, sizeof(buf), user_ptr);
	read_ret[4] = bpf_probe_read_user(buf, sizeof(buf), user_ptr);
	read_ret[5] = bpf_probe_read_user_str(buf, sizeof(buf), user_ptr);

	return 0;
}

SEC("fentry.s/" SYS_PREFIX "sys_nanosleep")
int do_copy_from_user(void *ctx)
{
	char buf[8];

	if ((bpf_get_current_pid_tgid() >> 32) != target_pid)
		return 0;

	read_ret[6] = bpf_copy_from_user(buf, sizeof(buf), user_ptr);
	read_ret[7] = bpf_copy_from_user_task(buf, sizeof(buf), user_ptr,
					      bpf_get_current_task_btf(), 0);
	read_ret[8] = bpf_copy_from_user_str((char *)buf, sizeof(buf), user_ptr, 0);

	return 0;
}