linux/tools/testing/selftests/bpf/progs/find_vma_fail2.c
Song Liu f108662b27 selftests/bpf: Add tests for bpf_find_vma
Add tests for bpf_find_vma in perf_event program and kprobe program. The
perf_event program is triggered from NMI context, so the second call of
bpf_find_vma() will return -EBUSY (irq_work busy). The kprobe program,
on the other hand, does not have this constraint.

Also add tests for illegal writes to task or vma from the callback
function. The verifier should reject both cases.

Signed-off-by: Song Liu <songliubraving@fb.com>
Signed-off-by: Alexei Starovoitov <ast@kernel.org>
Acked-by: Yonghong Song <yhs@fb.com>
Link: https://lore.kernel.org/bpf/20211105232330.1936330-3-songliubraving@fb.com
2021-11-07 11:54:51 -08:00

30 lines
587 B
C

// SPDX-License-Identifier: GPL-2.0
/* Copyright (c) 2021 Facebook */
#include "vmlinux.h"
#include <bpf/bpf_helpers.h>
char _license[] SEC("license") = "GPL";
struct callback_ctx {
int dummy;
};
static long write_task(struct task_struct *task, struct vm_area_struct *vma,
struct callback_ctx *data)
{
/* writing to task, which is illegal */
task->mm = NULL;
return 0;
}
SEC("raw_tp/sys_enter")
int handle_getpid(void)
{
struct task_struct *task = bpf_get_current_task_btf();
struct callback_ctx data = {};
bpf_find_vma(task, 0, write_task, &data, 0);
return 0;
}