Skip to content

Commit 29d9f30

Browse files
committed
Merge git://git.kernel.org/pub/scm/linux/kernel/git/netdev/net-next
Pull networking updates from David Miller: "Highlights: 1) Fix the iwlwifi regression, from Johannes Berg. 2) Support BSS coloring and 802.11 encapsulation offloading in hardware, from John Crispin. 3) Fix some potential Spectre issues in qtnfmac, from Sergey Matyukevich. 4) Add TTL decrement action to openvswitch, from Matteo Croce. 5) Allow paralleization through flow_action setup by not taking the RTNL mutex, from Vlad Buslov. 6) A lot of zero-length array to flexible-array conversions, from Gustavo A. R. Silva. 7) Align XDP statistics names across several drivers for consistency, from Lorenzo Bianconi. 8) Add various pieces of infrastructure for offloading conntrack, and make use of it in mlx5 driver, from Paul Blakey. 9) Allow using listening sockets in BPF sockmap, from Jakub Sitnicki. 10) Lots of parallelization improvements during configuration changes in mlxsw driver, from Ido Schimmel. 11) Add support to devlink for generic packet traps, which report packets dropped during ACL processing. And use them in mlxsw driver. From Jiri Pirko. 12) Support bcmgenet on ACPI, from Jeremy Linton. 13) Make BPF compatible with RT, from Thomas Gleixnet, Alexei Starovoitov, and your's truly. 14) Support XDP meta-data in virtio_net, from Yuya Kusakabe. 15) Fix sysfs permissions when network devices change namespaces, from Christian Brauner. 16) Add a flags element to ethtool_ops so that drivers can more simply indicate which coalescing parameters they actually support, and therefore the generic layer can validate the user's ethtool request. Use this in all drivers, from Jakub Kicinski. 17) Offload FIFO qdisc in mlxsw, from Petr Machata. 18) Support UDP sockets in sockmap, from Lorenz Bauer. 19) Fix stretch ACK bugs in several TCP congestion control modules, from Pengcheng Yang. 20) Support virtual functiosn in octeontx2 driver, from Tomasz Duszynski. 21) Add region operations for devlink and use it in ice driver to dump NVM contents, from Jacob Keller. 22) Add support for hw offload of MACSEC, from Antoine Tenart. 23) Add support for BPF programs that can be attached to LSM hooks, from KP Singh. 24) Support for multiple paths, path managers, and counters in MPTCP. From Peter Krystad, Paolo Abeni, Florian Westphal, Davide Caratti, and others. 25) More progress on adding the netlink interface to ethtool, from Michal Kubecek" * git://git.kernel.org/pub/scm/linux/kernel/git/netdev/net-next: (2121 commits) net: ipv6: rpl_iptunnel: Fix potential memory leak in rpl_do_srh_inline cxgb4/chcr: nic-tls stats in ethtool net: dsa: fix oops while probing Marvell DSA switches net/bpfilter: remove superfluous testing message net: macb: Fix handling of fixed-link node net: dsa: ksz: Select KSZ protocol tag netdevsim: dev: Fix memory leak in nsim_dev_take_snapshot_write net: stmmac: add EHL 2.5Gbps PCI info and PCI ID net: stmmac: add EHL PSE0 & PSE1 1Gbps PCI info and PCI ID net: stmmac: create dwmac-intel.c to contain all Intel platform net: dsa: bcm_sf2: Support specifying VLAN tag egress rule net: dsa: bcm_sf2: Add support for matching VLAN TCI net: dsa: bcm_sf2: Move writing of CFP_DATA(5) into slicing functions net: dsa: bcm_sf2: Check earlier for FLOW_EXT and FLOW_MAC_EXT net: dsa: bcm_sf2: Disable learning for ASP port net: dsa: b53: Deny enslaving port 7 for 7278 into a bridge net: dsa: b53: Prevent tagged VLAN on port 7 for 7278 net: dsa: b53: Restore VLAN entries upon (re)configuration net: dsa: bcm_sf2: Fix overflow checks hv_netvsc: Remove unnecessary round_up for recv_completion_cnt ...
2 parents 56a451b + 7f80ccf commit 29d9f30

File tree

1,772 files changed

+113780
-26434
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

1,772 files changed

+113780
-26434
lines changed

Documentation/admin-guide/sysctl/net.rst

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,8 @@ two flavors of JITs, the newer eBPF JIT currently supported on:
6767
- sparc64
6868
- mips64
6969
- s390x
70-
- riscv
70+
- riscv64
71+
- riscv32
7172

7273
And the older cBPF JIT supported on the following archs:
7374

