Skip to content

bpf: Hooks for sys_sendmsg

Andrey Ignatov netdev 4 versions – In review

Get series with b4
b4 am [email protected]

Versions newest first · linked by author and title

  1. v4 Latest6 patches 1 replyIn review
  2. v35 patches 2 repliesApplied
  3. v25 patches 3 repliesSuperseded
Earlier versions · 1
VersionPostedPatchesRepliesStatus
v15 patches6 repliesSuperseded

Changes in v4 from the cover letter

* handle static key correctly for CONFIG_CGROUP_BPF=n.

Patches in v4 No applies recorded yet

#Subject and filesSizeRepliesApplied
1/6bpf: Define cgroup_bpf_enabled for CONFIG_CGROUP_BPF=ninclude/linux/bpf-cgroup.h+1 -01 reply
2/6bpf: Hooks for sys_sendmsginclude/linux/bpf-cgroup.h include/linux/filter.h include/uapi/linux/bpf.h +5 more+125 -90 replies
3/6bpf: Sync bpf.h to tools/tools/include/uapi/linux/bpf.h+8 -00 replies
4/6libbpf: Support guessing sendmsg{4,6} progstools/lib/bpf/libbpf.c+2 -00 replies
5/6selftests/bpf: Prepare test_sock_addr for extensiontools/testing/selftests/bpf/test_sock_addr.c+460 -1950 replies
6/6selftests/bpf: Selftest for sys_sendmsg hookstools/testing/selftests/bpf/Makefile tools/testing/selftests/bpf/sendmsg4_prog.c tools/testing/selftests/bpf/sendmsg6_prog.c +1 more+628 -10 replies

Reviews trailers per patch

All 6 patches have a Reviewed-by or Acked-by.

PatchAlexei StarovoitovMartin KaFai Lau
1/6A-b
2/6A-b A-b
3/6A-b A-b
4/6A-b A-b
5/6A-b A-b
6/6A-b A-b

Trailers given in replies are filled; those carried in the patches from earlier versions are outlined with dashes.

Read the v4 thread

Cover letter [PATCH v4 bpf-next 0/6] bpf: Hooks for sys_sendmsg

v3 -> v4:
* handle static key correctly for CONFIG_CGROUP_BPF=n.

v2 -> v3:
* place BPF logic under static key in udp_sendmsg, udpv6_sendmsg;
* rebase.

v1 -> v2:
* return ENOTSUPP if bpf_prog rewrote IPv6-only with IPv4-mapped IPv6;
* add test for IPv4-mapped IPv6 use-case;
* fix build for CONFIG_CGROUP_BPF=n;
* rebase.

This path set adds BPF hooks for sys_sendmsg similar to existing hooks for sys_bind and sys_connect.

Hooks allow to override source IP (including the case when it's set via cmsg(3)) and destination IP:port for unconnected UDP (slow path). TCP and connected UDP (fast path) are not affected. This makes UDP support
complete: connected UDP is handled by sys_connect hooks, unconnected by sys_sendmsg ones.

Similar to sys_connect hooks, sys_sendmsg ones can be used to make system calls such as sendmsg(2) and sendto(2) return EPERM.

Please see patch 0002 for more details.

Andrey Ignatov (6):
bpf: Define cgroup_bpf_enabled for CONFIG_CGROUP_BPF=n
bpf: Hooks for sys_sendmsg
bpf: Sync bpf.h to tools/
libbpf: Support guessing sendmsg{4,6} progs selftests/bpf: Prepare test_sock_addr for extension selftests/bpf: Selftest for sys_sendmsg hooks

 include/linux/bpf-cgroup.h                   |   24 +-
 include/linux/filter.h                       |    1 +
 include/uapi/linux/bpf.h                     |    8 +
 kernel/bpf/cgroup.c                          |   11 +-
 kernel/bpf/syscall.c                         |    8 +
 net/core/filter.c                            |   39 +
 net/ipv4/udp.c                               |   20 +-
 net/ipv6/udp.c                               |   24 +
 tools/include/uapi/linux/bpf.h               |    8 +
 tools/lib/bpf/libbpf.c                       |    2 +
 tools/testing/selftests/bpf/Makefile         |    2 +-
 tools/testing/selftests/bpf/sendmsg4_prog.c  |   49 ++
 tools/testing/selftests/bpf/sendmsg6_prog.c  |   60 ++
 tools/testing/selftests/bpf/test_sock_addr.c | 1155 +++++++++++++++++++++-----
 14 files changed, 1215 insertions(+), 196 deletions(-)
 create mode 100644 tools/testing/selftests/bpf/sendmsg4_prog.c
 create mode 100644 tools/testing/selftests/bpf/sendmsg6_prog.c
Signature · 1 line
2.9.5