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
..
2024-07-31 15:16:00 +02:00
2022-08-25 11:11:19 +02:00
2018-08-13 00:42:51 -07:00
2019-09-19 09:08:00 +02:00
2024-05-13 18:30:34 +02:00
2025-09-29 21:58:19 +08:00
2018-11-14 04:46:23 -08:00
2018-06-27 11:32:06 +05:30
2020-06-25 15:42:02 +02:00
2025-09-17 17:26:40 +08:00
2024-05-13 18:30:34 +02:00
2025-10-02 22:14:14 +08:00
2024-10-11 16:00:11 +02:00
2023-08-11 11:33:38 +02:00
2022-12-08 11:16:29 +01:00
2020-09-15 02:54:09 -07:00
2023-08-11 11:33:51 +02:00
2025-10-02 22:12:46 +08:00
2025-10-02 22:15:33 +08:00
2025-10-02 22:13:20 +08:00
2025-10-02 22:14:38 +08:00
2018-12-05 19:41:11 +01:00
2024-03-08 08:21:29 +00:00
2022-11-25 17:36:45 +01:00
2019-12-31 12:36:59 +01:00
2025-02-07 11:46:05 +00:00
2019-08-06 19:05:24 +02:00
2024-05-13 18:30:34 +02:00
2023-05-17 11:11:43 +02:00
2020-04-13 10:34:26 +02:00
2025-09-29 21:59:33 +08:00
2019-06-06 13:01:03 -07:00
2021-01-09 13:37:37 +01:00
2024-05-13 18:30:34 +02:00
2025-10-02 22:13:09 +08:00
2018-03-08 14:36:36 -08:00
2024-07-31 15:15:59 +02:00
2020-08-17 00:53:38 -07:00
2019-09-24 08:39:30 -07:00
2024-07-31 15:15:59 +02:00
2023-11-08 11:21:06 +01:00
2018-11-19 11:16:57 +08:00
2020-05-06 16:00:34 +08:00
2020-02-22 22:09:34 -05:00
2020-12-29 13:46:50 +01:00
2019-02-20 10:20:55 +01:00
2025-10-02 22:14:50 +08:00
2020-03-04 16:09:34 -05:00
2024-05-13 18:30:34 +02:00
2025-10-02 22:14:48 +08:00
2021-06-30 08:48:51 -04:00
2021-01-27 08:19:03 -08:00
2019-02-27 10:08:07 +01:00
2024-10-11 16:00:11 +02:00
2024-07-31 15:16:01 +02:00
2018-01-21 22:20:24 -07:00
2020-03-23 21:20:56 -07:00
2025-10-02 22:13:10 +08:00
2019-02-05 17:36:19 -07:00
2024-05-13 18:30:34 +02:00
2020-01-13 19:40:37 +00:00
2021-01-09 13:37:37 +01:00
2020-05-02 17:24:11 +02:00
2018-02-03 17:39:02 +01:00
2020-09-23 10:46:34 +02:00
2019-02-20 10:20:55 +01:00
2021-01-09 13:37:37 +01:00
2025-10-02 22:13:41 +08:00
2024-05-13 18:30:34 +02:00
2024-05-13 18:30:34 +02:00
2024-08-08 15:52:17 +00:00
2020-01-09 13:19:41 -08:00
2025-09-29 21:58:19 +08:00
2021-01-09 13:37:37 +01:00
2020-09-09 19:03:12 +02:00
2018-02-23 15:42:38 +05:30
2020-08-17 20:03:43 -07:00
2020-08-20 01:16:21 -07:00
2020-02-02 20:08:23 -08:00
2020-04-06 11:25:59 +05:30
2020-03-25 12:43:10 +05:30
2020-07-14 15:33:12 -04:00
2020-04-15 11:54:10 +05:30
2018-08-24 13:09:03 +02:00
2021-04-16 11:57:51 +02:00
2020-01-29 18:00:16 +00:00
2024-10-11 16:00:11 +02:00
2022-01-05 12:33:48 +01:00
2020-11-05 11:07:02 +01:00
2019-07-21 09:04:16 +02:00
2025-01-18 15:31:34 +01:00
2018-11-19 18:19:47 -08:00
2018-12-18 11:29:52 -08:00
2025-10-02 22:13:56 +08:00
2021-12-08 08:46:51 +01:00
2025-10-02 22:13:22 +08:00
2019-10-07 14:56:02 -04:00
2018-02-16 20:22:54 +01:00
2021-06-29 13:56:26 +05:30
2021-06-29 13:56:26 +05:30
2019-07-29 21:05:09 +05:30
2018-05-15 15:15:59 -07:00
2018-03-08 14:36:36 -08:00
2019-08-14 09:28:38 +05:30
2018-07-23 20:26:32 -07:00
2018-03-21 14:35:57 -07:00
2019-01-03 10:22:07 +05:30
2018-10-30 11:01:12 -07:00
2022-06-25 11:46:27 +02:00
2019-05-20 16:47:13 -07:00
2019-08-12 13:29:46 -04:00
2018-11-23 08:19:26 +01:00
2018-05-22 18:54:04 +02:00
2018-05-18 10:28:24 +05:30
2018-05-18 10:28:24 +05:30
2025-10-02 22:13:21 +08:00
2018-04-12 09:39:59 -07:00
2021-09-22 11:45:29 +02:00
2020-04-02 16:34:29 +02:00
2024-08-08 15:52:17 +00:00
2021-09-07 23:21:26 -07:00
2018-07-02 15:18:13 -07:00
2025-10-02 22:15:29 +08:00
2018-03-12 02:39:53 -07:00
2018-05-14 00:06:00 -07:00
2020-01-09 14:58:35 -08:00
2023-01-18 09:26:26 +01:00
2023-09-23 10:46:58 +02:00
2024-10-11 16:00:11 +02:00
2019-03-25 12:40:15 +05:30
2020-06-17 12:53:11 +05:30
2025-10-02 22:15:29 +08:00
2025-10-02 22:14:57 +08:00
2019-06-09 09:18:11 +02:00
2025-10-02 22:15:16 +08:00
2021-05-22 10:57:29 +02:00
2018-11-16 14:44:23 -07:00
2025-09-27 22:38:53 +08:00
2024-05-13 18:30:34 +02:00
2024-10-11 16:00:11 +02:00
2020-01-12 09:42:26 +02:00
2020-09-28 17:55:43 -07:00
2024-10-11 16:00:11 +02:00
2020-01-24 18:05:38 -08:00
2020-12-02 08:34:39 +01:00
2024-05-13 18:30:34 +02:00
2022-03-11 10:06:50 +01:00
2024-10-10 10:27:23 +00:00