Skip to content

Commit

Permalink
bpf: verifier: Support KF_CHANGES_PKT flag
Browse files Browse the repository at this point in the history
KF_CHANGES_PKT indicates that the kfunc call may change packet data.
This is analogous to bpf_helper_changes_pkt_data().

Signed-off-by: Daniel Xu <dxu@dxuuu.xyz>
  • Loading branch information
danobi authored and intel-lab-lkp committed Dec 14, 2022
1 parent ff214d3 commit ca42b5d
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 0 deletions.
7 changes: 7 additions & 0 deletions Documentation/bpf/kfuncs.rst
Expand Up @@ -200,6 +200,13 @@ single argument which must be a trusted argument or a MEM_RCU pointer.
The argument may have reference count of 0 and the kfunc must take this
into consideration.

2.4.9 KF_CHANGES_PKT flag
-----------------

The KF_CHANGES_PKT is used for kfuncs that may change packet data.
After calls to such kfuncs, existing packet pointers will be invalidated
and must be revalidated before the prog can access packet data.

2.5 Registering the kfuncs
--------------------------

Expand Down
1 change: 1 addition & 0 deletions include/linux/btf.h
Expand Up @@ -71,6 +71,7 @@
#define KF_SLEEPABLE (1 << 5) /* kfunc may sleep */
#define KF_DESTRUCTIVE (1 << 6) /* kfunc performs destructive actions */
#define KF_RCU (1 << 7) /* kfunc only takes rcu pointer arguments */
#define KF_CHANGES_PKT (1 << 8) /* kfunc may change packet data */

/*
* Return the name of the passed struct, if exists, or halt the build if for
Expand Down
8 changes: 8 additions & 0 deletions kernel/bpf/verifier.c
Expand Up @@ -8213,6 +8213,11 @@ static bool is_kfunc_rcu(struct bpf_kfunc_call_arg_meta *meta)
return meta->kfunc_flags & KF_RCU;
}

static bool is_kfunc_changes_pkt(struct bpf_kfunc_call_arg_meta *meta)
{
return meta->kfunc_flags & KF_CHANGES_PKT;
}

static bool is_kfunc_arg_kptr_get(struct bpf_kfunc_call_arg_meta *meta, int arg)
{
return arg == 0 && (meta->kfunc_flags & KF_KPTR_GET);
Expand Down Expand Up @@ -9313,6 +9318,9 @@ static int check_kfunc_call(struct bpf_verifier_env *env, struct bpf_insn *insn,
mark_btf_func_reg_size(env, regno, t->size);
}

if (is_kfunc_changes_pkt(&meta))
clear_all_pkt_pointers(env);

return 0;
}

Expand Down

0 comments on commit ca42b5d

Please sign in to comment.