Commit fb55158
bpf: Refactor btf_kfunc_id_set_contains
btf_kfunc_id_set_contains() is called by fetch_kfunc_meta() in the BPF
verifier to get the kfunc flags stored in the .BTF_ids ELF section.
If it returns NULL instead of a valid pointer, it's interpreted by the
verifier as an illegal kfunc usage which fails the verification.
Conceptually, there are two potential reasons for
btf_kfunc_id_set_contains() to return NULL:
1. Provided kfunc BTF id is not present in relevant kfunc id sets.
2. The kfunc is not allowed, as determined by the program type
specific filter [1].
The filter functions accept a pointer to `struct bpf_prog`, so they
might implicitly depend on earlier stages of verification, when
bpf_prog members are set.
For example, bpf_qdisc_kfunc_filter() in linux/net/sched/bpf_qdisc.c
inspects prog->aux->st_ops [2], which is initialized in:
check_attach_btf_id() -> check_struct_ops_btf_id()
So far this hasn't been an issue, because fetch_kfunc_meta() is the
only place where lookup + filter logic is applied to a kfunc id.
However in subsequent patches of this series it is necessary to
inspect kfunc flags earlier in BPF verifier, in the add_kfunc_call().
To resolve this, refactor btf_kfunc_id_set_contains() into two
interface functions: btf_kfunc_flags() that does not apply the
filters, and btf_kfunc_flags_if_allowed() that does.
[1] https://lore.kernel.org/all/[email protected]/
[2] https://lore.kernel.org/all/[email protected]/
Signed-off-by: Ihor Solodrai <[email protected]>1 parent cb04cfa commit fb55158
3 files changed
+58
-20
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
575 | 575 | | |
576 | 576 | | |
577 | 577 | | |
578 | | - | |
579 | | - | |
| 578 | + | |
| 579 | + | |
| 580 | + | |
| 581 | + | |
580 | 582 | | |
581 | 583 | | |
582 | 584 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
8640 | 8640 | | |
8641 | 8641 | | |
8642 | 8642 | | |
8643 | | - | |
8644 | | - | |
8645 | | - | |
8646 | | - | |
| 8643 | + | |
| 8644 | + | |
| 8645 | + | |
8647 | 8646 | | |
8648 | | - | |
8649 | 8647 | | |
8650 | | - | |
| 8648 | + | |
8651 | 8649 | | |
8652 | 8650 | | |
8653 | 8651 | | |
8654 | 8652 | | |
8655 | 8653 | | |
8656 | | - | |
8657 | | - | |
8658 | | - | |
8659 | | - | |
8660 | | - | |
8661 | 8654 | | |
8662 | 8655 | | |
8663 | 8656 | | |
| |||
8668 | 8661 | | |
8669 | 8662 | | |
8670 | 8663 | | |
| 8664 | + | |
| 8665 | + | |
| 8666 | + | |
| 8667 | + | |
| 8668 | + | |
| 8669 | + | |
| 8670 | + | |
| 8671 | + | |
| 8672 | + | |
| 8673 | + | |
| 8674 | + | |
| 8675 | + | |
| 8676 | + | |
| 8677 | + | |
| 8678 | + | |
| 8679 | + | |
| 8680 | + | |
| 8681 | + | |
| 8682 | + | |
| 8683 | + | |
| 8684 | + | |
| 8685 | + | |
8671 | 8686 | | |
8672 | 8687 | | |
8673 | 8688 | | |
| |||
8721 | 8736 | | |
8722 | 8737 | | |
8723 | 8738 | | |
8724 | | - | |
8725 | | - | |
8726 | | - | |
| 8739 | + | |
8727 | 8740 | | |
8728 | 8741 | | |
8729 | 8742 | | |
8730 | 8743 | | |
8731 | 8744 | | |
8732 | | - | |
| 8745 | + | |
8733 | 8746 | | |
8734 | 8747 | | |
8735 | 8748 | | |
8736 | 8749 | | |
8737 | | - | |
| 8750 | + | |
| 8751 | + | |
| 8752 | + | |
| 8753 | + | |
| 8754 | + | |
| 8755 | + | |
| 8756 | + | |
| 8757 | + | |
| 8758 | + | |
| 8759 | + | |
| 8760 | + | |
| 8761 | + | |
| 8762 | + | |
| 8763 | + | |
| 8764 | + | |
| 8765 | + | |
| 8766 | + | |
| 8767 | + | |
| 8768 | + | |
| 8769 | + | |
| 8770 | + | |
8738 | 8771 | | |
8739 | 8772 | | |
8740 | 8773 | | |
8741 | 8774 | | |
8742 | 8775 | | |
8743 | | - | |
| 8776 | + | |
| 8777 | + | |
| 8778 | + | |
| 8779 | + | |
8744 | 8780 | | |
8745 | 8781 | | |
8746 | 8782 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
13631 | 13631 | | |
13632 | 13632 | | |
13633 | 13633 | | |
13634 | | - | |
| 13634 | + | |
13635 | 13635 | | |
13636 | 13636 | | |
13637 | 13637 | | |
| |||
0 commit comments