~ [ source navigation ] ~ [ diff markup ] ~ [ identifier search ] ~

TOMOYO Linux Cross Reference
Linux/tools/testing/selftests/bpf/progs/test_d_path.c

Version: ~ [ linux-6.12-rc7 ] ~ [ linux-6.11.7 ] ~ [ linux-6.10.14 ] ~ [ linux-6.9.12 ] ~ [ linux-6.8.12 ] ~ [ linux-6.7.12 ] ~ [ linux-6.6.60 ] ~ [ linux-6.5.13 ] ~ [ linux-6.4.16 ] ~ [ linux-6.3.13 ] ~ [ linux-6.2.16 ] ~ [ linux-6.1.116 ] ~ [ linux-6.0.19 ] ~ [ linux-5.19.17 ] ~ [ linux-5.18.19 ] ~ [ linux-5.17.15 ] ~ [ linux-5.16.20 ] ~ [ linux-5.15.171 ] ~ [ linux-5.14.21 ] ~ [ linux-5.13.19 ] ~ [ linux-5.12.19 ] ~ [ linux-5.11.22 ] ~ [ linux-5.10.229 ] ~ [ linux-5.9.16 ] ~ [ linux-5.8.18 ] ~ [ linux-5.7.19 ] ~ [ linux-5.6.19 ] ~ [ linux-5.5.19 ] ~ [ linux-5.4.285 ] ~ [ linux-5.3.18 ] ~ [ linux-5.2.21 ] ~ [ linux-5.1.21 ] ~ [ linux-5.0.21 ] ~ [ linux-4.20.17 ] ~ [ linux-4.19.323 ] ~ [ linux-4.18.20 ] ~ [ linux-4.17.19 ] ~ [ linux-4.16.18 ] ~ [ linux-4.15.18 ] ~ [ linux-4.14.336 ] ~ [ linux-4.13.16 ] ~ [ linux-4.12.14 ] ~ [ linux-4.11.12 ] ~ [ linux-4.10.17 ] ~ [ linux-4.9.337 ] ~ [ linux-4.4.302 ] ~ [ linux-3.10.108 ] ~ [ linux-2.6.32.71 ] ~ [ linux-2.6.0 ] ~ [ linux-2.4.37.11 ] ~ [ unix-v6-master ] ~ [ ccs-tools-1.8.9 ] ~ [ policy-sample ] ~
Architecture: ~ [ i386 ] ~ [ alpha ] ~ [ m68k ] ~ [ mips ] ~ [ ppc ] ~ [ sparc ] ~ [ sparc64 ] ~

  1 // SPDX-License-Identifier: GPL-2.0
  2 
  3 #include "vmlinux.h"
  4 #include <bpf/bpf_helpers.h>
  5 #include <bpf/bpf_tracing.h>
  6 
  7 #define MAX_PATH_LEN            128
  8 #define MAX_FILES               7
  9 
 10 pid_t my_pid = 0;
 11 __u32 cnt_stat = 0;
 12 __u32 cnt_close = 0;
 13 char paths_stat[MAX_FILES][MAX_PATH_LEN] = {};
 14 char paths_close[MAX_FILES][MAX_PATH_LEN] = {};
 15 int rets_stat[MAX_FILES] = {};
 16 int rets_close[MAX_FILES] = {};
 17 
 18 int called_stat = 0;
 19 int called_close = 0;
 20 
 21 SEC("fentry/security_inode_getattr")
 22 int BPF_PROG(prog_stat, struct path *path, struct kstat *stat,
 23              __u32 request_mask, unsigned int query_flags)
 24 {
 25         pid_t pid = bpf_get_current_pid_tgid() >> 32;
 26         __u32 cnt = cnt_stat;
 27         int ret;
 28 
 29         called_stat = 1;
 30 
 31         if (pid != my_pid)
 32                 return 0;
 33 
 34         if (cnt >= MAX_FILES)
 35                 return 0;
 36         ret = bpf_d_path(path, paths_stat[cnt], MAX_PATH_LEN);
 37 
 38         rets_stat[cnt] = ret;
 39         cnt_stat++;
 40         return 0;
 41 }
 42 
 43 SEC("fentry/filp_close")
 44 int BPF_PROG(prog_close, struct file *file, void *id)
 45 {
 46         pid_t pid = bpf_get_current_pid_tgid() >> 32;
 47         __u32 cnt = cnt_close;
 48         int ret;
 49 
 50         called_close = 1;
 51 
 52         if (pid != my_pid)
 53                 return 0;
 54 
 55         if (cnt >= MAX_FILES)
 56                 return 0;
 57         ret = bpf_d_path(&file->f_path,
 58                          paths_close[cnt], MAX_PATH_LEN);
 59 
 60         rets_close[cnt] = ret;
 61         cnt_close++;
 62         return 0;
 63 }
 64 
 65 char _license[] SEC("license") = "GPL";
 66 

~ [ source navigation ] ~ [ diff markup ] ~ [ identifier search ] ~

kernel.org | git.kernel.org | LWN.net | Project Home | SVN repository | Mail admin

Linux® is a registered trademark of Linus Torvalds in the United States and other countries.
TOMOYO® is a registered trademark of NTT DATA CORPORATION.

sflogo.php