test_d_path_check_rdonly_mem.c (717B)
1// SPDX-License-Identifier: GPL-2.0 2/* Copyright (c) 2022 Google */ 3 4#include "vmlinux.h" 5#include <bpf/bpf_helpers.h> 6#include <bpf/bpf_tracing.h> 7 8extern const int bpf_prog_active __ksym; 9 10SEC("fentry/security_inode_getattr") 11int BPF_PROG(d_path_check_rdonly_mem, struct path *path, struct kstat *stat, 12 __u32 request_mask, unsigned int query_flags) 13{ 14 void *active; 15 __u32 cpu; 16 17 cpu = bpf_get_smp_processor_id(); 18 active = (void *)bpf_per_cpu_ptr(&bpf_prog_active, cpu); 19 if (active) { 20 /* FAIL here! 'active' points to readonly memory. bpf helpers 21 * that update its arguments can not write into it. 22 */ 23 bpf_d_path(path, active, sizeof(int)); 24 } 25 return 0; 26} 27 28char _license[] SEC("license") = "GPL";