Documentation/bpf/bpf_devel_QA.rst

Lines changed: 12 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -20,11 +20,11 @@ Reporting bugs
2020
Q: How do I report bugs for BPF kernel code?
2121
--------------------------------------------
2222
A: Since all BPF kernel development as well as bpftool and iproute2 BPF
23-
loader development happens through the netdev kernel mailing list,
23+
loader development happens through the bpf kernel mailing list,
2424
please report any found issues around BPF to the following mailing
2525
list:
2626

27-
netdev@vger.kernel.org
27+
bpf@vger.kernel.org
2828

2929
This may also include issues related to XDP, BPF tracing, etc.
3030

@@ -46,17 +46,12 @@ Submitting patches
4646

4747
Q: To which mailing list do I need to submit my BPF patches?
4848
------------------------------------------------------------
49-
A: Please submit your BPF patches to the netdev kernel mailing list:
49+
A: Please submit your BPF patches to the bpf kernel mailing list:
5050

51-
52-
53-
Historically, BPF came out of networking and has always been maintained
54-
by the kernel networking community. Although these days BPF touches
55-
many other subsystems as well, the patches are still routed mainly
56-
through the networking community.
51+
5752

5853
In case your patch has changes in various different subsystems (e.g.
59-
tracing, security, etc), make sure to Cc the related kernel mailing
54+
networking, tracing, security, etc), make sure to Cc the related kernel mailing
6055
lists and maintainers from there as well, so they are able to review
6156
the changes and provide their Acked-by's to the patches.
6257

@@ -168,7 +163,7 @@ a BPF point of view.
168163
Be aware that this is not a final verdict that the patch will
169164
automatically get accepted into net or net-next trees eventually:
170165

171-
On the netdev kernel mailing list reviews can come in at any point
166+
On the bpf kernel mailing list reviews can come in at any point
172167
in time. If discussions around a patch conclude that they cannot
173168
get included as-is, we will either apply a follow-up fix or drop
174169
them from the trees entirely. Therefore, we also reserve to rebase
@@ -494,15 +489,15 @@ A: You need cmake and gcc-c++ as build requisites for LLVM. Once you have
494489
that set up, proceed with building the latest LLVM and clang version
495490
from the git repositories::
496491

497-
$ git clone http://llvm.org/git/llvm.git
498-
$ cd llvm/tools
499-
$ git clone --depth 1 http://llvm.org/git/clang.git
500-
$ cd ..; mkdir build; cd build
501-
$ cmake .. -DLLVM_TARGETS_TO_BUILD="BPF;X86" \
492+
$ git clone https://github.com/llvm/llvm-project.git
493+
$ mkdir -p llvm-project/llvm/build/install
494+
$ cd llvm-project/llvm/build
495+
$ cmake .. -G "Ninja" -DLLVM_TARGETS_TO_BUILD="BPF;X86" \
496+
-DLLVM_ENABLE_PROJECTS="clang" \
502497
-DBUILD_SHARED_LIBS=OFF \
503498
-DCMAKE_BUILD_TYPE=Release \
504499
-DLLVM_BUILD_RUNTIME=OFF
505-
$ make -j $(getconf _NPROCESSORS_ONLN)
500+
$ ninja
506501

507502
The built binaries can then be found in the build/bin/ directory, where
508503
you can point the PATH variable to.

Documentation/bpf/bpf_lsm.rst

