File tree 3 files changed +13
-2
lines changed 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 {
1483
1483
bool xdp_has_frags ;
1484
1484
bool exception_cb ;
1485
1485
bool exception_boundary ;
1486
+ bool is_extended ; /* true if extended by freplace program */
1486
1487
struct bpf_arena * arena ;
1487
1488
/* BTF_KIND_FUNC_PROTO for valid attach_btf_id */
1488
1489
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,
951
951
if (IS_ERR (prog ))
952
952
return prog ;
953
953
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
+ */
955
960
bpf_prog_put (prog );
956
961
return ERR_PTR (- EINVAL );
957
962
}
Original file line number Diff line number Diff line change @@ -3219,8 +3219,11 @@ static void bpf_tracing_link_release(struct bpf_link *link)
3219
3219
bpf_trampoline_put (tr_link -> trampoline );
3220
3220
3221
3221
/* 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;
3223
3225
bpf_prog_put (tr_link -> tgt_prog );
3226
+ }
3224
3227
}
3225
3228
3226
3229
static void bpf_tracing_link_dealloc (struct bpf_link * link )
@@ -3450,6 +3453,8 @@ static int bpf_tracing_prog_attach(struct bpf_prog *prog,
3450
3453
if (prog -> aux -> dst_trampoline && tr != prog -> aux -> dst_trampoline )
3451
3454
/* we allocated a new trampoline, so free the old one */
3452
3455
bpf_trampoline_put (prog -> aux -> dst_trampoline );
3456
+ if (prog -> type == BPF_PROG_TYPE_EXT )
3457
+ tgt_prog -> aux -> is_extended = true;
3453
3458
3454
3459
prog -> aux -> dst_prog = NULL ;
3455
3460
prog -> aux -> dst_trampoline = NULL ;
You can’t perform that action at this time.
0 commit comments