Alexei Starovoitov says: ==================== pull-request: bpf-next 2021-12-30 The following pull-request contains BPF updates for your *net-next* tree. We've added 72 non-merge commits during the last 20 day(s) which contain a total of 223 files changed, 3510 insertions(+), 1591 deletions(-). The main changes are: 1) Automatic setrlimit in libbpf when bpf is memcg's in the kernel, from Andrii. 2) Beautify and de-verbose verifier logs, from Christy. 3) Composable verifier types, from Hao. 4) bpf_strncmp helper, from Hou. 5) bpf.h header dependency cleanup, from Jakub. 6) get_func_[arg|ret|arg_cnt] helpers, from Jiri. 7) Sleepable local storage, from KP. 8) Extend kfunc with PTR_TO_CTX, PTR_TO_MEM argument support, from Kumar. ====================
Showing the changes to kernel/trace (3 of 221 files). Show all
Unified · Split
| @@ -345,7 +345,7 @@ static const struct bpf_func_proto bpf_probe_write_user_proto = { · 344 unmodified lines | ||
| 345 | 345 | .gpl_only = true, |
| 346 | 346 | .ret_type = RET_INTEGER, |
| 347 | 347 | .arg1_type = ARG_ANYTHING, |
| 348 | − .arg2_type = ARG_PTR_TO_MEM, | |
| 348 | + .arg2_type = ARG_PTR_TO_MEM | MEM_RDONLY, | |
| 349 | 349 | .arg3_type = ARG_CONST_SIZE, |
| 350 | 350 | }; |
| 351 | 351 | |
| @@ -394,7 +394,7 @@ static const struct bpf_func_proto bpf_trace_printk_proto = { · 42 unmodified lines | ||
| 394 | 394 | .func = bpf_trace_printk, |
| 395 | 395 | .gpl_only = true, |
| 396 | 396 | .ret_type = RET_INTEGER, |
| 397 | − .arg1_type = ARG_PTR_TO_MEM, | |
| 397 | + .arg1_type = ARG_PTR_TO_MEM | MEM_RDONLY, | |
| 398 | 398 | .arg2_type = ARG_CONST_SIZE, |
| 399 | 399 | }; |
| 400 | 400 | |
| @@ -450,9 +450,9 @@ static const struct bpf_func_proto bpf_trace_vprintk_proto = { · 49 unmodified lines | ||
| 450 | 450 | .func = bpf_trace_vprintk, |
| 451 | 451 | .gpl_only = true, |
| 452 | 452 | .ret_type = RET_INTEGER, |
| 453 | − .arg1_type = ARG_PTR_TO_MEM, | |
| 453 | + .arg1_type = ARG_PTR_TO_MEM | MEM_RDONLY, | |
| 454 | 454 | .arg2_type = ARG_CONST_SIZE, |
| 455 | − .arg3_type = ARG_PTR_TO_MEM_OR_NULL, | |
| 455 | + .arg3_type = ARG_PTR_TO_MEM | PTR_MAYBE_NULL | MEM_RDONLY, | |
| 456 | 456 | .arg4_type = ARG_CONST_SIZE_OR_ZERO, |
| 457 | 457 | }; |
| 458 | 458 | |
| @@ -492,9 +492,9 @@ static const struct bpf_func_proto bpf_seq_printf_proto = { · 33 unmodified lines | ||
| 492 | 492 | .ret_type = RET_INTEGER, |
| 493 | 493 | .arg1_type = ARG_PTR_TO_BTF_ID, |
| 494 | 494 | .arg1_btf_id = &btf_seq_file_ids[0], |
| 495 | − .arg2_type = ARG_PTR_TO_MEM, | |
| 495 | + .arg2_type = ARG_PTR_TO_MEM | MEM_RDONLY, | |
| 496 | 496 | .arg3_type = ARG_CONST_SIZE, |
| 497 | − .arg4_type = ARG_PTR_TO_MEM_OR_NULL, | |
| 497 | + .arg4_type = ARG_PTR_TO_MEM | PTR_MAYBE_NULL | MEM_RDONLY, | |
| 498 | 498 | .arg5_type = ARG_CONST_SIZE_OR_ZERO, |
| 499 | 499 | }; |
| 500 | 500 | |
| @@ -509,7 +509,7 @@ static const struct bpf_func_proto bpf_seq_write_proto = { · 8 unmodified lines | ||
| 509 | 509 | .ret_type = RET_INTEGER, |
| 510 | 510 | .arg1_type = ARG_PTR_TO_BTF_ID, |
| 511 | 511 | .arg1_btf_id = &btf_seq_file_ids[0], |
| 512 | − .arg2_type = ARG_PTR_TO_MEM, | |
| 512 | + .arg2_type = ARG_PTR_TO_MEM | MEM_RDONLY, | |
| 513 | 513 | .arg3_type = ARG_CONST_SIZE_OR_ZERO, |
| 514 | 514 | }; |
| 515 | 515 | |
| @@ -533,7 +533,7 @@ static const struct bpf_func_proto bpf_seq_printf_btf_proto = { · 17 unmodified lines | ||
| 533 | 533 | .ret_type = RET_INTEGER, |
| 534 | 534 | .arg1_type = ARG_PTR_TO_BTF_ID, |
| 535 | 535 | .arg1_btf_id = &btf_seq_file_ids[0], |
| 536 | − .arg2_type = ARG_PTR_TO_MEM, | |
| 536 | + .arg2_type = ARG_PTR_TO_MEM | MEM_RDONLY, | |
| 537 | 537 | .arg3_type = ARG_CONST_SIZE_OR_ZERO, |
| 538 | 538 | .arg4_type = ARG_ANYTHING, |
| 539 | 539 | }; |
| @@ -694,7 +694,7 @@ static const struct bpf_func_proto bpf_perf_event_output_proto = { · 154 unmodified lines | ||
| 694 | 694 | .arg1_type = ARG_PTR_TO_CTX, |
| 695 | 695 | .arg2_type = ARG_CONST_MAP_PTR, |
| 696 | 696 | .arg3_type = ARG_ANYTHING, |
| 697 | − .arg4_type = ARG_PTR_TO_MEM, | |
| 697 | + .arg4_type = ARG_PTR_TO_MEM | MEM_RDONLY, | |
| 698 | 698 | .arg5_type = ARG_CONST_SIZE_OR_ZERO, |
| 699 | 699 | }; |
| 700 | 700 | |
| @@ -1004,7 +1004,7 @@ const struct bpf_func_proto bpf_snprintf_btf_proto = { · 303 unmodified lines | ||
| 1004 | 1004 | .ret_type = RET_INTEGER, |
| 1005 | 1005 | .arg1_type = ARG_PTR_TO_MEM, |
| 1006 | 1006 | .arg2_type = ARG_CONST_SIZE, |
| 1007 | − .arg3_type = ARG_PTR_TO_MEM, | |
| 1007 | + .arg3_type = ARG_PTR_TO_MEM | MEM_RDONLY, | |
| 1008 | 1008 | .arg4_type = ARG_CONST_SIZE, |
| 1009 | 1009 | .arg5_type = ARG_ANYTHING, |
| 1010 | 1010 | }; |
| @@ -1012,7 +1012,7 @@ const struct bpf_func_proto bpf_snprintf_btf_proto = { · 1 unmodified line | ||
| 1012 | 1012 | BPF_CALL_1(bpf_get_func_ip_tracing, void *, ctx) |
| 1013 | 1013 | { |
| 1014 | 1014 | /* This helper call is inlined by verifier. */ |
| 1015 | − return ((u64 *)ctx)[-1]; | |
| 1015 | + return ((u64 *)ctx)[-2]; | |
| 1016 | 1016 | } |
| 1017 | 1017 | |
| 1018 | 1018 | static const struct bpf_func_proto bpf_get_func_ip_proto_tracing = { |
| @@ -1091,6 +1091,53 @@ static const struct bpf_func_proto bpf_get_branch_snapshot_proto = { · 72 unmodified lines | ||
| 1091 | 1091 | .arg2_type = ARG_CONST_SIZE_OR_ZERO, |
| 1092 | 1092 | }; |
| 1093 | 1093 | |
| 1094 | +BPF_CALL_3(get_func_arg, void *, ctx, u32, n, u64 *, value) | |
| 1095 | +{ | |
| 1096 | + /* This helper call is inlined by verifier. */ | |
| 1097 | + u64 nr_args = ((u64 *)ctx)[-1]; | |
| 1098 | + | |
| 1099 | + if ((u64) n >= nr_args) | |
| 1100 | + return -EINVAL; | |
| 1101 | + *value = ((u64 *)ctx)[n]; | |
| 1102 | + return 0; | |
| 1103 | +} | |
| 1104 | + | |
| 1105 | +static const struct bpf_func_proto bpf_get_func_arg_proto = { | |
| 1106 | + .func = get_func_arg, | |
| 1107 | + .ret_type = RET_INTEGER, | |
| 1108 | + .arg1_type = ARG_PTR_TO_CTX, | |
| 1109 | + .arg2_type = ARG_ANYTHING, | |
| 1110 | + .arg3_type = ARG_PTR_TO_LONG, | |
| 1111 | +}; | |
| 1112 | + | |
| 1113 | +BPF_CALL_2(get_func_ret, void *, ctx, u64 *, value) | |
| 1114 | +{ | |
| 1115 | + /* This helper call is inlined by verifier. */ | |
| 1116 | + u64 nr_args = ((u64 *)ctx)[-1]; | |
| 1117 | + | |
| 1118 | + *value = ((u64 *)ctx)[nr_args]; | |
| 1119 | + return 0; | |
| 1120 | +} | |
| 1121 | + | |
| 1122 | +static const struct bpf_func_proto bpf_get_func_ret_proto = { | |
| 1123 | + .func = get_func_ret, | |
| 1124 | + .ret_type = RET_INTEGER, | |
| 1125 | + .arg1_type = ARG_PTR_TO_CTX, | |
| 1126 | + .arg2_type = ARG_PTR_TO_LONG, | |
| 1127 | +}; | |
| 1128 | + | |
| 1129 | +BPF_CALL_1(get_func_arg_cnt, void *, ctx) | |
| 1130 | +{ | |
| 1131 | + /* This helper call is inlined by verifier. */ | |
| 1132 | + return ((u64 *)ctx)[-1]; | |
| 1133 | +} | |
| 1134 | + | |
| 1135 | +static const struct bpf_func_proto bpf_get_func_arg_cnt_proto = { | |
| 1136 | + .func = get_func_arg_cnt, | |
| 1137 | + .ret_type = RET_INTEGER, | |
| 1138 | + .arg1_type = ARG_PTR_TO_CTX, | |
| 1139 | +}; | |
| 1140 | + | |
| 1094 | 1141 | static const struct bpf_func_proto * |
| 1095 | 1142 | bpf_tracing_func_proto(enum bpf_func_id func_id, const struct bpf_prog *prog) |
| 1096 | 1143 | { |
| @@ -1287,7 +1334,7 @@ static const struct bpf_func_proto bpf_perf_event_output_proto_tp = { · 190 unmodified lines | ||
| 1287 | 1334 | .arg1_type = ARG_PTR_TO_CTX, |
| 1288 | 1335 | .arg2_type = ARG_CONST_MAP_PTR, |
| 1289 | 1336 | .arg3_type = ARG_ANYTHING, |
| 1290 | − .arg4_type = ARG_PTR_TO_MEM, | |
| 1337 | + .arg4_type = ARG_PTR_TO_MEM | MEM_RDONLY, | |
| 1291 | 1338 | .arg5_type = ARG_CONST_SIZE_OR_ZERO, |
| 1292 | 1339 | }; |
| 1293 | 1340 | |
| @@ -1509,7 +1556,7 @@ static const struct bpf_func_proto bpf_perf_event_output_proto_raw_tp = { · 215 unmodified lines | ||
| 1509 | 1556 | .arg1_type = ARG_PTR_TO_CTX, |
| 1510 | 1557 | .arg2_type = ARG_CONST_MAP_PTR, |
| 1511 | 1558 | .arg3_type = ARG_ANYTHING, |
| 1512 | − .arg4_type = ARG_PTR_TO_MEM, | |
| 1559 | + .arg4_type = ARG_PTR_TO_MEM | MEM_RDONLY, | |
| 1513 | 1560 | .arg5_type = ARG_CONST_SIZE_OR_ZERO, |
| 1514 | 1561 | }; |
| 1515 | 1562 | |
| @@ -1563,7 +1610,7 @@ static const struct bpf_func_proto bpf_get_stack_proto_raw_tp = { · 47 unmodified lines | ||
| 1563 | 1610 | .gpl_only = true, |
| 1564 | 1611 | .ret_type = RET_INTEGER, |
| 1565 | 1612 | .arg1_type = ARG_PTR_TO_CTX, |
| 1566 | − .arg2_type = ARG_PTR_TO_MEM, | |
| 1613 | + .arg2_type = ARG_PTR_TO_MEM | MEM_RDONLY, | |
| 1567 | 1614 | .arg3_type = ARG_CONST_SIZE_OR_ZERO, |
| 1568 | 1615 | .arg4_type = ARG_ANYTHING, |
| 1569 | 1616 | }; |
| @@ -1629,6 +1676,12 @@ tracing_prog_func_proto(enum bpf_func_id func_id, const struct bpf_prog *prog) · 59 unmodified lines | ||
| 1629 | 1676 | NULL; |
| 1630 | 1677 | case BPF_FUNC_d_path: |
| 1631 | 1678 | return &bpf_d_path_proto; |
| 1679 | + case BPF_FUNC_get_func_arg: | |
| 1680 | + return bpf_prog_has_trampoline(prog) ? &bpf_get_func_arg_proto : NULL; | |
| 1681 | + case BPF_FUNC_get_func_ret: | |
| 1682 | + return bpf_prog_has_trampoline(prog) ? &bpf_get_func_ret_proto : NULL; | |
| 1683 | + case BPF_FUNC_get_func_arg_cnt: | |
| 1684 | + return bpf_prog_has_trampoline(prog) ? &bpf_get_func_arg_cnt_proto : NULL; | |
| 1632 | 1685 | default: |
| 1633 | 1686 | fn = raw_tp_prog_func_proto(func_id, prog); |
| 1634 | 1687 | if (!fn && prog->expected_attach_type == BPF_TRACE_ITER) |
| @@ -7,6 +7,7 @@ · 6 unmodified lines | ||
| 7 | 7 | */ |
| 8 | 8 | #define pr_fmt(fmt) "trace_kprobe: " fmt |
| 9 | 9 | |
| 10 | +#include <linux/bpf-cgroup.h> | |
| 10 | 11 | #include <linux/security.h> |
| 11 | 12 | #include <linux/module.h> |
| 12 | 13 | #include <linux/uaccess.h> |
| @@ -7,6 +7,7 @@ · 6 unmodified lines | ||
| 7 | 7 | */ |
| 8 | 8 | #define pr_fmt(fmt) "trace_uprobe: " fmt |
| 9 | 9 | |
| 10 | +#include <linux/bpf-cgroup.h> | |
| 10 | 11 | #include <linux/security.h> |
| 11 | 12 | #include <linux/ctype.h> |
| 12 | 13 | #include <linux/module.h> |