aboutsummaryrefslogtreecommitdiffstatshomepage
AgeCommit message (Collapse)AuthorFilesLines
9 dayswireguard: socket: fix sticky source address on p2pHEADstableDavid Woodhouse2-2/+6
WireGuard attempts to reply from the address to which the original packet was sent, caching it in endpoint->src4 and validating it before each use with inet_confirm_addr(..., RT_SCOPE_HOST). For Legacy IP that validation always fails for an address on a point- to-point interface, because confirm_addr_indev() insists on inet_ifa_match(), which compares against ifa_address — the *peer* address on a p2p link — under a /32 mask. The local address is never within that "subnet", so a perfectly valid source address is discarded and send4() falls back to kernel source address selection. For peers on the far side of the p2p link, the fallback happens to select the same address and nobody notices. But when a peer on a local LAN sends to the p2p address (e.g. my OpenWrt box listening on its external PPPoE address), the reply is sent from the LAN interface's own address instead. A stateful firewall on the peer then drops the reply as unrelated to the flow it originated, and the handshake never completes. inet_confirm_addr() is an ARP helper answering "do I have an address on the same subnet as this"; what send4() wants to ask is only "is this still a local address". Use __ip_dev_find() for that, matching what send6() already does with ipv6_chk_addr(). IPv6 does not have this problem. Fixes: e7096c131e51 ("net: WireGuard secure network tunnel") Cc: stable@vger.kernel.org Signed-off-by: David Woodhouse <dwmw@amazon.co.uk> [ Jason: add test to netns.sh to make sure this doesn't resurface. ] Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com>
9 dayswireguard: timers: mark racy persistent_keepalive_interval accessesNguyen Ngoc Thang2-5/+6
wg_set_device_doit() updates peer->persistent_keepalive_interval under device_update_lock, while the RX/TX paths read it locklessly in wg_timers_any_authenticated_packet_traversal() and in the persistent keepalive timer. KCSAN reports the race: BUG: KCSAN: data-race in set_peer / wg_timers_any_authenticated_packet_traversal write to ... by task 3648 on cpu 1: set_peer+0x... drivers/net/wireguard/netlink.c:457 wg_set_device_doit+0x... read to ... by task 3652 on cpu 0: wg_timers_any_authenticated_packet_traversal+0x... timers.c:217 wg_packet_consume_data_done+0x... wg_packet_rx_poll+0x... The race is benign, but the reader also loads the field twice, so the zero check and the timer expiry computation can see different values. Load it once with READ_ONCE() and mark the writer and the other lockless reader accordingly. Reported-by: syzbot+de9701a2cad597c14d34@syzkaller.appspotmail.com Closes: https://syzkaller.appspot.com/bug?extid=de9701a2cad597c14d34 Fixes: e7096c131e51 ("net: WireGuard secure network tunnel") Signed-off-by: Nguyen Ngoc Thang <ngocthang2710.1999@gmail.com> Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com>
9 daysnet: mana: fix XDP_REDIRECT of pre-allocated RX buffersdavem/netOrgad Shaneh3-4/+21
mana_pre_alloc_rxbufs() fills the RX rings with plain pages from dev_alloc_pages() (from_pool == false), but the rxq is registered with MEM_TYPE_PAGE_POOL and mana_run_xdp() builds every xdp_buff with that rxq info. mana_rx_skb() frees a !from_pool buffer correctly on XDP_PASS, XDP_TX and XDP_DROP, but a redirected buffer is freed through its memory model: __xdp_return() hands the plain page to page_pool_put_full_netmem(). This triggers the WARN in include/net/page_pool/helpers.h, breaks the page refcount, RX refills fail and the queue stops receiving. The pre-allocated buffers fill the whole ring of every rxq created by an MTU change, by ethtool -L / -G and, since commit 730ff06d3f5c ("net: mana: Use page pool fragments for RX buffers instead of full pages to improve memory efficiency."), by every XDP attach and detach. So on current kernels the first ring of redirected packets after attaching an XDP program always hits this. Reproduced on 7.2.11, and on 6.12.113 after ethtool -L, on an Azure MANA VF: an XDP program that redirects UDP to an XSKMAP with an AF_XDP socket in copy mode gives WARNINGs at __xdp_return+0x249 (stack __xsk_map_redirect, xdp_do_redirect, mana_run_xdp, mana_poll), then the queue stops. Give each rxq a second xdp_rxq_info registered with MEM_TYPE_PAGE_SHARED, the model these buffers had before the page pool was added, and use it for buffers that are not from the pool. Those buffers are already DMA-unmapped by mana_refill_rx_oob() before XDP runs, and page_frag_free() frees them whatever their order. Allocating the pre-allocated buffers from the page pool instead would need the pools to exist before the rxqs and to outlive them, a much larger change. Found, fixed and tested with an AI coding assistant (Claude Code). Fixes: b1d13f7a3b53 ("net: mana: Add page pool for RX buffers") Signed-off-by: Orgad Shaneh <orgads@gmail.com> Link: https://patch.msgid.link/20261102064324.806414-1-orgads@gmail.com Signed-off-by: Jakub Kicinski <kuba@kernel.org>
9 daysnet: usb: lan78xx: let unregister_netdev() stop phylinkYuanZhe Liu1-3/+2
lan78xx_disconnect() stops phylink before unregistering the net device. phylink_start() is only called from lan78xx_open(), so when the device is unplugged before the interface has been brought up, the attached PHY is still in PHY_READY and phy_stop() reports: called from state READY WARNING: drivers/net/phy/phy.c:1670 at phy_stop+0xad/0x380 The same warning is emitted after an ifup/ifdown cycle, where the PHY is already in PHY_HALTED. unregister_netdev() already closes a running device, which calls lan78xx_stop() and phylink_stop() with dev->dev_mutex held and after the URBs have been terminated. Unregister first and disconnect the PHY afterwards, so the interface is stopped exactly once and only while it is running, and the net device can no longer be opened while its phylink instance has no PHY attached. Fixes: e110bc825897 ("net: usb: lan78xx: Convert to PHYLINK for improved PHY and MAC management") Cc: stable@vger.kernel.org Co-developed-by: Bin Yu <byu@xidian.edu.cn> Signed-off-by: Bin Yu <byu@xidian.edu.cn> Co-developed-by: Cheng Wen <wencheng@xidian.edu.cn> Signed-off-by: Cheng Wen <wencheng@xidian.edu.cn> Signed-off-by: YuanZhe Liu <25031212351@stu.xidian.edu.cn> Reviewed-by: Oleksij Rempel <o.rempel@pengutronix.de> Link: https://patch.msgid.link/20261031165213.2738-1-25031212351@stu.xidian.edu.cn Signed-off-by: Jakub Kicinski <kuba@kernel.org>
9 daysnet: gro: avoid parsing headers from shared fragmentsKyle Zeng1-1/+2
When an skb has an empty linear head, skb_gro_reset_offset() can expose the first page fragment directly to GRO header parsers. For an SKBFL_SHARED_FRAG skb, those bytes may still be writable through a file mapping. Headers validated during receive can therefore differ from the headers later copied into the linear head and used during completion. For example, changing an IPv6 destination-options length between the short and full header fetches in ipv6_gro_pull_exthdrs() can make ipv6_gro_complete() pass an out-of-bounds offset to udp6_gro_complete(). A userspace reproducer triggered a KASAN slab-out-of-bounds read there on an unmodified kernel as UID 1000. The same completion path can write the UDP checksum and length through the invalid offset. The packet has trusted TCP GSO metadata and spliced file data, so it reaches completion without an skb zerocopy destructor or a second GRO packet. Disable the direct-fragment fast path for skbs with externally writable fragments. With an empty linear head, frag0_len remains zero, so skb_gro_header_slow() pulls each required header into the linear head before it is inspected. Subsequent pulls preserve the validated prefix. This covers both gro_receive_skb() and napi_gro_frags(), including other protocols using the same helpers. Linear headers and private fragments retain their existing fast paths. Codex assisted with review of the supplied report, reproducer and draft fix, related-path analysis, and this changelog. The patched net/core/gro.o builds with W=1 using the supplied x86-64 configuration, allyesconfig and allmodconfig. The fix was checked by code-path analysis; the reproducer and kernel selftests have not been run on a booted patched kernel. The issue was found by an LLM. Fixes: dff0b0161ad5 ("net: gro: parse ipv6 ext headers without frag0 invalidation") Cc: stable@kernel.org Signed-off-by: Kyle Zeng <kylebot@openai.com> Link: https://patch.msgid.link/20261031050752.31869-1-kylebot@openai.com Signed-off-by: Jakub Kicinski <kuba@kernel.org>
9 daysMAINTAINERS: Add Hidayath as net/iucv maintainerAlexandra Winter1-1/+1
Hidayath Khan takes over maintership of s390's iucv transport mechanism and af_iucv sockets from Thorsten Winkler. Thank you for your support Thorsten, and thank you Hidayath for taking on this task. Acked-by: Hidayath Khan <hidayath@linux.ibm.com> Acked-by: Thorsten Winkler <twinkler@linux.ibm.com> Signed-off-by: Alexandra Winter <wintera@linux.ibm.com> Link: https://patch.msgid.link/20261104085605.2040729-1-wintera@linux.ibm.com Signed-off-by: Paolo Abeni <pabeni@redhat.com>
9 daysMerge branch 'net-fix-mac_len-of-skbs-copied-by-generic-xdp'Paolo Abeni3-3/+44
Tianyi Gao says: ==================== net: fix mac_len of skbs copied by generic XDP Generic XDP copies the skb before it runs a program with frags support. The copy happens when the skb is cloned, nonlinear, or has less than 256 bytes of headroom. skb_pp_cow_data() makes the copy, but it does not copy mac_len. After XDP, the skb has mac_len 0. Two places after generic XDP move skb->data by mac_len: - On XDP_REDIRECT to a cpumap, cpu_map_generic_redirect() pulls mac_len bytes, the length of the Ethernet header. Then it queues the skb to the target CPU. With mac_len 0, the IP layer on that CPU sees the Ethernet header and drops the packet. - On XDP_PASS, the skb can go on to tc ingress with a BPF program attached (tcx, cls_bpf or act_bpf). Before it runs the program, tc pushes mac_len bytes, the length of the Ethernet header. With mac_len 0, skb->data stays at the IP header. Therefore, the program reads the IP header as the Ethernet header. Patch 1 copies mac_len in skb_pp_cow_data(). Patch 2 adds a test to drivers/net/ping.py. The test redirects packets to a cpumap in generic XDP. On netdevsim, the test fails without patch 1. ==================== Link: https://patch.msgid.link/20261103200036.65764-2-tianyi@cloudflare.com Signed-off-by: Paolo Abeni <pabeni@redhat.com>
9 daysselftests: drv-net: ping: test generic XDP redirect to cpumapTianyi Gao2-3/+43
The generic XDP tests in ping.py only cover XDP_PASS. Add a test that redirects all packets to a cpumap with an xdp.frags program. It runs the same ping and TCP checks as the other tests. xdp_cpumap.bpf.c is a new program. It redirects every packet to entry 0 of a cpumap. It is not added to xdp_dummy.bpf.c. test_xdp_offload loads xdp_dummy.bpf.o in offload mode, which would fail on a cpumap. The new test extends _set_xdp_generic_mb_on() with two optional arguments. The first argument, prog, is the XDP program file name, with default "xdp_dummy.bpf.o". The second argument, on_attach, is a callback function, with default None. on_attach runs right after the program is attached. The new test passes "xdp_cpumap.bpf.o" to prog and a lambda that adds the cpumap entry to on_attach. Without the previous patch, the new test fails on netdevsim because ping gets no reply. Signed-off-by: Tianyi Gao <tianyi@cloudflare.com> Link: https://patch.msgid.link/20261103200036.65764-4-tianyi@cloudflare.com Signed-off-by: Paolo Abeni <pabeni@redhat.com>
9 daysnet: fix mac_len of skbs copied by generic XDPTianyi Gao1-0/+1
skb_pp_cow_data() copies the header fields of the old skb with skb_copy_header(). skb_copy_header() does not copy mac_len. Generic XDP uses skb_pp_cow_data() for programs with frags support. After such a program, the skb can have mac_len 0. cpu_map_generic_redirect() and tc ingress then get the position of the Ethernet header wrong. Copy mac_len in skb_pp_cow_data(), as dev_map_generic_redirect() does after skb_copy(). Fixes: e6d5dbdd20aa ("xdp: add multi-buff support for xdp running in generic mode") Signed-off-by: Tianyi Gao <tianyi@cloudflare.com> Reviewed-by: Toke Høiland-Jørgensen <toke@redhat.com> Link: https://patch.msgid.link/20261103200036.65764-3-tianyi@cloudflare.com Signed-off-by: Paolo Abeni <pabeni@redhat.com>
9 daysnet: dsa: microchip: initialize the IRQ access mutexTapio Reijonen1-0/+1
ksz_switch_register() initializes dev_mutex, regmap_mutex, alu_mutex and vlan_mutex but not lock_irq, which the IRQ chip takes in its bus lock callbacks on every mask and unmask of a switch interrupt, and the PTP code takes the same way. The zeroed mutex happens to work on the uncontended fast path, but with CONFIG_DEBUG_MUTEXES the first lock, from the IRQ domain mapping during probe, warns: DEBUG_LOCKS_WARN_ON(lock->magic != lock) WARNING: kernel/locking/mutex.c:625 at __mutex_lock ... ksz_irq_domain_map irq_domain_associate_locked irq_create_mapping_affinity ksz_irq_common_setup ksz9477_setup dsa_register_switch ksz_spi_probe and turns lock debugging off for the rest of the boot. Initialize it with the other mutexes. Triggered at every boot of a KSZ9897S over SPI on an i.MX6 SoloX board with CONFIG_DEBUG_MUTEXES, on v7.4-rc1 and earlier. With this patch the same board boots with lock debugging enabled and it stays enabled (debug_locks 1) through two hours of unrelated stress tests. Fixes: c9cd961c0d43 ("net: dsa: microchip: lan937x: add interrupt support for port phy link") Cc: stable@vger.kernel.org Signed-off-by: Tapio Reijonen <tapio.reijonen@vaisala.com> Reviewed-by: Daniel Machon <daniel.machon@microchip.com> Link: https://patch.msgid.link/20261104-ksz-irq-mutex-init-v1-1-e3bb7d9dbd80@vaisala.com Signed-off-by: Paolo Abeni <pabeni@redhat.com>
9 daysMerge branch 'xsk-fix-multi-buffer-tx-software-checksum'Paolo Abeni2-60/+104
Rongzheng Wang says: ==================== xsk: fix multi-buffer TX software checksum This is v5 of the AF_XDP multi-buffer TX software checksum fix. I found this while testing multi-buffer TX with XDP_UMEM_TX_SW_CSUM: a two-descriptor packet had a bad wire checksum, while a single descriptor was correct. There was no production or syzbot report. Patch 1 moves the software checksum calculation from xsk_skb_metadata() to the point where the last descriptor has been added to the skb. The old code calculated the checksum after the first descriptor, so multi-buffer packets only included the first fragment in the checksum. Patch 2 sends the packet using every descriptor count from 1 through MAX_SKB_FRAGS + 1, and runs the existing metadata and checksum verification for each case. The last case is the copy-mode frame limit documented in af_xdp.rst. The updated selftest passes in a local QEMU run. v4: https://lore.kernel.org/all/20261030023248.78802-1-testwrzwrz@gmail.com/ v3: https://lore.kernel.org/all/20261028025026.11401-1-testwrzwrz@gmail.com/ v2: https://lore.kernel.org/all/20261024141157.59301-1-testwrzwrz@gmail.com/ v1: https://lore.kernel.org/all/20261024091256.17918-1-testwrzwrz@gmail.com/ ==================== Link: https://patch.msgid.link/20261104034809.24545-1-testwrzwrz@gmail.com Signed-off-by: Paolo Abeni <pabeni@redhat.com>
9 daysselftests/bpf: cover AF_XDP multi-buffer TX software checksumRongzheng Wang1-52/+89
Extend test_xdp_metadata to send the same UDP packet using every descriptor count from 1 through MAX_TX_DESCS (MAX_SKB_FRAGS + 1), and to run the existing metadata and checksum verification for each case. Build the packet once and write it into the TX descriptors in a loop instead of using a flat two-descriptor layout. Keep the first descriptor large enough to cover the checksum offset; the remaining payload is split across the continuation descriptors, with the last descriptor taking the remaining length. Reuse the existing AF_XDP setup, packet generation, completion, and receive helpers in xdp_metadata.c instead of adding a separate test harness. Reviewed-by: Maciej Fijalkowski <maciej.fijalkowski@intel.com> Acked-by: Stanislav Fomichev <sdf@fomichev.me> Signed-off-by: Rongzheng Wang <testwrzwrz@gmail.com> Link: https://patch.msgid.link/20261104034809.24545-3-testwrzwrz@gmail.com Signed-off-by: Paolo Abeni <pabeni@redhat.com>
9 daysxsk: defer software checksum until the skb is completeRongzheng Wang1-8/+15
When XDP_UMEM_TX_SW_CSUM is used with multi-buffer TX, xsk_skb_metadata() calls skb_checksum_help() while only the first descriptor has been added to the skb. The checksum therefore covers just the first fragment, and skb_checksum_help() sets ip_summed to CHECKSUM_NONE, so the remaining fragments are never included in the checksum. Move the software checksum calculation to the point where the last descriptor has been added to the skb. On a checksum failure the packet is now dropped instead of being returned to the application for a retry. This path is not reachable with the existing metadata validation, but the behavior change is intentional. Fixes: 11614723af26 ("xsk: Add option to calculate TX checksum in SW") Cc: stable@vger.kernel.org Reviewed-by: Maciej Fijalkowski <maciej.fijalkowski@intel.com> Acked-by: Stanislav Fomichev <sdf@fomichev.me> Reviewed-by: Jason Xing <kerneljasonxing@gmail.com> Signed-off-by: Rongzheng Wang <testwrzwrz@gmail.com> Link: https://patch.msgid.link/20261104034809.24545-2-testwrzwrz@gmail.com Signed-off-by: Paolo Abeni <pabeni@redhat.com>
9 daysinet: frags: bound the wmem charge of the socket completing a reassemblyEric Dumazet4-22/+78
When a socket owned fragment completes a reassembly queue, inet_frag_reasm_prepare() and inet_frag_reasm_finish() charge the truesize of all other fragments to its sk_wmem_alloc. These fragments were orphaned when queued, and might have been sent by someone else, for instance padded TUN packets. Commit 3ae20e4697eb ("inet: frags: limit the truesize of a reassembly queue") bounds this charge to INT_MAX / 2 per queue, but a socket can complete several queues while the reassembled skbs are still alive, for instance held in a qdisc. sk_wmem_alloc can then go past INT_MAX, refcount_add() saturates it with a WARN, and the socket is leaked. This is reachable from an unprivileged user/network namespace, by raising ipfrag_high_thresh. Refuse the reassembly if the charge would push sk_wmem_alloc above 2 * sk_sndbuf, the bound ip_append_data() uses, plus 4MB of slack for fragments inflated by a refragmentation with a small MTU, and never above INT_MAX / 2. The cap matters for tun sockets, which use sk_sndbuf = INT_MAX, and whose skbs are still owned when act_ct or openvswitch reassemble them at ingress. Several queues can complete at the same time on different cpus for the same socket, so the charge is reserved with a cmpxchg() loop in inet_frag_reasm_prepare(), before it modifies the queue, and settled in inet_frag_reasm_finish(). Move the size checks of ip_frag_reasm(), ip6_frag_reasm() and nf_ct_frag6_reasm() before inet_frag_reasm_prepare(), using the first fragment which becomes the head, so that a successful inet_frag_reasm_prepare() is always followed by inet_frag_reasm_finish(). All callers already kill the queue when inet_frag_reasm_prepare() returns NULL. Found by code inspection (AI review), not reproduced. Fixes: 18685451fc4e ("inet: inet_defrag: prevent sk release while still in use") Reported-by: Paolo Abeni <pabeni@redhat.com> Closes: https://lore.kernel.org/netdev/24feda7d-ae49-45af-9596-2cc5f149f28e@redhat.com/ Signed-off-by: Eric Dumazet <edumazet@kernel.org> Reviewed-by: Ido Schimmel <idosch@nvidia.com> Link: https://patch.msgid.link/20261104122927.1033747-1-edumazet@kernel.org Signed-off-by: Paolo Abeni <pabeni@redhat.com>
10 daysipvlan: make outbound skb headers writableKyle Zeng1-2/+4
In L3 and L3S modes, ipvlan_process_v4_outbound() and ipvlan_process_v6_outbound() hand the skb to ip_local_out() and ip6_local_out(). The IP output path assumes it owns the network header: __ip_local_out() rewrites tot_len and the header checksum, and transport-mode XFRM can memmove the network header into the headroom when xfrm_skb_check_space() finds enough room, without copying. The skb reaching ipvlan can have its header shared with another skb, for example after an AF_PACKET tap on the ipvlan device or a tc mirred mirror action. pskb_network_may_pull() only makes the header linear; it does not unshare an already linear head. The writes above then modify the other skb. If that skb is on the receive path and its IPv4 header was already validated, IPv4 option processing can use the modified header, write past the linear data, and corrupt skb_shared_info. Use skb_cow_head() before taking header pointers and entering the local IP output path, like ip_forward() does with skb_cow() before it touches the header. Only checking skb_header_cloned() is enough here: skbs that TCP transmits are clones of the write-queue skb, whose header area has been released with __skb_header_release(). Their headers are private, so they are not copied, which avoids a reallocation for every TCP segment sent through an ipvlan slave. If the allocation fails, the existing error accounting and drop paths are used. L2 mode is unaffected. [edumazet: use skb_cow_head() instead of skb_unclone() to avoid copying every TCP segment, reword changelog] Fixes: 2ad7bf363841 ("ipvlan: Initial check-in of the IPVLAN driver.") Signed-off-by: Kyle Zeng <kylebot@openai.com> Signed-off-by: Eric Dumazet <edumazet@kernel.org> Link: https://patch.msgid.link/20261104113530.986664-1-edumazet@kernel.org Signed-off-by: Jakub Kicinski <kuba@kernel.org>
10 daysnet: require a full socket in sock_confirm_neigh()Kyle Zeng1-9/+10
An skb can retain dst_pending_confirm after its original output and socket owner have changed. For example, a raw MSG_CONFIRM packet can cross veth, have a TCP request socket assigned by TPROXY, and be bridged into gretap. Neighbor output for the outer packet then calls sock_confirm_neigh() with the request socket in skb->sk. The helper unconditionally treats a non-NULL skb->sk as a full socket when accessing sk_dst_pending_confirm. TCP request and TIME_WAIT sockets do not contain that field. This produces an out-of-bounds four-byte read and, if the word is nonzero, an out-of-bounds four-byte zero write. A KASAN-enabled kernel reports: BUG: KASAN: slab-out-of-bounds in ip_finish_output2+0xc9f/0xd60 Read of size 4 at addr ffff8880bdc3d880 by task tproxy_dst_conf/1771 Require sk_fullsock() before accessing the socket field, moving the existing helper earlier in the header to make it available here. Keep neigh_confirm() independent of the socket type so the skb's neighbor confirmation still works, including for socketless packets. This also covers the IPv6, VRF, and BPF neighbor-output callers. Fixes: 4ff0620354f2 ("net: add dst_pending_confirm flag to skbuff") Signed-off-by: Kyle Zeng <kylebot@openai.com> Signed-off-by: Eric Dumazet <edumazet@kernel.org> Reviewed-by: Kuniyuki Iwashima <kuniyu@google.com> Link: https://patch.msgid.link/20261104132900.1071940-1-edumazet@kernel.org Signed-off-by: Jakub Kicinski <kuba@kernel.org>
10 daysnet: protect negative destination advice with RCUKyle Zeng1-1/+4
SO_CNX_ADVICE calls __dst_negative_advice() while holding the socket lock. Connected UDP sends can still invalidate or replace sk_dst_cache without that lock. A concurrent sk_dst_check() can drop the final destination reference and allow an RCU callback to destroy it while __dst_negative_advice() retains only a borrowed pointer. This can cause a use-after-free while accessing dst->ops or running the negative_advice callback. The writer-side ordering fixed by commit 92f1655aa2b2 ("net: fix __dst_negative_advice() race") does not protect this reader from an independent cache replacement. Hold an RCU read-side critical section across the lookup and callback. This follows the datagram release callbacks and covers IPv4, IPv6, and XFRM advice without changing cache-reset or reference-ownership rules. Fixes: a87cb3e48ee8 ("net: Facility to report route quality of connected sockets") Signed-off-by: Kyle Zeng <kylebot@openai.com> Signed-off-by: Eric Dumazet <edumazet@kernel.org> Reviewed-by: Jiayuan Chen <jiayuan.chen@linux.dev> Reviewed-by: Kuniyuki Iwashima <kuniyu@google.com> Link: https://patch.msgid.link/20261104131744.1056562-1-edumazet@kernel.org Signed-off-by: Jakub Kicinski <kuba@kernel.org>
10 daysdocs: netdev: fix iproute2 process documentationWillem de Bruijn2-24/+41
The instructions on sending patches to iproute2 span both netdev and bpf docs, contain outdated references and miss some instructions. Address this: - Move all info to maintainer-netdev - Add a link in bpf_devel_QA to this location - Update URLs to git repositories - Update URLs to patchwork instance and delegates - Update subject prefix rules - Add suggestion to Cc: maintainers - Add pointer to iproute2 MAINTAINERS - Add pointer to iproute2 README.devel Acked-by: Alexei Starovoitov <ast@kernel.org> Signed-off-by: Willem de Bruijn <willemb@google.com> Link: https://patch.msgid.link/20261105184510.3230744-1-willemdebruijn.kernel@gmail.com Signed-off-by: Jakub Kicinski <kuba@kernel.org>
10 daysnet/mlx5: Lag, free steering resources on LAG destroy failureMark Bloch1-2/+1
When firmware fails to destroy LAG, driver returns before releasing the steering resources, leaking the associated software objects. The bond is no longer eligible for offload, and the driver cannot prevent its teardown. Release the steering resources even if LAG destruction fails. Preserve the error logging and return the original error after cleanup. Fixes: da6b0bb0fc73 ("net/mlx5: Lag, use steering to select the affinity port in LAG") Signed-off-by: Mark Bloch <mbloch@nvidia.com> Reviewed-by: Shay Drori <shayd@nvidia.com> Signed-off-by: Tariq Toukan <tariqt@nvidia.com> Link: https://patch.msgid.link/20261104183947.772195-1-tariqt@nvidia.com Signed-off-by: Jakub Kicinski <kuba@kernel.org>
10 daysnet/mlx5: Use only loaded devices for PTP clock operationsCarolina Jubran2-65/+185
The PTP periodic worker and PTP operations access PCI registers through the function backing the PTP clock. The PTP clock remains registered when a PCI function is suspended, so these paths can still access the function after it has been unloaded. To fix that, serialize clock hardware access with the clock mutex for all clocks and fail callbacks with -EAGAIN when there is no loaded function to service the clock. Additionally, tie the worker's lifetime to load/unload and use the devcom lock to synchronize with peer loads/unloads. Since the periodic worker is stopped during unload, the free running counter may wrap without being sampled. Reinitialize the timecounter on load using the hardware real time clock in real time mode, or the saved PHC time plus elapsed CLOCK_BOOTTIME in free running mode. This provides best effort PHC continuity across unload/load. In free running mode, elapsed time while unloaded is estimated using CLOCK_BOOTTIME rather than the PHC's adjusted frequency. Fixes: 8fc3e29be924 ("net/mlx5: Fix crash upon suspend/resume") Signed-off-by: Carolina Jubran <cjubran@nvidia.com> Reviewed-by: Cosmin Ratiu <cratiu@nvidia.com> Signed-off-by: Tariq Toukan <tariqt@nvidia.com> Link: https://patch.msgid.link/20261104183158.758314-1-tariqt@nvidia.com Signed-off-by: Jakub Kicinski <kuba@kernel.org>
10 daysnet: octeontx2: fix building without DEBUGFSArnd Bergmann1-5/+0
This error came up on my randconfig tests this week: drivers/net/ethernet/marvell/octeontx2/af/cn20k/debugfs.c: In function 'npc_cn20k_debugfs_init': drivers/net/ethernet/marvell/octeontx2/af/cn20k/debugfs.c:392:55: error: 'struct rvu' has no member named 'rvu_dbg'; did you mean 'rvu_dl'? 392 | debugfs_create_file("mcam_layout", 0444, rvu->rvu_dbg.npc, The problem here is that the rvu_dbg member is hidden in an #ifdef block, but the reference to it is not. Remove the #ifdef and waste a few bytes in the structure in this config. Note that the debugfs_create_file() call end up ignoring the arguments, so the actual debugfs implementation is still ignored here. Fixes: 528530dff56b ("octeontx2-af: npc: cn20k: add debugfs support") Signed-off-by: Arnd Bergmann <arnd@arndb.de> Acked-by: Ratheesh Kannoth <rkannoth@marvell.com> Link: https://patch.msgid.link/20261105161945.1658464-1-arnd@kernel.org Signed-off-by: Jakub Kicinski <kuba@kernel.org>
10 daysteam: fix promisc/allmulti leak in team_port_add error pathLi RongQing1-4/+5
team_port_add() increments the port's promiscuity and allmulti counts before calling team_dev_type_check_change(). If the latter fails, the error path does not undo these increments, leaving the port in promiscuous and allmulti mode even though it was not successfully added to the team. Undo the promiscuity increment under err_set_slave_allmulti and the allmulti increment under err_set_dev_type, so each error label only reverts what was successfully applied, matching the cleanup performed by team_port_del(). With the promiscuity rollback now living under err_set_slave_allmulti, the inline dev_set_promiscuity(port_dev, -1) in the dev_set_allmulti() failure branch becomes redundant: that branch already jumps to err_set_slave_allmulti, which undoes the promiscuity increment. Drop the inline call to avoid doing it twice. Found by source code audit. Fixes: 0ae9cfc454ea ("team: Move team device type change at the end of team_port_add") Signed-off-by: Li RongQing <lirongqing@baidu.com> Reviewed-by: Hangbin Liu <liuhangbin@kylinos.cn> Link: https://patch.msgid.link/20261104015217.2222-1-lirongqing@baidu.com Signed-off-by: Jakub Kicinski <kuba@kernel.org>
10 daysnet: wait for in-flight device unregistrations before netns dismantleEric Dumazet2-0/+36
A device can be unregistered by a context other than the cleanup_net() of its own netns, for instance a veth whose peer in another netns is deleted. If references on it are still held, it stays in netdev_wait_allrefs_any(), which rebroadcasts NETDEV_UNREGISTER every second. Meanwhile its netns can be dismantled: default_device_exit_batch() only takes care of devices still listed in the netns, then pernet exit handlers free their state, and finally struct net is freed while the device still points to it. The rebroadcasts then run notifiers against torn down pernet state, or freed memory. Three instances were reported so far: - netdev_genl_netdevice_event(): net->genl_sock is NULL [1] - nh_netdev_event(): net->nexthop.devhash is NULL [2] - nf_tables netdevice notifiers: use-after-free of the nftables pernet storage [3] but any notifier using dev_net(dev) is affected, as is netdev_wait_allrefs_any() itself (__rtnl_net_lock(dev_net(dev)) with CONFIG_DEBUG_NET_SMALL_RTNL=y). This was prevented by rtnl_lock_unregistering() until I removed it in commit 8a4fc54b07d7 ("net: get rid of rtnl_lock_unregistering()"), considering only the loopback dependency, and missing the notifiers one. Restore a per-netns counter of devices sitting in netdev_run_todo(), and make default_device_exit_batch() wait for it to reach zero, after it has unregistered all devices of the dying netns(es). At this point no new unregistration can be started for these netns. Unlike the old barrier, this only waits for devices of the netns being dismantled and runs after their own devices are gone. Tested on a KASAN kernel with a debug-only hack holding a reference on a veth device for 5 seconds after its unregistration: a nexthop on the veth in netns X, delete its peer from init_net, then delete X. Without this patch, the nexthop_flush_dev() null-ptr-deref from [2] triggers. With it, no splat; netns churn and dismantle of a netns whose own device is held still work. [1] https://lore.kernel.org/netdev/6adf9f64.6200f071.51519.0ed1.GAE@google.com/ [2] https://lore.kernel.org/netdev/20261105114707.3030737-1-bsdhenrymartin@gmail.com/ [3] https://lore.kernel.org/netdev/20261105114817.3033625-1-bsdhenrymartin@gmail.com/ Fixes: 8a4fc54b07d7 ("net: get rid of rtnl_lock_unregistering()") Cc: stable@vger.kernel.org Reported-by: syzbot+1269fe6cc2016008124e@syzkaller.appspotmail.com Closes: https://lore.kernel.org/netdev/6adf9f64.6200f071.51519.0ed1.GAE@google.com/ Reported-by: Henry Martin <bsdhenrymartin@gmail.com> Closes: https://lore.kernel.org/netdev/20261105114707.3030737-1-bsdhenrymartin@gmail.com/ Closes: https://lore.kernel.org/netdev/20261105114817.3033625-1-bsdhenrymartin@gmail.com/ Signed-off-by: Eric Dumazet <edumazet@kernel.org> Reviewed-by: Naman Gulati <namangulati@google.com> Link: https://patch.msgid.link/20261105144543.1624238-1-edumazet@kernel.org Signed-off-by: Jakub Kicinski <kuba@kernel.org>
10 daysMerge patch series "ipv6: ignore link state in gateway check"Jakub Kicinski2-1/+41
Yaroslav Dudkov says: ==================== IPv6 gateway validation can reject routes in non-main tables when ignore_routes_with_linkdown is enabled and the nexthop device has no carrier, even though these routes should be added. Fix this by ignoring link state during gateway validation and add a regression selftest covering IPv4 and IPv6 route installation. ==================== Link: https://patch.msgid.link/20261104195655.1406837-1-aroslavdudkov622@gmail.com Signed-off-by: Jakub Kicinski <kuba@kernel.org>
10 daysselftests: fib_tests: Add carrier gateway testYaroslav Dudkov1-0/+40
Test adds routes with a gateway while the nexthop device has no carrier and ignore_routes_with_linkdown is enabled on it. The routes are added to the main table and to a non-main table, with and without a device, for both IPv4 and IPv6. Routes are expected to be accepted disregarding the link state. Without the previous patch, the IPv6 non-main table cases fail: Without fix: Gateway validation with carrier down TEST: IPv4 route in main table [ OK ] TEST: IPv6 route in main table [ OK ] TEST: IPv4 route in non-main table [ OK ] TEST: IPv6 route in non-main table [FAIL] TEST: IPv4 route in non-main table without device [ OK ] TEST: IPv6 route in non-main table without device [FAIL] TEST: IPv4 linkdown flag set [ OK ] TEST: IPv6 linkdown flag set [FAIL] With fix: Gateway validation with carrier down TEST: IPv4 route in main table [ OK ] TEST: IPv6 route in main table [ OK ] TEST: IPv4 route in non-main table [ OK ] TEST: IPv6 route in non-main table [ OK ] TEST: IPv4 route in non-main table without device [ OK ] TEST: IPv6 route in non-main table without device [ OK ] TEST: IPv4 linkdown flag set [ OK ] TEST: IPv6 linkdown flag set [ OK ] Suggested-by: Ido Schimmel <idosch@nvidia.com> Signed-off-by: Yaroslav Dudkov <aroslavdudkov622@gmail.com> Tested-by: Hangbin Liu <liuhangbin@kylinos.cn> Reviewed-by: Hangbin Liu <liuhangbin@kylinos.cn> Reviewed-by: Ido Schimmel <idosch@nvidia.com> Link: https://patch.msgid.link/20261104195655.1406837-3-aroslavdudkov622@gmail.com Signed-off-by: Jakub Kicinski <kuba@kernel.org>
10 daysipv6: ignore link state in gateway checkYaroslav Dudkov1-1/+1
IPv6 route cannot be added in table when all following conditions are true: - gateway is not link-local address - ignore_routes_with_linkdown=1 on device - nexthop has no carrier - gateway is not present or covered by any route in table already Also multipath routes addition is invalidated by kernel even if only one of added nexthops satisfies all above conditions. Reproducer: ip netns add t ip -n t link add va type veth peer name vb ip -n t link set va up ip -n t addr add fd00::1/64 dev va nodad ip netns exec t sysctl -w \ net.ipv6.conf.va.ignore_routes_with_linkdown=1 ip -n t -6 route add 2001:db8::/64 via fd00::2 dev va # added ip -n t -6 route add 2001:db8::/64 table 100 via fd00::2 dev va # RTNETLINK answers: No route to host ip -n t -6 route show table all ip netns del t Route should be added because: - RT6_LOOKUP_F_IGNORE_LINKSTATE in commit d5d32e4b7668 ("net: ipv6: Do not consider link state for nexthop validation") was added for this - the same route is valid in main table (when no specifying table id while adding route) - fib6_nh_init() initializes nexthops with no carrier - IPv4 already does this (fib_check_nh_v4_gw() ignores link state using the FIB_LOOKUP_IGNORE_LINKSTATE flag) Before commit b2c709cce682 ("ipv6: Convert gateway validation to use fib6_info") rt6_lookup() was used for checking if nexthop is valid, rt6_lookup called rt6_device_match() which does not check the link state. After change rt6_lookup() to fib6_lookup() find_match() under fib6_lookup() started to invalidate linkdown devices, because RT6_LOOKUP_F_IGNORE_LINKSTATE is not passed to it. Adding RT6_LOOKUP_F_IGNORE_LINKSTATE to flags for ip6_route_check_nh() solves the problem. RT6_LOOKUP_F_IGNORE_LINKSTATE is already used inside the first search ip6_nh_lookup_table() and fixes the bug in second search fib6_lookup(). Also RT6_LOOKUP_F_IGNORE_LINKSTATE isn't read inside fib6_select_path(). Fixes: b2c709cce682 ("ipv6: Convert gateway validation to use fib6_info") Signed-off-by: Yaroslav Dudkov <aroslavdudkov622@gmail.com> Reviewed-by: Hangbin Liu <liuhangbin@kylinos.cn> Reviewed-by: Ido Schimmel <idosch@nvidia.com> Link: https://patch.msgid.link/20261104195655.1406837-2-aroslavdudkov622@gmail.com Signed-off-by: Jakub Kicinski <kuba@kernel.org>
10 daysnet/mlx5: Bridge, fix bogus MDB offload errorsGal Pressman1-10/+11
MDB add operations are queued on the switchdev deferred queue (SWITCHDEV_F_DEFER), while vlan object deletions are handled synchronously. A 'bridge vlan del' can overtake an MDB add that is still queued, and the vlan is already gone by the time the driver is called. The two operations are independent in practice: in my test, the MDB add is triggered by assigning the VF an IPv6 address (hence joining a solicited-node multicast group), while another process deletes the vlan from its representor. Racing 'bridge mdb add' against concurrent 'bridge vlan del' could result in: [ 5390.967651] mlx5_core 0000:08:00.0: E-Switch: Failed to lookup bridge port vlan metadata (vport=1) [ 5390.969120] mlx5_core 0000:08:00.1: E-Switch: Failed to lookup bridge port vlan metadata to create MDB (MAC=33:33:ff:12:00:05,vid=2204,vport=1) [ 5390.971676] mlx5_core 0000:08:00.1 eth4: Failed to add Port Multicast Database entry (object id=2) with error: -EINVAL (-22). Failure in updating the port's Multicast Database could lead to multicast forwarding issues. The error cannot reach anyone that could do anything with it, switchdev returned success to the bridge as soon as the MDB object was queued, and the errno only flags the entry as offload failed. The end result is correct either way, if the MDB has been offloaded before the vlan was deleted, mlx5_esw_bridge_port_mdb_vlan_flush() would have removed it. The FDB path already treats this as a harmless race, mlx5_esw_bridge_port_vlan_lookup() reports it on 'info' logging level and skips the offload. mlxsw did the same in [1]. Skip the MDB offload, report on 'info' logging level and return -EOPNOTSUPP: switchdev_port_obj_add_deferred() does not log it, and br_switchdev_mdb_complete() skips the port group flag update. [1] Commit 17b334a876fe ("mlxsw: spectrum_switchdev: Don't warn about valid situations") Fixes: 70f0302b3f20 ("net/mlx5: Bridge, implement mdb offload") Signed-off-by: Gal Pressman <gal@nvidia.com> Signed-off-by: Jianbo Liu <jianbol@nvidia.com> Reviewed-by: Cosmin Ratiu <cratiu@nvidia.com> Signed-off-by: Tariq Toukan <tariqt@nvidia.com> Link: https://patch.msgid.link/20261104183715.771390-1-tariqt@nvidia.com Signed-off-by: Jakub Kicinski <kuba@kernel.org>
10 daysaf_unix: Remove gc_in_progress check in unix_peek_fpl().Kuniyuki Iwashima1-3/+0
unix_vertex_dead() and unix_peek_fpl() are synchronised with unix_peek_seq to prevent GC from purging a live socket's recvq. unix_peek_fpl() skips the synchronisation if gc_in_progress is false. However, on weakly ordered arch, GC might have already started working while the write to gc_in_progress is buffered. This does not occur on x86. This is an unlikely path that happens only when AF_UNIX fd is peeked so not worth complicating. Instead of adding memory barriers in unix_gc() and unix_peek_fpl(), let's simply remove the broken short-circuit. Fixes: e5b31d988a41 ("af_unix: Give up GC if MSG_PEEK intervened.") Reported-by: Qihang Tang <q.h.hack.winter@gmail.com> Signed-off-by: Kuniyuki Iwashima <kuniyu@google.com> Link: https://patch.msgid.link/20261104162858.991930-1-kuniyu@google.com Signed-off-by: Jakub Kicinski <kuba@kernel.org>
10 daysMAINTAINERS: remove and replace myself as sfc maintainerEdward Cree1-1/+2
I will be retiring this month, so it is time to hand over the baton after a decade maintaining the Solarflare drivers. Remove my M: line, and add Alex and Andy as the new maintainers. Signed-off-by: Edward Cree <ecree.xilinx@gmail.com> Reviewed-by: Andy Moreton <andy.moreton@amd.com> Reviewed-by: Alex Austin <alex.austin@amd.com> Link: https://patch.msgid.link/20261104013138.4103896-1-edward.cree@amd.com Signed-off-by: Jakub Kicinski <kuba@kernel.org>
10 daystcp: free saved_syn after an RCU grace periodYingjie Wang5-9/+10
tcp_reqsk_record_syn() allocates saved_syn separately from its request socket. bpf_sock_ops_get_syn() can load that pointer while processing a retransmitted SYN under RCU. There are two ownership transfers which can let another CPU reclaim the allocation while such a reader is still using it. First, tcp_move_syn() transfers req->saved_syn to a newly created child socket. The child can be closed and tcp_saved_syn_free() can reclaim the allocation before a reader of the old request finishes. Second, inet_reqsk_clone() shallow-copies request_sock during request migration. After reqsk_migrate_reset() clears the old request pointer, the migrated clone owns it. However, a reader which already loaded the pointer from the old request can still be using it when the clone is released. I found this through LLM-assisted concurrency fuzzing. Mark the request-socket saved_syn pointer as RCU protected and use RCU accessors for its reads and updates. Keep the full-socket pointer plain because all of its accesses hold the socket lock. Embed an rcu_head in struct saved_syn and use kfree_rcu() in both teardown paths. This lets a request-side reader which loaded the object before an ownership transfer finish. This follows commit e3f33b0a1d89 ("ipv4: free inet_opt and ireq_opt after an RCU grace period"), which fixed the same ownership-transfer pattern for IPv4 options. The issue was confirmed with KASAN on v7.3-16007-g36aad21d50d1 using temporary kernel instrumentation to widen the reader and request-migration window. KASAN reported a slab-use-after-free read in bpf_sock_ops_get_syn(), with the allocation freed by __reqsk_free() from reqsk_timer_handler(). The same explicit migration test completed without a report with deferred reclamation. A patched kernel without the delay instrumentation also completed a successful migration and seven saved-SYN reads without a KASAN report. Fixes: 0813a841566f ("bpf: tcp: Allow bpf prog to write and parse TCP header option") Fixes: c905dee62232 ("tcp: Migrate TCP_NEW_SYN_RECV requests at retransmitting SYN+ACKs.") Cc: stable@vger.kernel.org Signed-off-by: Yingjie Wang <x-professor@outlook.com> Reviewed-by: Kuniyuki Iwashima <kuniyu@google.com> Reviewed-by: Eric Dumazet <edumazet@kernel.org> Link: https://patch.msgid.link/38fa9f2cc476502e9b1c1fef09ebba1df5dd5901.1793795528.git.x-professor@outlook.com Signed-off-by: Jakub Kicinski <kuba@kernel.org>
10 daysaf_unix: Convert unsigned long to u64 for GC.Kuniyuki Iwashima1-14/+14
Lim Chanyoun reported that unix_vertex_max_scc_index could wrap around on 32-bit kernels, which confuses GC into purging a live socket receive queue. I apparently designed GC with u64 in mind to avoid wraparound. [0] Let's make it true on 32-bit kernels. Note that unix_vertex.{out_degree,index} are converted for consistency; they are bounded by the number of allocated objects and do not exceed UINT_MAX on 32-bit kernels. Fixes: 4090fa373f0e ("af_unix: Replace garbage collection algorithm.") Link: https://lore.kernel.org/netdev/20240228030508.31297-1-kuniyu@amazon.com/ #[0] Reported-by: Lim Chanyoun <onleaf322@gmail.com> Signed-off-by: Kuniyuki Iwashima <kuniyu@google.com> Link: https://patch.msgid.link/20261104082058.452188-1-kuniyu@google.com Signed-off-by: Jakub Kicinski <kuba@kernel.org>
10 daysnet: bridge: use one headroom snapshot for ND repliesJun Yang1-2/+4
br_nd_send() calls LL_RESERVED_SPACE(dev) once to size the reply skb and again to reserve its headroom. When a port requiring more headroom is added to the bridge, br_add_if() can increase dev->needed_headroom between the two calls. The reserved headroom can then exceed the space accounted for by alloc_skb(). Take one headroom snapshot and use it for both the allocation size and skb_reserve(). Fixes: ed842faeb2bd ("bridge: suppress nd pkts on BR_NEIGH_SUPPRESS ports") Cc: stable@kernel.org Reported-by: TencentOS Corvus AI <corvus@tencent.com> Signed-off-by: Jun Yang <junvyyang@tencent.com> Acked-by: Nikolay Aleksandrov <razor@blackwall.org> Reviewed-by: Ido Schimmel <idosch@nvidia.com> Link: https://patch.msgid.link/20261103075439.43644-1-juny24602@gmail.com Signed-off-by: Jakub Kicinski <kuba@kernel.org>
10 daysMerge patch series "net: gro: fix frag0 and remcsum handling"Jakub Kicinski5-5/+43
Eric Dumazet says: ==================== Two GRO fixes for paths using remote checksum offload (VXLAN, GUE) and for NAPI_GRO_CB(skb)->frag0 after a pull. Patch 1 skips skb_gro_remcsum_cleanup() once the skb was merged, as grc->offset can no longer be trusted, and no longer builds fraglist packets with an adjusted inner checksum. Patch 2 invalidates frag0 before a pull, which commit bd56a29c7a4e ("net: gro: change skb_gro_network_header()") stopped doing. ==================== Link: https://patch.msgid.link/20261104151042.1157782-1-edumazet@kernel.org Signed-off-by: Jakub Kicinski <kuba@kernel.org>
10 daysnet: gro: invalidate frag0 after a pullEric Dumazet5-4/+29
Since commit bd56a29c7a4e ("net: gro: change skb_gro_network_header()"), skb_gro_header_slow() no longer invalidates NAPI_GRO_CB(skb)->frag0 after pskb_may_pull(). skb_gro_may_pull() keeps comparing against the frag0_len value set in skb_gro_reset_offset(), assuming that after a slow pull, all later accesses are beyond frag0_len. This is not true: - udp4_gro_receive() and udp6_gro_receive() read the network header with skb_gro_network_header() after udp_gro_udphdr() pulled the UDP header. - vxlan_gro_receive() calls skb_gro_remcsum_cleanup() at a lower offset after the inner handlers pulled their headers. - skb_gro_remcsum_process() can pull beyond the inner Ethernet header before eth_gro_receive() reads it. - napi_frags_skb() calls __skb_pull(skb, ETH_HLEN) after a slow pull, so frag0 still points to the Ethernet header. If the pull consumed the first page fragment, __skb_pull_tail() released it. If the head had to grow, pskb_expand_head() freed the old one. These reads, and the 2-byte write in skb_gro_remcsum_cleanup(), then access memory the skb no longer holds a reference on. esp4_gro_receive(), esp6_gro_receive(), skb_gro_receive_list() and udp_gro_receive_segment() also pull directly and never invalidated frag0. Add skb_gro_frag0_invalidate(), which only clears frag0_len, and call it before each of these pulls. This is a single store in the slow path, and frag0 stays non NULL, so skb_gro_network_header() does not need a NULL test. frag0 must be invalidated even if the pull fails: __pskb_pull_tail() can return NULL after pskb_expand_head() freed the old head, for instance if a frag_list member has to be cloned or pulled. As frag0 is now invalidated before a pull that can fail, gro_try_pull_from_frag0() can see an skb whose linear part does not cover skb_gro_offset() while frag0 still points to the start of the packet, for instance after skb_gro_remcsum_cleanup() pulled a shorter length. Copying from frag0 would then corrupt the headers: only use frag0 while frag0_len is not zero, and use pskb_may_pull() otherwise. If this pull fails, for instance after a failed pskb_pull() in esp4_gro_receive(), do not hold the packet: later GRO lookups and gro_complete() handlers expect its headers in the linear part. This was found by Taesoo Kim and Cen Zhang, using LLM assisted code analysis, and confirmed with reproducers. Fixes: bd56a29c7a4e ("net: gro: change skb_gro_network_header()") Fixes: 9fd1ff5d2ac7 ("udp: Support UDP fraglist GRO/GSO.") Cc: stable@vger.kernel.org Reported-by: Taesoo Kim <tsgatesv@gmail.com> Reported-by: Cen Zhang <cenzhang@linux.microsoft.com> Signed-off-by: Eric Dumazet <edumazet@kernel.org> Link: https://patch.msgid.link/20261104151042.1157782-3-edumazet@kernel.org Signed-off-by: Jakub Kicinski <kuba@kernel.org>
10 daysnet: gro: do not undo remote checksum offload on merged packetsEric Dumazet2-1/+14
skb_gro_flush_final_remcsum() calls skb_gro_remcsum_cleanup() to undo the checksum adjustment done by skb_gro_remcsum_process() when the packet was not consumed by GRO. When the inner handler merged the packet (NAPI_GRO_CB(skb)->same_flow is set), grc->offset can no longer be trusted: - skb_gro_receive() either gives the frags or the head of the skb to the held packet, or uses __skb_pull(skb, offset) before adding the skb to the frag_list of the held packet. - skb_gro_receive_list() uses skb_pull(skb, skb_gro_offset(skb)). grc->offset is relative to the original skb->data, so the 2-byte read-modify-write done by skb_gro_remcsum_cleanup() can land in the payload of a packet which now belongs to the GRO packet. pskb_may_pull() can also be called on this frag_list member. With fraglist GRO, this can also be a use-after-free: pskb_may_pull(skb, skb_gro_offset(skb)) in skb_gro_receive_list() or udp_gro_receive_segment() releases the first page fragment if it only contains headers. NAPI_GRO_CB(skb)->frag0 and frag0_len are not updated, so skb_gro_remcsum_cleanup() takes the fast path and writes through frag0 into a page the skb no longer holds a reference on. The non merged case, where frag0 is used after this pull, is handled in the following patch. For skbs merged by skb_gro_receive(), the cleanup can be skipped: the skb is freed, or its headers are rebuilt from the head skb in skb_segment(). Fraglist members keep their own inner headers, as skb_segment_list() only copies the link-layer and tunnel headers from the head skb. Their checksum can not be right in all cases: a packet forwarded with its tunnel header needs the original value, while a VXLAN packet decapsulated locally needs the adjusted one, as vxlan_remcsum() only adjusts the head skb. Make skb_gro_receive_list() refuse packets with skb->remcsum_offload set, so that fraglist members never carry an adjusted checksum. This affects VXLAN (VXLAN_F_REMCSUM_NOPARTIAL) and GUE (FOU_F_REMCSUM_NOPARTIAL). This was found while fixing a report from Taesoo Kim and Cen Zhang, who used LLM assisted code analysis and provided reproducers. Fixes: 26c4f7da3e41 ("net: Fix remcsum in GRO path to not change packet") Cc: stable@vger.kernel.org Signed-off-by: Eric Dumazet <edumazet@kernel.org> Link: https://patch.msgid.link/20261104151042.1157782-2-edumazet@kernel.org Signed-off-by: Jakub Kicinski <kuba@kernel.org>
10 daysnet/mlx5e: Fix queue stats access to queues without statsBreno Leitao1-1/+4
I am seeing the following mlx5e crash in the Meta fleet: pc : mlx5e_get_queue_stats_rx+0x4c/0xc8 Call trace: mlx5e_get_queue_stats_rx+0x4c/0xc8 (P) netdev_stat_queue_sum+0x78/0x480 netdev_nl_qstats_get_dump_one+0xf0/0x268 netdev_nl_qstats_get_dumpit+0x7c/0x1f8 When dumping device-wide qstats, the core calls the per-queue callbacks for every queue below real_num_{rx,tx}_queues, regardless of whether the netdev is up. Some of those queues have no stats behind them: - RX stats live in priv->channel_stats[], which only has entries for channels that have been opened (stats_nch). real_num_rx_queues can be larger, for example after the channel count is raised while the netdev is down, or after opening the channels failed part way. - TX stats are looked up in priv->txq2sq_stats[], which is NULL for SQs that were never activated and for HTB queues while the channels are closed. In both cases the callback dereferences a NULL pointer. The dump needs no privileges, so any user can trigger it. Return early for RX queues at or above stats_nch and for TX queues without SQ stats. Fixes: 7b66ae536a78 ("net/mlx5e: Add per queue netdev-genl stats") Cc: stable@vger.kernel.org Signed-off-by: Breno Leitao <leitao@debian.org> Reviewed-by: Tariq Toukan <tariqt@nvidia.com> Link: https://patch.msgid.link/20261104-mlx5e-qstats-null-v1-1-a6a003245cec@debian.org Signed-off-by: Jakub Kicinski <kuba@kernel.org>
10 daysnet: raw: fix ICMP unreachable sent when receive queue is fullJiayuan Chen2-14/+16
It's found in a raw socket application. When the application doesn't read packets in time, the client receives ICMP Protocol Unreachable, which makes the client abort the session. The reason is that the server hits the sk_rcvbuf limit, and raw_v4_input() skips the socket before setting 'delivered', so it returns 0. Then ip_protocol_deliver_rcu() sees 'raw' is 0, thinks no one handles this protocol and calls icmp_send() to send ICMP Protocol Unreachable. IPv6 has the same issue, ip6_protocol_deliver_rcu() sends ICMPv6 Parameter Problem instead. Also, we'd better run icmp_filter() and ip_mc_sf_allow() (icmpv6_filter() for IPv6) before we check sk_rcvbuf, otherwise packets rejected by ICMP_FILTER/ICMPV6_FILTER or the multicast filter are counted in sk_drops. So move the check right before skb_clone(). Fixes: d721812aa875 ("ipv4: raw: check sk->sk_rcvbuf earlier") Fixes: 026763ece881 ("ipv6: raw: check sk->sk_rcvbuf earlier") Signed-off-by: Jiayuan Chen <jiayuan.chen@linux.dev> Link: https://patch.msgid.link/20261104115732.322151-1-jiayuan.chen@linux.dev Signed-off-by: Jakub Kicinski <kuba@kernel.org>
10 daysnet: usb: lan78xx: resume phylink on non-reset USB resumeStefano Munari1-9/+7
lan78xx_suspend() calls phylink_suspend(dev->phylink, false) on an open interface, which always stops phylink and halts the PHY. The matching phylink_resume() is only called from lan78xx_reset_resume(). When the USB device stays powered across system sleep (e.g. s2idle) and the USB core calls .resume instead, the link stays down until the interface is brought down and up by hand. The ifdown triggers: WARNING: drivers/net/phy/phy.c:1670 at phy_stop+0x44/0xc8 called from state HALTED Move phylink_resume() to the end of lan78xx_resume(), which both resume paths go through, and call it only if the resume succeeded and the interface was open, mirroring lan78xx_suspend(). As a side effect, lan78xx_reset_resume() no longer starts phylink on a closed interface. Tested on a Raspberry Pi 3B+ (LAN7515) with s2idle: the link now comes back up on its own after resume and ifdown no longer warns. Fixes: e110bc825897 ("net: usb: lan78xx: Convert to PHYLINK for improved PHY and MAC management") Signed-off-by: Stefano Munari <stefanomunari.sm@gmail.com> Tested-by: Oleksij Rempel <o.rempel@pengutronix.de> Link: https://patch.msgid.link/20261102235133.23011-1-stefanomunari.sm@gmail.com Signed-off-by: Jakub Kicinski <kuba@kernel.org>
10 daysMerge branch 'xsk-zc-mbuf-fixes'Jakub Kicinski7-23/+60
Maciej Fijalkowski says: ==================== xsk: ZC mbuf fixes Nagato Shiratana reported that duplicate fill ring addresses in aligned mode let a driver pass the same buffer to xsk_buff_add_frag() twice. This corrupts pool->xskb_list and can lead to a NULL pointer dereference in xp_free(). Patch 1 makes xsk_buff_add_frag() reject such buffers. Inspecting the rest of the zero-copy multi-buffer code found more issues: - i40e retries a freed frame, or stalls the queue on a duplicate, when xsk_buff_add_frag() fails (patch 2) - ice leaks the buffer when a frag is empty or cannot be added (patch 3) - ice and libeth free the frags of a frame still being received when a multi-buffer XDP_TX frame completes (patches 4-5) - handing out a duplicate of a frame's head clears its frags flag, so its frags stay on pool->xskb_list and end up in the next frame (patch 6) - ice and idpf leak a partially received frame on ring cleanup, and its frags end up in the next frame (patches 8-9) Patch 7 is Chenguang Zhao's fix for i40e building broken skbs from multi-buffer frames. It was posted earlier in an IWL pull request [0] and is included here unchanged. Patches 1 and 6 were tested with KUnit tests based on the reporter's reproducer, plus I verified to-be-upstreamed xsk.py test suite passes on ice driver (back-to-back setup based on netns) with this set applied. ==================== Link: https://patch.msgid.link/20261102124950.958345-1-maciej.fijalkowski@intel.com Signed-off-by: Jakub Kicinski <kuba@kernel.org>
10 daysidpf: free stashed XSk Rx frame when releasing the queueMaciej Fijalkowski1-0/+5
idpf_xskrq_poll() stashes a partially received multi-buffer frame in rxq->xsk, with its frags on pool->xskb_list. Nothing frees or clears rxq->xsk on queue release, as idpf_rx_desc_rel() only returns the page stash sharing its storage for non-XSk queues. On ifdown, the buffers are lost to user space and, as the pool outlives the queue, the stale frags are taken as frags of the next frame. If the pool is disabled on a running interface, the queue restarts in page mode with rxq->xdp.data still pointing to an xskb of the pool, which is freed later. The page path then takes it for a partial frame, writes frag info through it and returns it to a page pool. Free the stashed frame and clear the pointer when the XSk state of the queue is cleared, while the pool is still attached. Fixes: 9705d6552f58 ("idpf: implement Rx path for AF_XDP") Signed-off-by: Maciej Fijalkowski <maciej.fijalkowski@intel.com> Reviewed-by: Björn Töpel <bjorn@kernel.org> Link: https://patch.msgid.link/20261102124950.958345-10-maciej.fijalkowski@intel.com Signed-off-by: Jakub Kicinski <kuba@kernel.org>
10 daysice: xsk: free stashed Rx frame when cleaning the ringMaciej Fijalkowski1-0/+5
ice_clean_rx_irq_zc() stashes a partially received multi-buffer frame in rx_ring->xsk, with its frags on pool->xskb_list. next_to_clean is already past its buffers, so ice_xsk_clean_rx_ring(), which walks next_to_clean..next_to_use, misses the frame, and ice_vsi_cfg_rxq() later clears the pointer via ring->xdp.data. The buffers are lost to user space and, as the pool outlives the ring across ifdown/ifup or a reset, the stale frags are taken as frags of the next frame. Before commit 93f53db9f9dc ("ice: switch to Page Pool"), the frame was tracked by rx_ring->first_desc and leaked the same way. Free the stashed frame when cleaning the ring. Fixes: 1bbc04de607b ("ice: xsk: add RX multi-buffer support") Signed-off-by: Maciej Fijalkowski <maciej.fijalkowski@intel.com> Reviewed-by: Björn Töpel <bjorn@kernel.org> Link: https://patch.msgid.link/20261102124950.958345-9-maciej.fijalkowski@intel.com Signed-off-by: Jakub Kicinski <kuba@kernel.org>
10 daysi40e: xsk: fix multi-buffer XDP_PASS skb constructionChenguang Zhao1-8/+5
When AF_XDP ZC receives a multi-buffer frame and the XDP program returns XDP_PASS, i40e_construct_skb_zc() copies frags into a new skb. The copy used skb_frag_page() as the memcpy source (page metadata instead of packet data) and passed a virtual address to __skb_fill_page_desc_noacc(), which expects a struct page *. Use skb_frag_address() for the copy, attach frags with skb_add_rx_frag() so len/data_len/truesize are updated, and on dev_alloc_page() failure free the skb via the shared out path so xsk_buff_free() still runs and previously attached pages are released by kfree_skb. Fixes: 1c9ba9c14658 ("i40e: xsk: add RX multi-buffer support") Signed-off-by: Chenguang Zhao <zhaochenguang@kylinos.cn> Reviewed-by: Aleksandr Loktionov <aleksandr.loktionov@intel.com> Reviewed-by: Jason Xing <kerneljasonxing@gmail.com> Acked-by: Maciej Fijalkowski <maciej.fijalkowski@intel.com> Tested-by: Patryk Holda <patryk.holda@intel.com> Signed-off-by: Tony Nguyen <anthony.l.nguyen@intel.com> Reviewed-by: Björn Töpel <bjorn@kernel.org> Link: https://patch.msgid.link/20261102124950.958345-8-maciej.fijalkowski@intel.com Signed-off-by: Jakub Kicinski <kuba@kernel.org>
10 daysxsk: do not clear frags flag when acquiring a bufferMaciej Fijalkowski4-3/+6
xp_alloc() and xsk_buff_set_size() reset xdp_buff::flags of every buffer they hand out. In aligned mode, duplicate fill ring addresses map to the same xskb, so the head of a frame still being gathered can be handed out again and lose XDP_FLAGS_HAS_FRAGS. xsk_buff_add_frag() rejects the duplicate and the frame is dropped, but xsk_buff_free() leaves its frags on pool->xskb_list, where they are taken as frags of the next frame. Keep XDP_FLAGS_HAS_FRAGS on hand-out and clear it when the frags are released, in xsk_buff_free() and xsk_rcv_zc(). The driver XDP_TX paths, bpf_xdp_adjust_tail() and bpf_xdp_pull_data() already clear it, and pool->heads starts zeroed. Other flags are still reset on hand-out, as nothing clears them on release. Since xsk_rcv_zc() now clears the flag, i40e must count Rx bytes before running the XDP program, like ice and libeth. Fixes: f7f6aa8e2438 ("xsk: make xsk_buff_pool responsible for clearing xdp_buff::flags") Signed-off-by: Maciej Fijalkowski <maciej.fijalkowski@intel.com> Reviewed-by: Björn Töpel <bjorn@kernel.org> Link: https://patch.msgid.link/20261102124950.958345-7-maciej.fijalkowski@intel.com Signed-off-by: Jakub Kicinski <kuba@kernel.org>
10 dayslibeth: xsk: do not free in-flight frags on XDP_TX completionMaciej Fijalkowski1-2/+8
libeth_xsk_tx_queue_bulk() takes the frags of a multi-buffer frame off pool->xskb_list but leaves XDP_FLAGS_HAS_FRAGS set on the head. When the head completes, libeth_xsk_buff_free_slow() frees whatever is on the list at that point. The XDPSQ can be completed by a bulk flush while the frags of a frame are being queued, or by its cleanup timer while a partial Rx frame is stashed. Those frags are then freed while in use, and the frame being queued is sent truncated. Clear the flag on the head once all of its frags are queued. Fixes: b3ad8450b4dc ("libeth: xsk: add XSk XDP_TX sending helpers") Signed-off-by: Maciej Fijalkowski <maciej.fijalkowski@intel.com> Reviewed-by: Björn Töpel <bjorn@kernel.org> Link: https://patch.msgid.link/20261102124950.958345-6-maciej.fijalkowski@intel.com Signed-off-by: Jakub Kicinski <kuba@kernel.org>
10 daysice: xsk: do not free in-flight frags on XDP_TX completionMaciej Fijalkowski1-1/+8
ice_xmit_xdp_tx_zc() takes the frags of a multi-buffer frame off pool->xskb_list but leaves XDP_FLAGS_HAS_FRAGS set on the head. When the head completes, xsk_buff_free() frees whatever is on the list at that point, which are the frags of a frame still being received. If ice_xmit_xdp_tx_zc() completes such a head while cleaning the ring before sending another frame, xsk_buff_get_frag() returns NULL and xsk_buff_xdp_get_dma() dereferences it. Clear the flag on the head once its frags are on the ring. As xdp_get_buff_len() then covers only the head, count Rx bytes before running the XDP program, like libeth does. Fixes: eeb2b5381038 ("ice: xsk: Tx multi-buffer support") Signed-off-by: Maciej Fijalkowski <maciej.fijalkowski@intel.com> Reviewed-by: Björn Töpel <bjorn@kernel.org> Link: https://patch.msgid.link/20261102124950.958345-5-maciej.fijalkowski@intel.com Signed-off-by: Jakub Kicinski <kuba@kernel.org>
10 daysice: xsk: fix leaking Rx buffers in multi-buffer pathMaciej Fijalkowski1-1/+4
ice_clean_rx_irq_zc() consumes a descriptor without freeing its buffer when a frag has zero length or when xsk_buff_add_frag() fails, which happens if the frags array is full or the fill ring has duplicates. Such buffers are lost to user space until the socket is closed. Free the buffer in both cases. xp_free() skips a duplicate already freed with the frame. Fixes: 1bbc04de607b ("ice: xsk: add RX multi-buffer support") Fixes: 93f53db9f9dc ("ice: switch to Page Pool") Signed-off-by: Maciej Fijalkowski <maciej.fijalkowski@intel.com> Reviewed-by: Björn Töpel <bjorn@kernel.org> Link: https://patch.msgid.link/20261102124950.958345-4-maciej.fijalkowski@intel.com Signed-off-by: Jakub Kicinski <kuba@kernel.org>
10 daysi40e: xsk: fix xsk_buff_add_frag() error handling in RxMaciej Fijalkowski1-6/+14
When xsk_buff_add_frag() fails, i40e_clean_rx_irq_zc() frees the frame but stays on the current descriptor, so the next poll restarts from the freed head. If the frags array was full, the retry passes on a frame missing the freed frags, with its head already on the free list. If the buffer is a duplicate, every poll fails the same way and the queue stalls. Free the current buffer along with the frame and move on to the next descriptor, as ice does. The rest of the dropped frame is received as a new frame. xp_free() skips a duplicate already freed with the frame. Fixes: 1c9ba9c14658 ("i40e: xsk: add RX multi-buffer support") Signed-off-by: Maciej Fijalkowski <maciej.fijalkowski@intel.com> Reviewed-by: Björn Töpel <bjorn@kernel.org> Link: https://patch.msgid.link/20261102124950.958345-3-maciej.fijalkowski@intel.com Signed-off-by: Jakub Kicinski <kuba@kernel.org>
10 daysxsk: fix list corruption in xsk_buff_add_frag()Maciej Fijalkowski1-2/+5
In aligned mode, a fill ring address maps straight to its pool->heads[] entry. If user space posts the same address twice, a driver can pass xsk_buff_add_frag() a buffer that is the head of the frame or is already on pool->xskb_list or pool->free_list. Re-adding a linked node corrupts the list. With buffers A, B, C, B, xsk_rcv_zc() emits two descriptors instead of four and leaves the list head pointing at a self-linked B. When the Rx ring later has no room for a frame, the xsk_buff_free() cleanup follows B into pool->free_list and passes the list head to xp_free(): BUG: kernel NULL pointer dereference, address: 00000000000000c0 RIP: 0010:xp_free+0x1a/0x50 Call Trace: xsk_rcv_zc+0xca/0x200 The head is not on any list and needs a separate check. Adding it as its own frag lets bpf_xdp_adjust_tail() free the in-use head and wrap sinfo->nr_frags to 255. Reject such buffers before adding them to the frags array, as commit e37b2abca804 ("xsk: fix NULL pointer dereference in __xsk_rcv()") does in the copy path. Callers already drop the frame on failure. Unaligned mode is not affected, as each fill ring entry gets its own xskb from pool->free_heads[]. Reproduced with a KUnit test feeding synthetic buffers to xsk_rcv_zc(), by Nagato Shiratana. Fixes: 24ea50127ecf ("xsk: support mbuf on ZC RX") Reported-by: Nagato Shiratana <zuomao338@gmail.com> Signed-off-by: Maciej Fijalkowski <maciej.fijalkowski@intel.com> Reviewed-by: Björn Töpel <bjorn@kernel.org> Link: https://patch.msgid.link/20261102124950.958345-2-maciej.fijalkowski@intel.com Signed-off-by: Jakub Kicinski <kuba@kernel.org>
10 daysnet: skbuff: preserve fclone lifetime when freeing stolen headsKyle Zeng1-1/+5
skb_morph() can give an skb from skbuff_fclone_cache a page-fragment head without changing its fclone tag. IPv4 reassembly can produce such an skb, which can subsequently reach the GRO stolen-head path. napi_skb_free_stolen_head() puts the shell into the ordinary NAPI skb cache without dropping its fclone_ref. If the embedded companion is still live, KASAN poisons it along with the original, and later cache reuse or eviction can overwrite or free the allocation underneath it. A mirrored batman-adv DAT packet retained in a plug qdisc reproduces a KASAN use-after-free in plug_dequeue(). Use kfree_skbmem() for fclones in napi_skb_free_stolen_head(), retaining NAPI caching for ordinary skb heads. Also use kfree_skbmem() in kfree_skb_partial(), whose stolen-head branch has the same assumption about the allocation cache. This releases the shell according to its allocation kind and preserves any live companion without freeing the data that has been transferred to the receiving skb. Fixes: f450d539c05a ("skbuff: introduce {,__}napi_build_skb() which reuses NAPI cache heads") Signed-off-by: Kyle Zeng <kylebot@openai.com> Link: https://patch.msgid.link/20261030042329.74461-1-kylebot@openai.com Signed-off-by: Jakub Kicinski <kuba@kernel.org>
10 daysipv4: keep XFRM headers out of corked skb lengthsKyle Zeng1-4/+4
__ip_append_data() allocates space for dst.header_len in the first skb, but includes that space in skb->len until __ip_make_skb() pulls it. Fragment accounting uses an MTU that already excludes the XFRM headers. As a result, the next skb can have a fraggap larger than its capped datalen, and skb_copy_and_csum_bits() can overwrite its shared info. For example, five AH tunnel states can reserve 500 bytes while leaving an effective MTU of 348. With 40 bytes of IPv4 options, the second skb has room for 288 bytes of fragment data but receives a 500-byte gap copy. The overwritten shared info is subsequently consumed by the skb release paths. Reserve the XFRM headers together with the link-layer headroom instead. This keeps skb->len, the gap-copy offsets and the trim lengths relative to the IPv4 packet throughout corking. The network and transport header addresses and the headroom available to XFRM at output are unchanged. Both paged and linear allocations, including subsequent corked appends, use the corrected accounting. Fixes: 353e5c9abd90 ("ipv4: Fix IPsec slowpath fragmentation problem") Cc: stable@vger.kernel.org Signed-off-by: Kyle Zeng <kylebot@openai.com> Link: https://patch.msgid.link/20261030042229.74068-1-kylebot@openai.com Signed-off-by: Jakub Kicinski <kuba@kernel.org>