Files
kernel_realme_nemo/include/linux
Andrey Ignatov 60e01af983 UPSTREAM: bpf: Hooks for sys_sendmsg
In addition to already existing BPF hooks for sys_bind and sys_connect,
the patch provides new hooks for sys_sendmsg.

It leverages existing BPF program type `BPF_PROG_TYPE_CGROUP_SOCK_ADDR`
that provides access to socket itlself (properties like family, type,
protocol) and user-passed `struct sockaddr *` so that BPF program can
override destination IP and port for system calls such as sendto(2) or
sendmsg(2) and/or assign source IP to the socket.

The hooks are implemented as two new attach types:
`BPF_CGROUP_UDP4_SENDMSG` and `BPF_CGROUP_UDP6_SENDMSG` for UDPv4 and
UDPv6 correspondingly.

UDPv4 and UDPv6 separate attach types for same reason as sys_bind and
sys_connect hooks, i.e. to prevent reading from / writing to e.g.
user_ip6 fields when user passes sockaddr_in since it'd be out-of-bound.

The difference with already existing hooks is sys_sendmsg are
implemented only for unconnected UDP.

For TCP it doesn't make sense to change user-provided `struct sockaddr *`
at sendto(2)/sendmsg(2) time since socket either was already connected
and has source/destination set or wasn't connected and call to
sendto(2)/sendmsg(2) would lead to ENOTCONN anyway.

Connected UDP is already handled by sys_connect hooks that can override
source/destination at connect time and use fast-path later, i.e. these
hooks don't affect UDP fast-path.

Rewriting source IP is implemented differently than that in sys_connect
hooks. When sys_sendmsg is used with unconnected UDP it doesn't work to
just bind socket to desired local IP address since source IP can be set
on per-packet basis by using ancillary data (cmsg(3)). So no matter if
socket is bound or not, source IP has to be rewritten on every call to
sys_sendmsg.

To do so two new fields are added to UAPI `struct bpf_sock_addr`;
* `msg_src_ip4` to set source IPv4 for UDPv4;
* `msg_src_ip6` to set source IPv6 for UDPv6.

Change-Id: If2579364b20e5184f9340fe6f2036fe40478b591
Signed-off-by: Andrey Ignatov <rdna@fb.com>
Acked-by: Alexei Starovoitov <ast@kernel.org>
Acked-by: Martin KaFai Lau <kafai@fb.com>
Signed-off-by: Daniel Borkmann <daniel@iogearbox.net>
Signed-off-by: Naveen <133593113+elohim-etz@users.noreply.github.com>
2025-12-24 11:40:23 +00:00
..
2021-12-25 18:03:37 +05:30
2021-12-25 18:03:37 +05:30
2021-12-25 18:03:37 +05:30
2021-12-25 18:03:37 +05:30
2021-12-25 18:03:37 +05:30
2021-12-25 18:03:37 +05:30
2025-12-24 11:16:57 +00:00
2022-08-17 15:18:46 +05:30
2021-12-25 18:03:37 +05:30
2021-12-25 18:03:37 +05:30
2022-10-26 13:17:05 +02:00
2025-09-21 09:20:40 +00:00
2021-12-25 18:03:37 +05:30
2021-12-25 18:03:37 +05:30
2025-12-24 11:35:46 +00:00
2023-10-31 18:44:28 +05:30
2020-03-03 00:04:10 +08:00
2025-12-24 11:20:53 +00:00
2021-12-25 18:03:37 +05:30
2021-12-25 18:03:37 +05:30
2023-12-20 15:32:35 +01:00
2019-11-24 08:22:48 +01:00
2021-12-08 08:46:55 +01:00
2025-12-24 11:40:23 +00:00
2021-12-25 18:03:37 +05:30
2025-12-24 11:35:13 +00:00
2020-04-02 16:34:21 +02:00
2021-12-25 18:03:37 +05:30
2020-03-03 00:04:10 +08:00
2021-12-25 18:03:37 +05:30
2021-12-25 18:03:37 +05:30
2021-03-03 18:58:56 +01:00
2020-01-13 19:40:11 +00:00
2025-12-24 11:35:14 +00:00
2019-12-17 21:13:36 +01:00
2021-03-03 18:58:56 +01:00
2022-08-25 11:11:25 +02:00
2021-02-07 14:47:41 +01:00
2020-09-09 19:35:54 +02:00
2025-09-21 09:20:40 +00:00
2021-12-25 18:03:37 +05:30
2019-12-31 12:37:21 +01:00
2021-12-25 18:03:37 +05:30
2021-07-11 12:48:09 +02:00
2021-12-25 18:03:37 +05:30
2021-12-25 18:03:37 +05:30
2021-12-25 18:03:37 +05:30
2021-12-25 18:03:37 +05:30
2020-06-16 12:53:13 -07:00
2020-03-20 10:54:12 +01:00
2019-08-12 13:29:46 -04:00
2021-12-25 18:03:37 +05:30
2020-06-05 16:00:11 +08:00
2021-12-25 18:03:37 +05:30
2025-12-24 11:23:19 +00:00
2019-06-11 12:21:48 +02:00
2023-11-28 16:45:44 +00:00
2021-12-25 18:03:37 +05:30
2021-12-25 18:03:37 +05:30
2020-04-02 16:34:36 +02:00
2021-12-25 18:03:37 +05:30
2020-08-01 00:48:35 +08:00
2020-01-09 14:58:35 -08:00
2025-12-24 11:20:53 +00:00
2021-12-25 18:03:37 +05:30
2025-12-24 11:16:57 +00:00
2021-12-25 18:03:37 +05:30
2020-04-02 16:34:36 +02:00
2021-12-14 10:16:55 +01:00
2021-12-25 18:03:37 +05:30
2021-12-25 18:03:37 +05:30