@@ -25,50 +25,18 @@ EXPORT_SYMBOL(cgroup_bpf_enabled_key);
2525/* __always_inline is necessary to prevent indirect call through run_prog
2626 * function pointer.
2727 */
28- static __always_inline int
29- bpf_prog_run_array_cg_flags (const struct cgroup_bpf * cgrp ,
30- enum cgroup_bpf_attach_type atype ,
31- const void * ctx , bpf_prog_run_fn run_prog ,
32- int retval , u32 * ret_flags )
33- {
34- const struct bpf_prog_array_item * item ;
35- const struct bpf_prog * prog ;
36- const struct bpf_prog_array * array ;
37- struct bpf_run_ctx * old_run_ctx ;
38- struct bpf_cg_run_ctx run_ctx ;
39- u32 func_ret ;
40-
41- run_ctx .retval = retval ;
42- migrate_disable ();
43- rcu_read_lock ();
44- array = rcu_dereference (cgrp -> effective [atype ]);
45- item = & array -> items [0 ];
46- old_run_ctx = bpf_set_run_ctx (& run_ctx .run_ctx );
47- while ((prog = READ_ONCE (item -> prog ))) {
48- run_ctx .prog_item = item ;
49- func_ret = run_prog (prog , ctx );
50- if (!(func_ret & 1 ) && !IS_ERR_VALUE ((long )run_ctx .retval ))
51- run_ctx .retval = - EPERM ;
52- * (ret_flags ) |= (func_ret >> 1 );
53- item ++ ;
54- }
55- bpf_reset_run_ctx (old_run_ctx );
56- rcu_read_unlock ();
57- migrate_enable ();
58- return run_ctx .retval ;
59- }
60-
6128static __always_inline int
6229bpf_prog_run_array_cg (const struct cgroup_bpf * cgrp ,
6330 enum cgroup_bpf_attach_type atype ,
6431 const void * ctx , bpf_prog_run_fn run_prog ,
65- int retval )
32+ int retval , u32 * ret_flags )
6633{
6734 const struct bpf_prog_array_item * item ;
6835 const struct bpf_prog * prog ;
6936 const struct bpf_prog_array * array ;
7037 struct bpf_run_ctx * old_run_ctx ;
7138 struct bpf_cg_run_ctx run_ctx ;
39+ u32 func_ret ;
7240
7341 run_ctx .retval = retval ;
7442 migrate_disable ();
@@ -78,8 +46,11 @@ bpf_prog_run_array_cg(const struct cgroup_bpf *cgrp,
7846 old_run_ctx = bpf_set_run_ctx (& run_ctx .run_ctx );
7947 while ((prog = READ_ONCE (item -> prog ))) {
8048 run_ctx .prog_item = item ;
81- if (!run_prog (prog , ctx ) && !IS_ERR_VALUE ((long )run_ctx .retval ))
49+ func_ret = run_prog (prog , ctx );
50+ if (!(func_ret & 1 ) && !IS_ERR_VALUE ((long )run_ctx .retval ))
8251 run_ctx .retval = - EPERM ;
52+ if (ret_flags )
53+ * (ret_flags ) |= (func_ret >> 1 );
8354 item ++ ;
8455 }
8556 bpf_reset_run_ctx (old_run_ctx );
@@ -1144,9 +1115,8 @@ int __cgroup_bpf_run_filter_skb(struct sock *sk,
11441115 u32 flags = 0 ;
11451116 bool cn ;
11461117
1147- ret = bpf_prog_run_array_cg_flags (
1148- & cgrp -> bpf , atype ,
1149- skb , __bpf_prog_run_save_cb , 0 , & flags );
1118+ ret = bpf_prog_run_array_cg (& cgrp -> bpf , atype , skb ,
1119+ __bpf_prog_run_save_cb , 0 , & flags );
11501120
11511121 /* Return values of CGROUP EGRESS BPF programs are:
11521122 * 0: drop packet
@@ -1172,7 +1142,8 @@ int __cgroup_bpf_run_filter_skb(struct sock *sk,
11721142 ret = (cn ? NET_XMIT_DROP : ret );
11731143 } else {
11741144 ret = bpf_prog_run_array_cg (& cgrp -> bpf , atype ,
1175- skb , __bpf_prog_run_save_cb , 0 );
1145+ skb , __bpf_prog_run_save_cb , 0 ,
1146+ NULL );
11761147 if (ret && !IS_ERR_VALUE ((long )ret ))
11771148 ret = - EFAULT ;
11781149 }
@@ -1202,7 +1173,8 @@ int __cgroup_bpf_run_filter_sk(struct sock *sk,
12021173{
12031174 struct cgroup * cgrp = sock_cgroup_ptr (& sk -> sk_cgrp_data );
12041175
1205- return bpf_prog_run_array_cg (& cgrp -> bpf , atype , sk , bpf_prog_run , 0 );
1176+ return bpf_prog_run_array_cg (& cgrp -> bpf , atype , sk , bpf_prog_run , 0 ,
1177+ NULL );
12061178}
12071179EXPORT_SYMBOL (__cgroup_bpf_run_filter_sk );
12081180
@@ -1247,8 +1219,8 @@ int __cgroup_bpf_run_filter_sock_addr(struct sock *sk,
12471219 }
12481220
12491221 cgrp = sock_cgroup_ptr (& sk -> sk_cgrp_data );
1250- return bpf_prog_run_array_cg_flags (& cgrp -> bpf , atype ,
1251- & ctx , bpf_prog_run , 0 , flags );
1222+ return bpf_prog_run_array_cg (& cgrp -> bpf , atype , & ctx , bpf_prog_run ,
1223+ 0 , flags );
12521224}
12531225EXPORT_SYMBOL (__cgroup_bpf_run_filter_sock_addr );
12541226
@@ -1275,7 +1247,7 @@ int __cgroup_bpf_run_filter_sock_ops(struct sock *sk,
12751247 struct cgroup * cgrp = sock_cgroup_ptr (& sk -> sk_cgrp_data );
12761248
12771249 return bpf_prog_run_array_cg (& cgrp -> bpf , atype , sock_ops , bpf_prog_run ,
1278- 0 );
1250+ 0 , NULL );
12791251}
12801252EXPORT_SYMBOL (__cgroup_bpf_run_filter_sock_ops );
12811253
@@ -1292,7 +1264,8 @@ int __cgroup_bpf_check_dev_permission(short dev_type, u32 major, u32 minor,
12921264
12931265 rcu_read_lock ();
12941266 cgrp = task_dfl_cgroup (current );
1295- ret = bpf_prog_run_array_cg (& cgrp -> bpf , atype , & ctx , bpf_prog_run , 0 );
1267+ ret = bpf_prog_run_array_cg (& cgrp -> bpf , atype , & ctx , bpf_prog_run , 0 ,
1268+ NULL );
12961269 rcu_read_unlock ();
12971270
12981271 return ret ;
@@ -1457,7 +1430,8 @@ int __cgroup_bpf_run_filter_sysctl(struct ctl_table_header *head,
14571430
14581431 rcu_read_lock ();
14591432 cgrp = task_dfl_cgroup (current );
1460- ret = bpf_prog_run_array_cg (& cgrp -> bpf , atype , & ctx , bpf_prog_run , 0 );
1433+ ret = bpf_prog_run_array_cg (& cgrp -> bpf , atype , & ctx , bpf_prog_run , 0 ,
1434+ NULL );
14611435 rcu_read_unlock ();
14621436
14631437 kfree (ctx .cur_val );
@@ -1550,7 +1524,7 @@ int __cgroup_bpf_run_filter_setsockopt(struct sock *sk, int *level,
15501524
15511525 lock_sock (sk );
15521526 ret = bpf_prog_run_array_cg (& cgrp -> bpf , CGROUP_SETSOCKOPT ,
1553- & ctx , bpf_prog_run , 0 );
1527+ & ctx , bpf_prog_run , 0 , NULL );
15541528 release_sock (sk );
15551529
15561530 if (ret )
@@ -1650,7 +1624,7 @@ int __cgroup_bpf_run_filter_getsockopt(struct sock *sk, int level,
16501624
16511625 lock_sock (sk );
16521626 ret = bpf_prog_run_array_cg (& cgrp -> bpf , CGROUP_GETSOCKOPT ,
1653- & ctx , bpf_prog_run , retval );
1627+ & ctx , bpf_prog_run , retval , NULL );
16541628 release_sock (sk );
16551629
16561630 if (ret < 0 )
@@ -1699,7 +1673,7 @@ int __cgroup_bpf_run_filter_getsockopt_kern(struct sock *sk, int level,
16991673 */
17001674
17011675 ret = bpf_prog_run_array_cg (& cgrp -> bpf , CGROUP_GETSOCKOPT ,
1702- & ctx , bpf_prog_run , retval );
1676+ & ctx , bpf_prog_run , retval , NULL );
17031677 if (ret < 0 )
17041678 return ret ;
17051679
0 commit comments