@@ -692,6 +692,8 @@ static enum bpf_dynptr_type arg_to_dynptr_type(enum bpf_arg_type arg_type)
692692 return BPF_DYNPTR_TYPE_XDP;
693693 case DYNPTR_TYPE_SKB_META:
694694 return BPF_DYNPTR_TYPE_SKB_META;
695+ case DYNPTR_TYPE_FILE:
696+ return BPF_DYNPTR_TYPE_FILE;
695697 default:
696698 return BPF_DYNPTR_TYPE_INVALID;
697699 }
@@ -710,14 +712,16 @@ static enum bpf_type_flag get_dynptr_type_flag(enum bpf_dynptr_type type)
710712 return DYNPTR_TYPE_XDP;
711713 case BPF_DYNPTR_TYPE_SKB_META:
712714 return DYNPTR_TYPE_SKB_META;
715+ case BPF_DYNPTR_TYPE_FILE:
716+ return DYNPTR_TYPE_FILE;
713717 default:
714718 return 0;
715719 }
716720}
717721
718722static bool dynptr_type_refcounted(enum bpf_dynptr_type type)
719723{
720- return type == BPF_DYNPTR_TYPE_RINGBUF;
724+ return type == BPF_DYNPTR_TYPE_RINGBUF || type == BPF_DYNPTR_TYPE_FILE ;
721725}
722726
723727static void __mark_dynptr_reg(struct bpf_reg_state *reg,
@@ -12291,6 +12295,8 @@ enum special_kfunc_type {
1229112295 KF_bpf_res_spin_unlock,
1229212296 KF_bpf_res_spin_lock_irqsave,
1229312297 KF_bpf_res_spin_unlock_irqrestore,
12298+ KF_bpf_dynptr_from_file,
12299+ KF_bpf_dynptr_file_discard,
1229412300 KF___bpf_trap,
1229512301 KF_bpf_task_work_schedule_signal,
1229612302 KF_bpf_task_work_schedule_resume,
@@ -12363,6 +12369,8 @@ BTF_ID(func, bpf_res_spin_lock)
1236312369BTF_ID(func, bpf_res_spin_unlock)
1236412370BTF_ID(func, bpf_res_spin_lock_irqsave)
1236512371BTF_ID(func, bpf_res_spin_unlock_irqrestore)
12372+ BTF_ID(func, bpf_dynptr_from_file)
12373+ BTF_ID(func, bpf_dynptr_file_discard)
1236612374BTF_ID(func, __bpf_trap)
1236712375BTF_ID(func, bpf_task_work_schedule_signal)
1236812376BTF_ID(func, bpf_task_work_schedule_resume)
@@ -13326,6 +13334,11 @@ static int check_kfunc_args(struct bpf_verifier_env *env, struct bpf_kfunc_call_
1332613334 dynptr_arg_type |= DYNPTR_TYPE_XDP;
1332713335 } else if (meta->func_id == special_kfunc_list[KF_bpf_dynptr_from_skb_meta]) {
1332813336 dynptr_arg_type |= DYNPTR_TYPE_SKB_META;
13337+ } else if (meta->func_id == special_kfunc_list[KF_bpf_dynptr_from_file]) {
13338+ dynptr_arg_type |= DYNPTR_TYPE_FILE;
13339+ } else if (meta->func_id == special_kfunc_list[KF_bpf_dynptr_file_discard]) {
13340+ dynptr_arg_type |= DYNPTR_TYPE_FILE;
13341+ meta->release_regno = regno;
1332913342 } else if (meta->func_id == special_kfunc_list[KF_bpf_dynptr_clone] &&
1333013343 (dynptr_arg_type & MEM_UNINIT)) {
1333113344 enum bpf_dynptr_type parent_type = meta->initialized_dynptr.type;
@@ -14006,12 +14019,18 @@ static int check_kfunc_call(struct bpf_verifier_env *env, struct bpf_insn *insn,
1400614019 * PTR_TO_BTF_ID in bpf_kfunc_arg_meta, do the release now.
1400714020 */
1400814021 if (meta.release_regno) {
14009- err = release_reference(env, regs[meta.release_regno].ref_obj_id);
14010- if (err) {
14011- verbose(env, "kfunc %s#%d reference has not been acquired before\n",
14012- func_name, meta.func_id);
14013- return err;
14022+ struct bpf_reg_state *reg = ®s[meta.release_regno];
14023+
14024+ if (meta.initialized_dynptr.ref_obj_id) {
14025+ err = unmark_stack_slots_dynptr(env, reg);
14026+ } else {
14027+ err = release_reference(env, reg->ref_obj_id);
14028+ if (err)
14029+ verbose(env, "kfunc %s#%d reference has not been acquired before\n",
14030+ func_name, meta.func_id);
1401414031 }
14032+ if (err)
14033+ return err;
1401514034 }
1401614035
1401714036 if (meta.func_id == special_kfunc_list[KF_bpf_list_push_front_impl] ||
0 commit comments