@@ -780,7 +780,10 @@ bool is_bpf_text_address(unsigned long addr)
780780
781781struct bpf_prog * bpf_prog_ksym_find (unsigned long addr )
782782{
783- struct bpf_ksym * ksym = bpf_ksym_find (addr );
783+ struct bpf_ksym * ksym ;
784+
785+ WARN_ON_ONCE (!rcu_read_lock_held ());
786+ ksym = bpf_ksym_find (addr );
784787
785788 return ksym && ksym -> prog ?
786789 container_of (ksym , struct bpf_prog_aux , ksym )-> prog :
@@ -2307,40 +2310,48 @@ static unsigned int __bpf_prog_ret0_warn(const void *ctx,
23072310 return 0 ;
23082311}
23092312
2310- bool bpf_prog_map_compatible (struct bpf_map * map ,
2311- const struct bpf_prog * fp )
2313+ static bool __bpf_prog_map_compatible (struct bpf_map * map ,
2314+ const struct bpf_prog * fp )
23122315{
23132316 enum bpf_prog_type prog_type = resolve_prog_type (fp );
2314- bool ret ;
23152317 struct bpf_prog_aux * aux = fp -> aux ;
2318+ enum bpf_cgroup_storage_type i ;
2319+ bool ret = false;
2320+ u64 cookie ;
23162321
23172322 if (fp -> kprobe_override )
2318- return false;
2319-
2320- /* XDP programs inserted into maps are not guaranteed to run on
2321- * a particular netdev (and can run outside driver context entirely
2322- * in the case of devmap and cpumap). Until device checks
2323- * are implemented, prohibit adding dev-bound programs to program maps.
2324- */
2325- if (bpf_prog_is_dev_bound (aux ))
2326- return false;
2323+ return ret ;
23272324
2328- spin_lock (& map -> owner .lock );
2329- if (!map -> owner .type ) {
2330- /* There's no owner yet where we could check for
2331- * compatibility.
2332- */
2333- map -> owner .type = prog_type ;
2334- map -> owner .jited = fp -> jited ;
2335- map -> owner .xdp_has_frags = aux -> xdp_has_frags ;
2336- map -> owner .attach_func_proto = aux -> attach_func_proto ;
2325+ spin_lock (& map -> owner_lock );
2326+ /* There's no owner yet where we could check for compatibility. */
2327+ if (!map -> owner ) {
2328+ map -> owner = bpf_map_owner_alloc (map );
2329+ if (!map -> owner )
2330+ goto err ;
2331+ map -> owner -> type = prog_type ;
2332+ map -> owner -> jited = fp -> jited ;
2333+ map -> owner -> xdp_has_frags = aux -> xdp_has_frags ;
2334+ map -> owner -> attach_func_proto = aux -> attach_func_proto ;
2335+ for_each_cgroup_storage_type (i ) {
2336+ map -> owner -> storage_cookie [i ] =
2337+ aux -> cgroup_storage [i ] ?
2338+ aux -> cgroup_storage [i ]-> cookie : 0 ;
2339+ }
23372340 ret = true;
23382341 } else {
2339- ret = map -> owner .type == prog_type &&
2340- map -> owner .jited == fp -> jited &&
2341- map -> owner .xdp_has_frags == aux -> xdp_has_frags ;
2342+ ret = map -> owner -> type == prog_type &&
2343+ map -> owner -> jited == fp -> jited &&
2344+ map -> owner -> xdp_has_frags == aux -> xdp_has_frags ;
2345+ for_each_cgroup_storage_type (i ) {
2346+ if (!ret )
2347+ break ;
2348+ cookie = aux -> cgroup_storage [i ] ?
2349+ aux -> cgroup_storage [i ]-> cookie : 0 ;
2350+ ret = map -> owner -> storage_cookie [i ] == cookie ||
2351+ !cookie ;
2352+ }
23422353 if (ret &&
2343- map -> owner . attach_func_proto != aux -> attach_func_proto ) {
2354+ map -> owner -> attach_func_proto != aux -> attach_func_proto ) {
23442355 switch (prog_type ) {
23452356 case BPF_PROG_TYPE_TRACING :
23462357 case BPF_PROG_TYPE_LSM :
@@ -2353,11 +2364,24 @@ bool bpf_prog_map_compatible(struct bpf_map *map,
23532364 }
23542365 }
23552366 }
2356- spin_unlock ( & map -> owner . lock );
2357-
2367+ err :
2368+ spin_unlock ( & map -> owner_lock );
23582369 return ret ;
23592370}
23602371
2372+ bool bpf_prog_map_compatible (struct bpf_map * map , const struct bpf_prog * fp )
2373+ {
2374+ /* XDP programs inserted into maps are not guaranteed to run on
2375+ * a particular netdev (and can run outside driver context entirely
2376+ * in the case of devmap and cpumap). Until device checks
2377+ * are implemented, prohibit adding dev-bound programs to program maps.
2378+ */
2379+ if (bpf_prog_is_dev_bound (fp -> aux ))
2380+ return false;
2381+
2382+ return __bpf_prog_map_compatible (map , fp );
2383+ }
2384+
23612385static int bpf_check_tail_call (const struct bpf_prog * fp )
23622386{
23632387 struct bpf_prog_aux * aux = fp -> aux ;
@@ -2370,7 +2394,7 @@ static int bpf_check_tail_call(const struct bpf_prog *fp)
23702394 if (!map_type_contains_progs (map ))
23712395 continue ;
23722396
2373- if (!bpf_prog_map_compatible (map , fp )) {
2397+ if (!__bpf_prog_map_compatible (map , fp )) {
23742398 ret = - EINVAL ;
23752399 goto out ;
23762400 }
@@ -2931,7 +2955,10 @@ EXPORT_SYMBOL_GPL(bpf_event_output);
29312955
29322956/* Always built-in helper functions. */
29332957const struct bpf_func_proto bpf_tail_call_proto = {
2934- .func = NULL,
2958+ /* func is unused for tail_call, we set it to pass the
2959+ * get_helper_proto check
2960+ */
2961+ .func = BPF_PTR_POISON ,
29352962 .gpl_only = false,
29362963 .ret_type = RET_VOID ,
29372964 .arg1_type = ARG_PTR_TO_CTX ,
0 commit comments