linux/net/core
Jakub Sitnicki ca5da71a58 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>
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>
2022-04-15 14:18:32 +02:00
..
Makefile
bpf_sk_storage.c bpf: Improve bucket_log calculation logic 2020-02-14 16:34:10 -05:00
datagram.c udp: fix skb_copy_and_csum_datagram with odd segment sizes 2021-02-17 10:35:19 +01:00
datagram.h
dev.c net: annotate data-races on txq->xmit_lock_owner 2021-12-08 09:01:12 +01:00
dev_addr_lists.c net: remove unnecessary variables and callback 2019-10-24 14:53:49 -07:00
dev_ioctl.c net: fix dev_ifsioc_locked() race condition 2021-03-07 12:20:43 +01:00
devlink.c devlink: Hold rtnl lock while reading netdev attributes 2020-12-08 10:40:23 +01:00
drop_monitor.c drop_monitor: fix data-race in dropmon_net_event / trace_napi_poll_hit 2022-02-23 11:59:58 +01:00
dst.c net: print proper warning on dst underflow 2019-09-26 09:05:56 +02:00
dst_cache.c treewide: Replace GPLv2 boilerplate/reference with SPDX - rule 152 2019-05-30 11:26:32 -07:00
ethtool.c net: ethtool: clear heap allocations for ethtool function 2021-06-30 08:47:47 -04:00
failover.c
fib_notifier.c net: fib_notifier: move fib_notifier_ops from struct net into per-net struct 2019-09-07 17:28:22 +02:00
fib_rules.c ipv6: fix memory leak in fib6_rule_suppress 2021-12-08 09:01:13 +01:00
filter.c bpf: Make dst_port field in struct bpf_sock 16-bit wide 2022-04-15 14:18:32 +02:00
flow_dissector.c flow_dissector: Fix out-of-bounds warnings 2021-09-22 12:26:29 +02:00
flow_offload.c net: core: rename indirect block ingress cb function 2019-12-18 16:08:47 +01:00
gen_estimator.c net_sched: gen_estimator: support large ewma log 2021-02-07 15:35:47 +01:00
gen_stats.c treewide: Replace GPLv2 boilerplate/reference with SPDX - rule 152 2019-05-30 11:26:32 -07:00
gro_cells.c
hwbm.c net: hwbm: Make the hwbm_pool lock a mutex 2019-06-09 19:40:10 -07:00
link_watch.c net: linkwatch: fix failure to restore device state across suspend/resume 2021-08-18 08:57:00 +02:00
lwt_bpf.c lwt: Disable BH too in run_lwt_bpf() 2020-12-30 11:51:30 +01:00
lwtunnel.c lwtunnel: Validate RTA_ENCAP_TYPE attribute length 2022-01-11 15:23:32 +01:00
neighbour.c net, neigh: clear whole pneigh_entry at alloc time 2021-12-14 14:49:04 +01:00
net-procfs.c net-procfs: show net devices bound packet types 2022-02-01 17:24:37 +01:00
net-sysfs.c net-sysfs: add check for netdevice being present to speed_show 2022-03-16 13:21:46 +01:00
net-sysfs.h
net-traces.c page_pool: add tracepoints for page_pool with details need by XDP 2019-06-19 11:23:13 -04:00
net_namespace.c netns: add schedule point in ops_exit_list() 2022-01-27 09:19:54 +01:00
netclassid_cgroup.c cgroup, netclassid: remove double cond_resched 2020-05-10 10:31:32 +02:00
netevent.c treewide: Replace GPLv2 boilerplate/reference with SPDX - rule 152 2019-05-30 11:26:32 -07:00
netpoll.c net: Have netpoll bring-up DSA management interface 2020-11-24 13:28:57 +01:00
netprio_cgroup.c netprio_cgroup: Fix unlimited memory leak of v2 cgroups 2020-05-20 08:20:12 +02:00
page_pool.c mm: fix struct page layout on 32-bit systems 2021-05-19 10:08:31 +02:00
pktgen.c pktgen: fix misuse of BUG_ON() in pktgen_thread_worker() 2021-03-07 12:20:44 +01:00
ptp_classifier.c treewide: Replace GPLv2 boilerplate/reference with SPDX - rule 295 2019-06-05 17:36:38 +02:00
request_sock.c tcp: add rcu protection around tp->fastopen_rsk 2019-10-13 10:13:08 -07:00
rtnetlink.c rtnetlink: make sure to refresh master_dev/m_ops in __rtnl_newlink() 2022-02-05 12:35:37 +01:00
scm.c treewide: Replace GPLv2 boilerplate/reference with SPDX - rule 152 2019-05-30 11:26:32 -07:00
secure_seq.c
skbuff.c net: __pskb_pull_tail() & pskb_carve_frag_list() drop_monitor friends 2022-03-02 11:41:06 +01:00
skmsg.c bpf, sockmap: Fix memleak in tcp_bpf_sendmsg while sk msg is full 2022-04-15 14:18:16 +02:00
sock.c esp: Fix possible buffer overflow in ESP transformation 2022-03-28 08:46:44 +02:00
sock_diag.c sock: make cookie generation global instead of per netns 2019-08-09 13:14:46 -07:00
sock_map.c bpf: Fix integer overflow in argument calculation for bpf_map_area_alloc 2021-12-17 10:12:24 +01:00
sock_reuseport.c udp: Prevent reuseport_select_sock from reading uninitialized socks 2021-01-23 15:57:56 +01:00
stream.c net: stream: don't purge sk_error_queue in sk_stream_kill_queues() 2021-11-17 09:48:38 +01:00
sysctl_net_core.c bpf: Prevent increasing bpf_jit_limit above max 2021-11-17 09:48:20 +01:00
timestamping.c
tso.c net: Use skb accessors in network core 2019-07-22 20:47:56 -07:00
utils.c net: Fix skb->csum update in inet_proto_csum_replace16(). 2020-02-05 21:22:52 +00:00
xdp.c xdp: obtain the mem_id mutex before trying to remove an entry. 2019-12-18 16:09:10 +01:00