File tree Expand file tree Collapse file tree 3 files changed +13
-2
lines changed Expand file tree Collapse file tree 3 files changed +13
-2
lines changed Original file line number Diff line number Diff line change @@ -1483,6 +1483,7 @@ struct bpf_prog_aux {
14831483 bool xdp_has_frags ;
14841484 bool exception_cb ;
14851485 bool exception_boundary ;
1486+ bool is_extended ; /* true if extended by freplace program */
14861487 struct bpf_arena * arena ;
14871488 /* BTF_KIND_FUNC_PROTO for valid attach_btf_id */
14881489 const struct btf_type * attach_func_proto ;
Original file line number Diff line number Diff line change @@ -951,7 +951,12 @@ static void *prog_fd_array_get_ptr(struct bpf_map *map,
951951 if (IS_ERR (prog ))
952952 return prog ;
953953
954- if (!bpf_prog_map_compatible (map , prog )) {
954+ if (!bpf_prog_map_compatible (map , prog ) || prog -> aux -> is_extended ) {
955+ /* Extended prog can not be tail callee. It's to prevent a
956+ * potential infinite loop like:
957+ * tail callee prog entry -> tail callee prog subprog ->
958+ * freplace prog entry --tailcall-> tail callee prog entry.
959+ */
955960 bpf_prog_put (prog );
956961 return ERR_PTR (- EINVAL );
957962 }
Original file line number Diff line number Diff line change @@ -3219,8 +3219,11 @@ static void bpf_tracing_link_release(struct bpf_link *link)
32193219 bpf_trampoline_put (tr_link -> trampoline );
32203220
32213221 /* tgt_prog is NULL if target is a kernel function */
3222- if (tr_link -> tgt_prog )
3222+ if (tr_link -> tgt_prog ) {
3223+ if (link -> prog -> type == BPF_PROG_TYPE_EXT )
3224+ tr_link -> tgt_prog -> aux -> is_extended = false;
32233225 bpf_prog_put (tr_link -> tgt_prog );
3226+ }
32243227}
32253228
32263229static void bpf_tracing_link_dealloc (struct bpf_link * link )
@@ -3450,6 +3453,8 @@ static int bpf_tracing_prog_attach(struct bpf_prog *prog,
34503453 if (prog -> aux -> dst_trampoline && tr != prog -> aux -> dst_trampoline )
34513454 /* we allocated a new trampoline, so free the old one */
34523455 bpf_trampoline_put (prog -> aux -> dst_trampoline );
3456+ if (prog -> type == BPF_PROG_TYPE_EXT )
3457+ tgt_prog -> aux -> is_extended = true;
34533458
34543459 prog -> aux -> dst_prog = NULL ;
34553460 prog -> aux -> dst_trampoline = NULL ;
You can’t perform that action at this time.
0 commit comments