History

Merge git://git.kernel.org/pub/scm/linux/kernel/git/bpf/bpf-next

Alexei Starovoitov says: ==================== pull-request: bpf-next 2019-11-02 The following pull-request contains BPF updates for your *net-next* tree. We've added 30 non-merge commits during the last 7 day(s) which contain a total of 41 files changed, 1864 insertions(+), 474 deletions(-). The main changes are: 1) Fix long standing user vs kernel access issue by introducing bpf_probe_read_user() and bpf_probe_read_kernel() helpers, from Daniel. 2) Accelerated xskmap lookup, from Björn and Maciej. 3) Support for automatic map pinning in libbpf, from Toke. 4) Cleanup of BTF-enabled raw tracepoints, from Alexei. 5) Various fixes to libbpf and selftests. ====================

David S. Miller committed 7 years ago

Commit ae8a76f2 parents d31e955 358fdb441 files · +1863 −476Browse files

Showing the changes to include/uapi/linux (1 of 41 files). Show all

Unified · Split

include/uapi/linux/bpf.h+84−40
@@ -173,6 +173,7 @@ enum bpf_prog_type { · 172 unmodified lines
173 BPF_PROG_TYPE_CGROUP_SYSCTL,173 BPF_PROG_TYPE_CGROUP_SYSCTL,
174 BPF_PROG_TYPE_RAW_TRACEPOINT_WRITABLE,174 BPF_PROG_TYPE_RAW_TRACEPOINT_WRITABLE,
175 BPF_PROG_TYPE_CGROUP_SOCKOPT,175 BPF_PROG_TYPE_CGROUP_SOCKOPT,
176 BPF_PROG_TYPE_TRACING,
176};177};
177 178
178enum bpf_attach_type {179enum bpf_attach_type {
@@ -199,6 +200,7 @@ enum bpf_attach_type { · 20 unmodified lines
199 BPF_CGROUP_UDP6_RECVMSG,200 BPF_CGROUP_UDP6_RECVMSG,
200 BPF_CGROUP_GETSOCKOPT,201 BPF_CGROUP_GETSOCKOPT,
201 BPF_CGROUP_SETSOCKOPT,202 BPF_CGROUP_SETSOCKOPT,
203 BPF_TRACE_RAW_TP,
202 __MAX_BPF_ATTACH_TYPE204 __MAX_BPF_ATTACH_TYPE
203};205};
204 206
@@ -561,10 +563,13 @@ union bpf_attr { · 356 unmodified lines
561 * Return563 * Return
562 * 0 on success, or a negative error in case of failure.564 * 0 on success, or a negative error in case of failure.
563 *565 *
564 * int bpf_probe_read(void *dst, u32 size, const void *src)566 * int bpf_probe_read(void *dst, u32 size, const void *unsafe_ptr)
565 * Description567 * Description
566 * For tracing programs, safely attempt to read *size* bytes from568 * For tracing programs, safely attempt to read *size* bytes from
567 * address *src* and store the data in *dst*.569 * kernel space address *unsafe_ptr* and store the data in *dst*.
570 *
571 * Generally, use bpf_probe_read_user() or bpf_probe_read_kernel()
572 * instead.
568 * Return573 * Return
569 * 0 on success, or a negative error in case of failure.574 * 0 on success, or a negative error in case of failure.
570 *575 *
@@ -1426,45 +1431,14 @@ union bpf_attr { · 855 unmodified lines
1426 * Return1431 * Return
1427 * 0 on success, or a negative error in case of failure.1432 * 0 on success, or a negative error in case of failure.
1428 *1433 *
1429 * int bpf_probe_read_str(void *dst, int size, const void *unsafe_ptr)1434 * int bpf_probe_read_str(void *dst, u32 size, const void *unsafe_ptr)
1430 * Description1435 * Description
1431 * Copy a NUL terminated string from an unsafe address1436 * Copy a NUL terminated string from an unsafe kernel address
1432 * *unsafe_ptr* to *dst*. The *size* should include the1437 * *unsafe_ptr* to *dst*. See bpf_probe_read_kernel_str() for
1433 * terminating NUL byte. In case the string length is smaller than1438 * more details.
1434 * *size*, the target is not padded with further NUL bytes. If the
1435 * string length is larger than *size*, just *size*-1 bytes are
1436 * copied and the last byte is set to NUL.
1437 *
1438 * On success, the length of the copied string is returned. This
1439 * makes this helper useful in tracing programs for reading
1440 * strings, and more importantly to get its length at runtime. See
1441 * the following snippet:
1442 *
1443 * ::
1444 *
1445 * SEC("kprobe/sys_open")
1446 * void bpf_sys_open(struct pt_regs *ctx)
1447 * {
1448 * char buf[PATHLEN]; // PATHLEN is defined to 256
1449 * int res = bpf_probe_read_str(buf, sizeof(buf),
1450 * ctx->di);
1451 *
1452 * // Consume buf, for example push it to
1453 * // userspace via bpf_perf_event_output(); we
1454 * // can use res (the string length) as event
1455 * // size, after checking its boundaries.
1456 * }
1457 *
1458 * In comparison, using **bpf_probe_read()** helper here instead
1459 * to read the string would require to estimate the length at
1460 * compile time, and would often result in copying more memory
1461 * than necessary.
1462 *1439 *
1463 * Another useful use case is when parsing individual process1440 * Generally, use bpf_probe_read_user_str() or bpf_probe_read_kernel_str()
1464 * arguments or individual environment variables navigating1441 * instead.
1465 * *current*\ **->mm->arg_start** and *current*\
1466 * **->mm->env_start**: using this helper and the return value,
1467 * one can quickly iterate at the right offset of the memory area.
1468 * Return1442 * Return
1469 * On success, the strictly positive length of the string,1443 * On success, the strictly positive length of the string,
1470 * including the trailing NUL character. On error, a negative1444 * including the trailing NUL character. On error, a negative
@@ -2775,6 +2749,72 @@ union bpf_attr { · 1304 unmodified lines
2775 * restricted to raw_tracepoint bpf programs.2749 * restricted to raw_tracepoint bpf programs.
2776 * Return2750 * Return
2777 * 0 on success, or a negative error in case of failure.2751 * 0 on success, or a negative error in case of failure.
2752 *
2753 * int bpf_probe_read_user(void *dst, u32 size, const void *unsafe_ptr)
2754 * Description
2755 * Safely attempt to read *size* bytes from user space address
2756 * *unsafe_ptr* and store the data in *dst*.
2757 * Return
2758 * 0 on success, or a negative error in case of failure.
2759 *
2760 * int bpf_probe_read_kernel(void *dst, u32 size, const void *unsafe_ptr)
2761 * Description
2762 * Safely attempt to read *size* bytes from kernel space address
2763 * *unsafe_ptr* and store the data in *dst*.
2764 * Return
2765 * 0 on success, or a negative error in case of failure.
2766 *
2767 * int bpf_probe_read_user_str(void *dst, u32 size, const void *unsafe_ptr)
2768 * Description
2769 * Copy a NUL terminated string from an unsafe user address
2770 * *unsafe_ptr* to *dst*. The *size* should include the
2771 * terminating NUL byte. In case the string length is smaller than
2772 * *size*, the target is not padded with further NUL bytes. If the
2773 * string length is larger than *size*, just *size*-1 bytes are
2774 * copied and the last byte is set to NUL.
2775 *
2776 * On success, the length of the copied string is returned. This
2777 * makes this helper useful in tracing programs for reading
2778 * strings, and more importantly to get its length at runtime. See
2779 * the following snippet:
2780 *
2781 * ::
2782 *
2783 * SEC("kprobe/sys_open")
2784 * void bpf_sys_open(struct pt_regs *ctx)
2785 * {
2786 * char buf[PATHLEN]; // PATHLEN is defined to 256
2787 * int res = bpf_probe_read_user_str(buf, sizeof(buf),
2788 * ctx->di);
2789 *
2790 * // Consume buf, for example push it to
2791 * // userspace via bpf_perf_event_output(); we
2792 * // can use res (the string length) as event
2793 * // size, after checking its boundaries.
2794 * }
2795 *
2796 * In comparison, using **bpf_probe_read_user()** helper here
2797 * instead to read the string would require to estimate the length
2798 * at compile time, and would often result in copying more memory
2799 * than necessary.
2800 *
2801 * Another useful use case is when parsing individual process
2802 * arguments or individual environment variables navigating
2803 * *current*\ **->mm->arg_start** and *current*\
2804 * **->mm->env_start**: using this helper and the return value,
2805 * one can quickly iterate at the right offset of the memory area.
2806 * Return
2807 * On success, the strictly positive length of the string,
2808 * including the trailing NUL character. On error, a negative
2809 * value.
2810 *
2811 * int bpf_probe_read_kernel_str(void *dst, u32 size, const void *unsafe_ptr)
2812 * Description
2813 * Copy a NUL terminated string from an unsafe kernel address *unsafe_ptr*
2814 * to *dst*. Same semantics as with bpf_probe_read_user_str() apply.
2815 * Return
2816 * On success, the strictly positive length of the string, including
2817 * the trailing NUL character. On error, a negative value.
2778 */2818 */
2779#define __BPF_FUNC_MAPPER(FN) \2819#define __BPF_FUNC_MAPPER(FN) \
2780 FN(unspec), \2820 FN(unspec), \
@@ -2888,7 +2928,11 @@ union bpf_attr { · 107 unmodified lines
2888 FN(sk_storage_delete), \2928 FN(sk_storage_delete), \
2889 FN(send_signal), \2929 FN(send_signal), \
2890 FN(tcp_gen_syncookie), \2930 FN(tcp_gen_syncookie), \
2891 FN(skb_output),2931 FN(skb_output), \
2932 FN(probe_read_user), \
2933 FN(probe_read_kernel), \
2934 FN(probe_read_user_str), \
2935 FN(probe_read_kernel_str),
2892 2936
2893/* integer value in 'imm' field of BPF_CALL instruction selects which helper2937/* integer value in 'imm' field of BPF_CALL instruction selects which helper
2894 * function eBPF program intends to call2938 * function eBPF program intends to call