Commit fca1aa7
bpf: Handle MEM_RCU type properly
Commit 9bb00b2 ("bpf: Add kfunc bpf_rcu_read_lock/unlock()")
introduced MEM_RCU and bpf_rcu_read_lock/unlock() support. In that
commit, a rcu pointer is tagged with both MEM_RCU and PTR_TRUSTED
so that it can be passed into kfuncs or helpers as an argument.
Martin raised a good question in [1] such that the rcu pointer,
although being able to accessing the object, might have reference
count of 0. This might cause a problem if the rcu pointer is passed
to a kfunc which expects trusted arguments where ref count should
be greater than 0.
This patch makes the following changes related to MEM_RCU pointer:
- MEM_RCU pointer might be NULL (PTR_MAYBE_NULL).
- Introduce KF_RCU so MEM_RCU ptr can be acquired with
a KF_RCU tagged kfunc which assumes ref count of rcu ptr
could be zero.
- For mem access 'b = ptr->a', say 'ptr' is a MEM_RCU ptr, and
'a' is tagged with __rcu as well. Let us mark 'b' as
MEM_RCU | PTR_MAYBE_NULL.
[1] https://lore.kernel.org/bpf/ac70f574-4023-664e-b711-e0d3b18117fd@linux.dev/
Fixes: 9bb00b2 ("bpf: Add kfunc bpf_rcu_read_lock/unlock()")
Signed-off-by: Yonghong Song <yhs@fb.com>
Link: https://lore.kernel.org/r/20221203184602.477272-1-yhs@fb.com
Signed-off-by: Alexei Starovoitov <ast@kernel.org>1 parent 7068194 commit fca1aa7
File tree
4 files changed
+48
-14
lines changed- include/linux
- kernel/bpf
4 files changed
+48
-14
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
682 | 682 | | |
683 | 683 | | |
684 | 684 | | |
685 | | - | |
| 685 | + | |
686 | 686 | | |
687 | 687 | | |
688 | 688 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
70 | 70 | | |
71 | 71 | | |
72 | 72 | | |
| 73 | + | |
73 | 74 | | |
74 | 75 | | |
75 | 76 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1837 | 1837 | | |
1838 | 1838 | | |
1839 | 1839 | | |
| 1840 | + | |
| 1841 | + | |
| 1842 | + | |
| 1843 | + | |
| 1844 | + | |
| 1845 | + | |
| 1846 | + | |
| 1847 | + | |
| 1848 | + | |
| 1849 | + | |
| 1850 | + | |
| 1851 | + | |
| 1852 | + | |
1840 | 1853 | | |
1841 | 1854 | | |
1842 | 1855 | | |
| |||
2013 | 2026 | | |
2014 | 2027 | | |
2015 | 2028 | | |
| 2029 | + | |
2016 | 2030 | | |
2017 | 2031 | | |
2018 | 2032 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
4275 | 4275 | | |
4276 | 4276 | | |
4277 | 4277 | | |
4278 | | - | |
| 4278 | + | |
4279 | 4279 | | |
4280 | 4280 | | |
4281 | 4281 | | |
| |||
4287 | 4287 | | |
4288 | 4288 | | |
4289 | 4289 | | |
| 4290 | + | |
| 4291 | + | |
| 4292 | + | |
| 4293 | + | |
| 4294 | + | |
4290 | 4295 | | |
4291 | 4296 | | |
4292 | 4297 | | |
| |||
4785 | 4790 | | |
4786 | 4791 | | |
4787 | 4792 | | |
4788 | | - | |
| 4793 | + | |
4789 | 4794 | | |
4790 | | - | |
| 4795 | + | |
| 4796 | + | |
4791 | 4797 | | |
4792 | | - | |
| 4798 | + | |
| 4799 | + | |
4793 | 4800 | | |
4794 | 4801 | | |
4795 | | - | |
| 4802 | + | |
4796 | 4803 | | |
4797 | 4804 | | |
4798 | 4805 | | |
| |||
5957 | 5964 | | |
5958 | 5965 | | |
5959 | 5966 | | |
5960 | | - | |
| 5967 | + | |
5961 | 5968 | | |
5962 | 5969 | | |
5963 | 5970 | | |
| |||
6136 | 6143 | | |
6137 | 6144 | | |
6138 | 6145 | | |
6139 | | - | |
| 6146 | + | |
6140 | 6147 | | |
6141 | 6148 | | |
6142 | 6149 | | |
| |||
8038 | 8045 | | |
8039 | 8046 | | |
8040 | 8047 | | |
| 8048 | + | |
| 8049 | + | |
| 8050 | + | |
| 8051 | + | |
| 8052 | + | |
8041 | 8053 | | |
8042 | 8054 | | |
8043 | 8055 | | |
| |||
8722 | 8734 | | |
8723 | 8735 | | |
8724 | 8736 | | |
8725 | | - | |
| 8737 | + | |
8726 | 8738 | | |
8727 | 8739 | | |
8728 | 8740 | | |
8729 | | - | |
8730 | | - | |
| 8741 | + | |
| 8742 | + | |
| 8743 | + | |
| 8744 | + | |
| 8745 | + | |
| 8746 | + | |
| 8747 | + | |
| 8748 | + | |
8731 | 8749 | | |
| 8750 | + | |
8732 | 8751 | | |
8733 | 8752 | | |
8734 | 8753 | | |
| |||
8839 | 8858 | | |
8840 | 8859 | | |
8841 | 8860 | | |
8842 | | - | |
| 8861 | + | |
8843 | 8862 | | |
8844 | 8863 | | |
8845 | 8864 | | |
| |||
8954 | 8973 | | |
8955 | 8974 | | |
8956 | 8975 | | |
8957 | | - | |
| 8976 | + | |
8958 | 8977 | | |
8959 | 8978 | | |
8960 | 8979 | | |
| |||
11294 | 11313 | | |
11295 | 11314 | | |
11296 | 11315 | | |
11297 | | - | |
| 11316 | + | |
11298 | 11317 | | |
11299 | 11318 | | |
11300 | 11319 | | |
| |||
0 commit comments