Commit 6e5cae9
Alexei Starovoitov
Merge branch 'bpf-additional-use-cases-for-untrusted-ptr_to_mem'
Eduard Zingerman says:
====================
bpf: additional use-cases for untrusted PTR_TO_MEM
This patch set introduces two usability enhancements leveraging
untrusted pointers to mem:
- When reading a pointer field from a PTR_TO_BTF_ID, the resulting
value is now assumed to be PTR_TO_MEM|MEM_RDONLY|PTR_UNTRUSTED
instead of SCALAR_VALUE, provided the pointer points to a primitive
type.
- __arg_untrusted attribute for global function parameters,
allowed for pointer arguments of both structural and primitive
types:
- For structural types, the attribute produces
PTR_TO_BTF_ID|PTR_UNTRUSTED.
- For primitive types, it yields
PTR_TO_MEM|MEM_RDONLY|PTR_UNTRUSTED.
Here are examples enabled by the series:
struct foo {
int *arr;
};
...
p = bpf_core_cast(..., struct foo);
bpf_for(i, 0, ...) {
... p->arr[i] ... // load at any offset is allowed
}
int memcmp(void *a __arg_untrusted, void *b __arg_untrusted, size_t n) {
bpf_for(i, 0, n)
if (a[i] - b[i]) // load at any offset is allowed
return ...;
return 0;
}
The patch-set was inspired by Anrii's series [1]. The goal of that
series was to define a generic global glob_match function, capable to
accept any pointer type:
__weak int glob_match(const char *pat, const char *str);
char filename_glob[32];
void foo(...) {
...
task = bpf_get_current_task_btf();
filename = task->mm->exe_file->f_path.dentry->d_name.name;
... match_glob(filename_glob, // pointer to map value
filename) ... // scalar
}
At the moment, there is no straightforward way to express such a
function. This patch-set makes it possible to define it as follows:
__weak int glob_match(const char *pat __arg_untrusted,
const char *str __arg_untrusted);
[1] https://github.com/anakryiko/linux/tree/bpf-mem-cast
Changelog:
v1: https://lore.kernel.org/bpf/[email protected]/
v1 -> v2:
- Added safety check in btf_prepare_func_args() to ensure that only
struct or primitive types could be combined with __arg_untrusted
(Alexei).
- Removed unnecessary 'continue' btf_check_func_arg_match() (Alexei).
- Added test cases for __arg_untrusted pointers to enum and
__arg_untrusted combined with non-kernel type (Kumar).
- Added acks from Kumar.
====================
Link: https://patch.msgid.link/[email protected]
Signed-off-by: Alexei Starovoitov <[email protected]>File tree
7 files changed
+274
-29
lines changed- include/linux
- kernel/bpf
- tools
- lib/bpf
- testing/selftests/bpf
- prog_tests
- progs
7 files changed
+274
-29
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
223 | 223 | | |
224 | 224 | | |
225 | 225 | | |
| 226 | + | |
226 | 227 | | |
227 | 228 | | |
228 | 229 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
891 | 891 | | |
892 | 892 | | |
893 | 893 | | |
| 894 | + | |
| 895 | + | |
| 896 | + | |
| 897 | + | |
| 898 | + | |
| 899 | + | |
894 | 900 | | |
895 | 901 | | |
896 | 902 | | |
| |||
6915 | 6921 | | |
6916 | 6922 | | |
6917 | 6923 | | |
| 6924 | + | |
6918 | 6925 | | |
6919 | 6926 | | |
6920 | 6927 | | |
| |||
7156 | 7163 | | |
7157 | 7164 | | |
7158 | 7165 | | |
| 7166 | + | |
| 7167 | + | |
7159 | 7168 | | |
7160 | 7169 | | |
7161 | 7170 | | |
| |||
7228 | 7237 | | |
7229 | 7238 | | |
7230 | 7239 | | |
| 7240 | + | |
| 7241 | + | |
| 7242 | + | |
7231 | 7243 | | |
7232 | 7244 | | |
7233 | 7245 | | |
| |||
7640 | 7652 | | |
7641 | 7653 | | |
7642 | 7654 | | |
7643 | | - | |
7644 | | - | |
7645 | | - | |
7646 | | - | |
7647 | | - | |
| 7655 | + | |
| 7656 | + | |
| 7657 | + | |
| 7658 | + | |
| 7659 | + | |
| 7660 | + | |
7648 | 7661 | | |
7649 | 7662 | | |
7650 | 7663 | | |
| |||
7752 | 7765 | | |
7753 | 7766 | | |
7754 | 7767 | | |
| 7768 | + | |
| 7769 | + | |
7755 | 7770 | | |
7756 | 7771 | | |
7757 | 7772 | | |
| |||
7812 | 7827 | | |
7813 | 7828 | | |
7814 | 7829 | | |
| 7830 | + | |
| 7831 | + | |
| 7832 | + | |
| 7833 | + | |
| 7834 | + | |
| 7835 | + | |
| 7836 | + | |
| 7837 | + | |
| 7838 | + | |
| 7839 | + | |
| 7840 | + | |
| 7841 | + | |
| 7842 | + | |
| 7843 | + | |
| 7844 | + | |
| 7845 | + | |
| 7846 | + | |
| 7847 | + | |
| 7848 | + | |
| 7849 | + | |
| 7850 | + | |
| 7851 | + | |
| 7852 | + | |
| 7853 | + | |
| 7854 | + | |
| 7855 | + | |
| 7856 | + | |
| 7857 | + | |
| 7858 | + | |
| 7859 | + | |
| 7860 | + | |
| 7861 | + | |
7815 | 7862 | | |
7816 | 7863 | | |
7817 | 7864 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
2796 | 2796 | | |
2797 | 2797 | | |
2798 | 2798 | | |
2799 | | - | |
2800 | | - | |
2801 | | - | |
2802 | | - | |
2803 | | - | |
| 2799 | + | |
| 2800 | + | |
| 2801 | + | |
| 2802 | + | |
| 2803 | + | |
2804 | 2804 | | |
2805 | | - | |
| 2805 | + | |
| 2806 | + | |
2806 | 2807 | | |
2807 | | - | |
| 2808 | + | |
| 2809 | + | |
| 2810 | + | |
| 2811 | + | |
| 2812 | + | |
| 2813 | + | |
| 2814 | + | |
| 2815 | + | |
| 2816 | + | |
| 2817 | + | |
| 2818 | + | |
| 2819 | + | |
| 2820 | + | |
| 2821 | + | |
| 2822 | + | |
| 2823 | + | |
| 2824 | + | |
2808 | 2825 | | |
2809 | | - | |
2810 | | - | |
2811 | | - | |
2812 | | - | |
2813 | | - | |
2814 | | - | |
2815 | 2826 | | |
2816 | 2827 | | |
2817 | 2828 | | |
| |||
5965 | 5976 | | |
5966 | 5977 | | |
5967 | 5978 | | |
| 5979 | + | |
5968 | 5980 | | |
5969 | 5981 | | |
5970 | 5982 | | |
| |||
5998 | 6010 | | |
5999 | 6011 | | |
6000 | 6012 | | |
6001 | | - | |
6002 | | - | |
| 6013 | + | |
| 6014 | + | |
| 6015 | + | |
| 6016 | + | |
| 6017 | + | |
6003 | 6018 | | |
6004 | 6019 | | |
6005 | 6020 | | |
| |||
7298 | 7313 | | |
7299 | 7314 | | |
7300 | 7315 | | |
7301 | | - | |
7302 | | - | |
| 7316 | + | |
| 7317 | + | |
| 7318 | + | |
| 7319 | + | |
| 7320 | + | |
7303 | 7321 | | |
7304 | 7322 | | |
7305 | 7323 | | |
| |||
7353 | 7371 | | |
7354 | 7372 | | |
7355 | 7373 | | |
7356 | | - | |
| 7374 | + | |
| 7375 | + | |
| 7376 | + | |
| 7377 | + | |
7357 | 7378 | | |
7358 | 7379 | | |
7359 | 7380 | | |
7360 | 7381 | | |
7361 | | - | |
7362 | | - | |
| 7382 | + | |
| 7383 | + | |
| 7384 | + | |
| 7385 | + | |
| 7386 | + | |
7363 | 7387 | | |
7364 | 7388 | | |
7365 | 7389 | | |
| |||
10413 | 10437 | | |
10414 | 10438 | | |
10415 | 10439 | | |
| 10440 | + | |
| 10441 | + | |
| 10442 | + | |
| 10443 | + | |
| 10444 | + | |
| 10445 | + | |
10416 | 10446 | | |
10417 | 10447 | | |
10418 | 10448 | | |
| |||
23122 | 23152 | | |
23123 | 23153 | | |
23124 | 23154 | | |
23125 | | - | |
23126 | | - | |
| 23155 | + | |
| 23156 | + | |
23127 | 23157 | | |
23128 | 23158 | | |
23129 | | - | |
| 23159 | + | |
| 23160 | + | |
23130 | 23161 | | |
23131 | 23162 | | |
23132 | 23163 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
215 | 215 | | |
216 | 216 | | |
217 | 217 | | |
| 218 | + | |
218 | 219 | | |
219 | 220 | | |
220 | 221 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
72 | 72 | | |
73 | 73 | | |
74 | 74 | | |
75 | | - | |
| 75 | + | |
76 | 76 | | |
77 | 77 | | |
78 | 78 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
5 | 5 | | |
6 | 6 | | |
7 | 7 | | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
8 | 39 | | |
9 | 40 | | |
10 | 41 | | |
| |||
0 commit comments