Lines changed: 142 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,142 @@
1+
.. SPDX-License-Identifier: GPL-2.0+
2+
.. Copyright (C) 2020 Google LLC.
3+
4+
================
5+
LSM BPF Programs
6+
================
7+
8+
These BPF programs allow runtime instrumentation of the LSM hooks by privileged
9+
users to implement system-wide MAC (Mandatory Access Control) and Audit
10+
policies using eBPF.
11+
12+
Structure
13+
---------
14+
15+
The example shows an eBPF program that can be attached to the ``file_mprotect``
16+
LSM hook:
17+
18+
.. c:function:: int file_mprotect(struct vm_area_struct *vma, unsigned long reqprot, unsigned long prot);
19+
20+
Other LSM hooks which can be instrumented can be found in
21+
``include/linux/lsm_hooks.h``.
22+
23+
eBPF programs that use :doc:`/bpf/btf` do not need to include kernel headers
24+
for accessing information from the attached eBPF program's context. They can
25+
simply declare the structures in the eBPF program and only specify the fields
26+
that need to be accessed.
27+
28+
.. code-block:: c
29+
30+
struct mm_struct {
31+
unsigned long start_brk, brk, start_stack;
32+
} __attribute__((preserve_access_index));
33+
34+
struct vm_area_struct {
35+
unsigned long start_brk, brk, start_stack;
36+
unsigned long vm_start, vm_end;
37+
struct mm_struct *vm_mm;
38+
} __attribute__((preserve_access_index));
39+
40+
41+
.. note:: The order of the fields is irrelevant.
42+
43+
This can be further simplified (if one has access to the BTF information at
44+
build time) by generating the ``vmlinux.h`` with:
45+
46+
.. code-block:: console
47+
48+
# bpftool btf dump file <path-to-btf-vmlinux> format c > vmlinux.h
49+
50+
.. note:: ``path-to-btf-vmlinux`` can be ``/sys/kernel/btf/vmlinux`` if the
51+
build environment matches the environment the BPF programs are
52+
deployed in.
53+
54+
The ``vmlinux.h`` can then simply be included in the BPF programs without
55+
requiring the definition of the types.
56+
57+
The eBPF programs can be declared using the``BPF_PROG``
58+
macros defined in `tools/lib/bpf/bpf_tracing.h`_. In this
59+
example:
60+
61+
* ``"lsm/file_mprotect"`` indicates the LSM hook that the program must
62+
be attached to
63+
* ``mprotect_audit`` is the name of the eBPF program
64+
65+
.. code-block:: c
66+
67+
SEC("lsm/file_mprotect")
68+
int BPF_PROG(mprotect_audit, struct vm_area_struct *vma,
69+
unsigned long reqprot, unsigned long prot, int ret)
70+
{
71+
/* ret is the return value from the previous BPF program
72+
* or 0 if it's the first hook.
73+
*/
74+
if (ret != 0)
75+
return ret;
76+
77+
int is_heap;
78+
79+
is_heap = (vma->vm_start >= vma->vm_mm->start_brk &&
80+
vma->vm_end <= vma->vm_mm->brk);
81+
82+
/* Return an -EPERM or write information to the perf events buffer
83+
* for auditing
84+
*/
85+
if (is_heap)
86+
return -EPERM;
87+
}
88+
89+
The ``__attribute__((preserve_access_index))`` is a clang feature that allows
90+
the BPF verifier to update the offsets for the access at runtime using the
91+
:doc:`/bpf/btf` information. Since the BPF verifier is aware of the types, it
92+
also validates all the accesses made to the various types in the eBPF program.
93+
94+
Loading
95+
-------
96+
97+
eBPF programs can be loaded with the :manpage:`bpf(2)` syscall's
98+
``BPF_PROG_LOAD`` operation:
99+
100+
.. code-block:: c
101+
102+
struct bpf_object *obj;
103+
104+
obj = bpf_object__open("./my_prog.o");
105+
bpf_object__load(obj);
106+
107+
This can be simplified by using a skeleton header generated by ``bpftool``:
108+
109+
.. code-block:: console
110+
111+
# bpftool gen skeleton my_prog.o > my_prog.skel.h
112+
113+
and the program can be loaded by including ``my_prog.skel.h`` and using
114+
the generated helper, ``my_prog__open_and_load``.
115+
116+
Attachment to LSM Hooks
117+
-----------------------
118+
119+
The LSM allows attachment of eBPF programs as LSM hooks using :manpage:`bpf(2)`
120+
syscall's ``BPF_RAW_TRACEPOINT_OPEN`` operation or more simply by
121+
using the libbpf helper ``bpf_program__attach_lsm``.
122+
123+
The program can be detached from the LSM hook by *destroying* the ``link``
124+
link returned by ``bpf_program__attach_lsm`` using ``bpf_link__destroy``.
125+
126+
One can also use the helpers generated in ``my_prog.skel.h`` i.e.
127+
``my_prog__attach`` for attachment and ``my_prog__destroy`` for cleaning up.
128+
129+
Examples
130+
--------
131+
132+
An example eBPF program can be found in
133+
`tools/testing/selftests/bpf/progs/lsm.c`_ and the corresponding
134+
userspace code in `tools/testing/selftests/bpf/prog_tests/test_lsm.c`_
135+
136+
.. Links
137+
.. _tools/lib/bpf/bpf_tracing.h:
138+
https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git/tree/tools/lib/bpf/bpf_tracing.h
139+
.. _tools/testing/selftests/bpf/progs/lsm.c:
140+
https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git/tree/tools/testing/selftests/bpf/progs/lsm.c
141+
.. _tools/testing/selftests/bpf/prog_tests/test_lsm.c:
142+
https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git/tree/tools/testing/selftests/bpf/prog_tests/test_lsm.c

0 commit comments

Comments
 (0)