]> git.proxmox.com Git - mirror_ubuntu-jammy-kernel.git/commit
bpf: Make remote_port field in struct bpf_sk_lookup 16-bit wide
authorJakub Sitnicki <jakub@cloudflare.com>
Wed, 9 Feb 2022 18:43:32 +0000 (19:43 +0100)
committerStefan Bader <stefan.bader@canonical.com>
Wed, 27 Apr 2022 09:59:51 +0000 (11:59 +0200)
commit7263730fec9be3a270feaacdc4afca7e4fe2c471
tree617ba124bfcd5d35c0542466e376d7c10bbfa11f
parent113b8a33c9b53a2f97ae8f8069cb48012e0de5f4
bpf: Make remote_port field in struct bpf_sk_lookup 16-bit wide

BugLink: https://bugs.launchpad.net/bugs/1969107
commit 9a69e2b385f443f244a7e8b8bcafe5ccfb0866b4 upstream.

remote_port is another case of a BPF context field documented as a 32-bit
value in network byte order for which the BPF context access converter
generates a load of a zero-padded 16-bit integer in network byte order.

First such case was dst_port in bpf_sock which got addressed in commit
4421a582718a ("bpf: Make dst_port field in struct bpf_sock 16-bit wide").

Loading 4-bytes from the remote_port offset and converting the value with
bpf_ntohl() leads to surprising results, as the expected value is shifted
by 16 bits.

Reduce the confusion by splitting the field in two - a 16-bit field holding
a big-endian integer, and a 16-bit zero-padding anonymous field that
follows it.

Suggested-by: Alexei Starovoitov <ast@kernel.org>
Signed-off-by: Jakub Sitnicki <jakub@cloudflare.com>
Signed-off-by: Alexei Starovoitov <ast@kernel.org>
Link: https://lore.kernel.org/bpf/20220209184333.654927-2-jakub@cloudflare.com
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
(cherry picked from commit 0c64645e6373761f1f8f292dc122742827f1240e)
Signed-off-by: Paolo Pisati <paolo.pisati@canonical.com>
include/uapi/linux/bpf.h
net/bpf/test_run.c
net/core/filter.c