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

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

Version: ~ [ linux-6.11-rc3 ] ~ [ linux-6.10.4 ] ~ [ linux-6.9.12 ] ~ [ linux-6.8.12 ] ~ [ linux-6.7.12 ] ~ [ linux-6.6.45 ] ~ [ linux-6.5.13 ] ~ [ linux-6.4.16 ] ~ [ linux-6.3.13 ] ~ [ linux-6.2.16 ] ~ [ linux-6.1.104 ] ~ [ linux-6.0.19 ] ~ [ linux-5.19.17 ] ~ [ linux-5.18.19 ] ~ [ linux-5.17.15 ] ~ [ linux-5.16.20 ] ~ [ linux-5.15.164 ] ~ [ linux-5.14.21 ] ~ [ linux-5.13.19 ] ~ [ linux-5.12.19 ] ~ [ linux-5.11.22 ] ~ [ linux-5.10.223 ] ~ [ linux-5.9.16 ] ~ [ linux-5.8.18 ] ~ [ linux-5.7.19 ] ~ [ linux-5.6.19 ] ~ [ linux-5.5.19 ] ~ [ linux-5.4.281 ] ~ [ linux-5.3.18 ] ~ [ linux-5.2.21 ] ~ [ linux-5.1.21 ] ~ [ linux-5.0.21 ] ~ [ linux-4.20.17 ] ~ [ linux-4.19.319 ] ~ [ 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 /* Copyright (C) 2023 Chuyi Zhou <zhouchuyi@bytedance.com> */
  3 
  4 #include "vmlinux.h"
  5 #include <bpf/bpf_helpers.h>
  6 #include <bpf/bpf_tracing.h>
  7 #include "bpf_misc.h"
  8 #include "bpf_experimental.h"
  9 
 10 char _license[] SEC("license") = "GPL";
 11 
 12 struct cgroup *bpf_cgroup_from_id(u64 cgid) __ksym;
 13 void bpf_cgroup_release(struct cgroup *p) __ksym;
 14 void bpf_rcu_read_lock(void) __ksym;
 15 void bpf_rcu_read_unlock(void) __ksym;
 16 
 17 SEC("?fentry.s/" SYS_PREFIX "sys_getpgid")
 18 __failure __msg("expected an RCU CS when using bpf_iter_task_next")
 19 int BPF_PROG(iter_tasks_without_lock)
 20 {
 21         struct task_struct *pos;
 22 
 23         bpf_for_each(task, pos, NULL, BPF_TASK_ITER_ALL_PROCS) {
 24 
 25         }
 26         return 0;
 27 }
 28 
 29 SEC("?fentry.s/" SYS_PREFIX "sys_getpgid")
 30 __failure __msg("expected an RCU CS when using bpf_iter_css_next")
 31 int BPF_PROG(iter_css_without_lock)
 32 {
 33         u64 cg_id = bpf_get_current_cgroup_id();
 34         struct cgroup *cgrp = bpf_cgroup_from_id(cg_id);
 35         struct cgroup_subsys_state *root_css, *pos;
 36 
 37         if (!cgrp)
 38                 return 0;
 39         root_css = &cgrp->self;
 40 
 41         bpf_for_each(css, pos, root_css, BPF_CGROUP_ITER_DESCENDANTS_POST) {
 42 
 43         }
 44         bpf_cgroup_release(cgrp);
 45         return 0;
 46 }
 47 
 48 SEC("?fentry.s/" SYS_PREFIX "sys_getpgid")
 49 __failure __msg("expected an RCU CS when using bpf_iter_task_next")
 50 int BPF_PROG(iter_tasks_lock_and_unlock)
 51 {
 52         struct task_struct *pos;
 53 
 54         bpf_rcu_read_lock();
 55         bpf_for_each(task, pos, NULL, BPF_TASK_ITER_ALL_PROCS) {
 56                 bpf_rcu_read_unlock();
 57 
 58                 bpf_rcu_read_lock();
 59         }
 60         bpf_rcu_read_unlock();
 61         return 0;
 62 }
 63 
 64 SEC("?fentry.s/" SYS_PREFIX "sys_getpgid")
 65 __failure __msg("expected an RCU CS when using bpf_iter_css_next")
 66 int BPF_PROG(iter_css_lock_and_unlock)
 67 {
 68         u64 cg_id = bpf_get_current_cgroup_id();
 69         struct cgroup *cgrp = bpf_cgroup_from_id(cg_id);
 70         struct cgroup_subsys_state *root_css, *pos;
 71 
 72         if (!cgrp)
 73                 return 0;
 74         root_css = &cgrp->self;
 75 
 76         bpf_rcu_read_lock();
 77         bpf_for_each(css, pos, root_css, BPF_CGROUP_ITER_DESCENDANTS_POST) {
 78                 bpf_rcu_read_unlock();
 79 
 80                 bpf_rcu_read_lock();
 81         }
 82         bpf_rcu_read_unlock();
 83         bpf_cgroup_release(cgrp);
 84         return 0;
 85 }
 86 
 87 SEC("?fentry/" SYS_PREFIX "sys_getpgid")
 88 __failure __msg("css_task_iter is only allowed in bpf_lsm, bpf_iter and sleepable progs")
 89 int BPF_PROG(iter_css_task_for_each)
 90 {
 91         u64 cg_id = bpf_get_current_cgroup_id();
 92         struct cgroup *cgrp = bpf_cgroup_from_id(cg_id);
 93         struct cgroup_subsys_state *css;
 94         struct task_struct *task;
 95 
 96         if (cgrp == NULL)
 97                 return 0;
 98         css = &cgrp->self;
 99 
100         bpf_for_each(css_task, task, css, CSS_TASK_ITER_PROCS) {
101 
102         }
103         bpf_cgroup_release(cgrp);
104         return 0;
105 }
106 

~ [ 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