Files
kernel_samsung_a71/include/uapi/linux
Jakub Sitnicki 08c41d70f6 UPSTREAM: bpf: Make dst_port field in struct bpf_sock 16-bit wide
[ Upstream commit 4421a582718ab81608d8486734c18083b822390d ]

Menglong Dong reports that the documentation for the dst_port field in
struct bpf_sock is inaccurate and confusing. From the BPF program PoV, the
field is a zero-padded 16-bit integer in network byte order. The value
appears to the BPF user as if laid out in memory as so:

  offsetof(struct bpf_sock, dst_port) + 0  <port MSB>
                                      + 8  <port LSB>
                                      +16  0x00
                                      +24  0x00

32-, 16-, and 8-bit wide loads from the field are all allowed, but only if
the offset into the field is 0.

32-bit wide loads from dst_port are especially confusing. The loaded value,
after converting to host byte order with bpf_ntohl(dst_port), contains the
port number in the upper 16-bits.

Remove the confusion by splitting the field into two 16-bit fields. For
backward compatibility, allow 32-bit wide loads from offsetof(struct
bpf_sock, dst_port).

While at it, allow loads 8-bit loads at offset [0] and [1] from dst_port.

Reported-by: Menglong Dong <imagedong@tencent.com>
Change-Id: Id86817d538b4f552ca112639c0a40fb2d8bd9eb9
Signed-off-by: Jakub Sitnicki <jakub@cloudflare.com>
Link: https://lore.kernel.org/r/20220130115518.213259-2-jakub@cloudflare.com
Signed-off-by: Alexei Starovoitov <ast@kernel.org>
Signed-off-by: Sasha Levin <sashal@kernel.org>
2025-10-02 22:15:33 +08:00
..
2018-06-27 11:32:06 +05:30
2024-05-13 18:30:34 +02:00
2024-07-31 15:15:59 +02:00
2019-09-24 08:39:30 -07:00
2023-11-08 11:21:06 +01:00
2018-11-19 11:16:57 +08:00
2024-05-13 18:30:34 +02:00
2024-05-13 18:30:34 +02:00
2024-05-13 18:30:34 +02:00
2021-04-16 11:57:51 +02:00
2018-02-16 20:22:54 +01:00
2021-06-29 13:56:26 +05:30
2018-03-08 14:36:36 -08:00
2018-07-23 20:26:32 -07:00
2019-08-12 13:29:46 -04:00
2018-03-12 02:39:53 -07:00
2020-01-09 14:58:35 -08:00
2023-09-23 10:46:58 +02:00
2025-10-02 22:15:16 +08:00
2024-05-13 18:30:34 +02:00
2022-03-11 10:06:50 +01:00