From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=100.103.45.18 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796283218; b=WV15JWXfD9AiKhidmW8TZY26qK53rELDnlu5Pypbh1oeaibnvuUkklKjJHYrQff9nL4Q fcki9COidHM2U3d3jDtWjLEtLggs86xORy43F7IKP4crh+jrozvLT9lbPQD3VMHlDFD6D pGcJXYkTr02q1vC1rr9sufDZCVjwuH2Lve3VknBy512caZw+Cn4TAy0zTvCUWwXvzhx7K UQZlIjZitB9lP8m7PQkiEa4DYijgK3vR2BReQ3l9aS5osVbknNr8TH3gZt/23qGapHVO5 mgpXB8X7XB++AE/2lWxnosxI+Q2qj/Vg1YUra1joBs/maBYTlnAicByzno9JoaMA1fQ== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796283218; h=Received:DKIM-Signature:Message-ID:From:Subject:Reply-To:To:Cc: In-Reply-To:References:Content-Type:Content-Transfer-Encoding:Date; bh=zejWPTgdBrpPJr4O3ih6y16ThEWl1ZcIa3GREfX+Cyw=; b=3RtANHKh9iyWj+2+ZimuNAPgKKdyUbPCFUXcpGBHwth1Yc4VmPufPcWrTa6mQN+m/ZWx NqWVFtY6ij5IO9X3w7x+3cq9a2cde9WM9K3adydxX87JDmnUGVAZawWytXdcykn3JQDya W0WWIqilvGSf/PCn8XhrN7dXvxJyrZnWFJRljlR27U/giXV8/L8pYvxgMJ2iJcX6ZLEC9 u4dtHKmlXUC2hb8kY6zisaR5tzCRU+9EdY51jmILvJeGdjglI8hG//Qktmxw/jI2ycL8y yvmvD+TML9b6H2wG2PEQ2/XECNt/zSpUvrpJmLNvJfvrikrPFRlUhfz0tVFnXynZh4Q== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=OLRjcw3U; arc=none smtp.remote-ip=100.103.45.18 Received: from smtp.kernel.org (quasi.space.kernel.org [100.103.45.18]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (prime256v1)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 9F08C606A322 for ; Thu, 3 Dec 2026 07:33:38 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=OLRjcw3U Received: by smtp.kernel.org (Postfix) with ESMTPSA id 399771F00893; Thu, 3 Dec 2026 07:33:38 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1796283218; bh=zejWPTgdBrpPJr4O3ih6y16ThEWl1ZcIa3GREfX+Cyw=; h=From:Subject:Reply-To:To:Cc:In-Reply-To:References:Date; b=OLRjcw3UH5QEdAlmYYRmNacZjrwM36aluCQAY0RiSraBQpFX0u7T1ruKJsSjj62YJ ho0IVDO7trVaXeGQfAvGvEABJi29XcLa4dnNj1bBQt4DFV8Drc5F0j65J5++7wBFY6 gzadx1R6gkL5jpgJiMokW89UOE9pbkTxly42WioM9Pv3KrVR2SAhMrgomAV2eY9+hM n+8zOWjK50H3UsAuDPtJu2jbxhCoshR6FTY/cYWBbLOzyZniGAG2vsD9Jb9Ow7u/9u Gn+mJnsqJz1reNx5AhnguJNdWFdqI1YZv1qLluFPiBWts+FGNycSaJOALOEdNQQ0dZ 3sWDRL8YIM3Zw== Message-ID: From: sashiko-bot@kernel.org Subject: Re: [PATCH v6 10/17] wifi: cc33xx: Add rx.c, rx.h Reply-To: sashiko-reviews@lists.linux.dev To: "Ramesh Ramalingam" Cc: devicetree@vger.kernel.org, robh@kernel.org, conor+dt@kernel.org In-Reply-To: <20261203070906.1294171-11-r-ramalingam@ti.com> References: <20261203070906.1294171-1-r-ramalingam@ti.com> <20261203070906.1294171-11-r-ramalingam@ti.com> Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable Date: Thu, 03 Dec 2026 07:33:37 +0000 X-Mailing-List: devicetree@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list Thank you for your contribution! Sashiko AI review found 11 potential issues to consider: - [High] wifi: cc33xx: concurrent cc33xx_flush_deferred_work() races with netstack_work - [High] wifi: cc33xx: desc->length underflow causes infinite loop or OOB read in rx.c - [High] wifi: cc33xx: unchecked nab_rx_header->len causes OOB read in cc33xx_rx() - [High] wifi: cc33xx: teardown ordering UAF in cc33xx_remove() and cc33xx_turn_off() - [Medium] wifi: cc33xx: OOB read on split descriptor in cc33xx_rx_handle_packet() - [Medium] wifi: cc33xx: missing skb->len checks in cc33xx_rx_get_packet_data() - [Medium] wifi: cc33xx: partial_rx.skb leaked on firmware recovery and driver removal - [Medium] wifi: cc33xx: cc33xx_rx_status() passes unsupported rate_idx to mac80211 - [Low] wifi: cc33xx: unratelimited dev_warn()/dev_err() in RX path under cc->mutex - [Low] wifi: cc33xx: missing le16_to_cpu() on __le16 fields in rx.c debug logs - [Low] wifi: cc33xx: double subtraction of pad_len in cc33xx_rx_get_packet_data() -- commit 0a5e47272fafbb9009679e3984d494d3dc15af9f Author: Michael Nemanov wifi: cc33xx: Add rx.c, rx.h This commit adds RX buffer parsing, descriptor handling, and RX filter helpers for the TI CC33xx wireless driver. > diff --git a/drivers/net/wireless/ti/cc33xx/rx.c b/drivers/net/wireless/t= i/cc33xx/rx.c > new file mode 100644 > index 0000000000000..81e16749ed0be > --- /dev/null > +++ b/drivers/net/wireless/ti/cc33xx/rx.c > @@ -0,0 +1,385 @@ [ ... ] > + rate_idx =3D cc33xx_rate_to_idx(desc->rate, status->band); > + if (rate_idx =3D=3D CONF_HW_RXTX_RATE_UNSUPPORTED) > + dev_err(cc->dev, "Invalid RX rate from HW: %d\n", desc->rate); > + > + status->rate_idx =3D rate_idx; [Severity: Medium] Can passing CONF_HW_RXTX_RATE_UNSUPPORTED (0xff) in status->rate_idx trigger warnings in mac80211? When firmware reports an unmapped rate (such as desc->rate =3D=3D 0 or a ra= te above CONF_HW_RATE_INDEX_MAX), cc33xx_rx_status() logs an error but still passes 0xff to ieee80211_rx_ni(). ieee80211_rx_list() treats an out-of-ran= ge rate_idx as a driver bug, emitting WARN/WARN_ON/WARN_ONCE splats before dropping the frame. Should this clamp rate_idx to a valid fallback (such as 0) or drop the frame instead? [ ... ] > + if (unlikely(desc_err_code & CC33XX_RX_DESC_MIC_FAIL)) { > + status->flag |=3D RX_FLAG_MMIC_ERROR; > + dev_warn(cc->dev, "Michael MIC error. Desc: 0x%x\n", > + desc_err_code); > + } [Severity: Low] Should this dev_warn(), along with the dev_err() for invalid RX rates above and the dev_warn() for CC33XX_RX_DESC_DECRYPT_FAIL in cc33xx_rx_get_packet_descriptor(), be ratelimited? All three run per received packet while cc->mutex is held in cc33xx_irq_work(). A nearby peer sending forged frames that fail decryption or Michael MIC verification can flood the kernel log and stall operations waiting on cc->mutex. [ ... ] > + /* Descriptor was fully copied */ > + pkt_data_len =3D cc->partial_rx.original_bytes; > + pkt_data_len -=3D sizeof(struct cc33xx_rx_descriptor); > + > + if (unlikely(cc->partial_rx.desc.status & CC33XX_RX_DESC_DECRYPT_FAIL))= { > + dev_warn(cc->dev, "corrupted packet in RX: status: 0x%x len: %d\n", > + cc->partial_rx.desc.status & CC33XX_RX_DESC_STATUS_MASK, > + pkt_data_len); > + > + /* If frame can be fully dropped */ > + if (pkt_data_len <=3D *raw_buffer_len) { > + *raw_buffer_len -=3D pkt_data_len; > + cc->partial_rx.status =3D CURR_RX_START; > + } else { > + cc->partial_rx.handled_bytes +=3D *raw_buffer_len; > + cc->partial_rx.status =3D CURR_RX_DROP; > + *raw_buffer_len =3D 0; > + } > + goto out; > + } [Severity: High] Can a malformed descriptor with desc->length < sizeof(struct cc33xx_rx_descriptor) cause an infinite loop or an out-of-bounds read? Without a lower-bound check on original_bytes, subtracting 16 underflows u16 pkt_data_len to 65520..65535. On the normal path this requests a ~64 KB allocation under cc->mutex and absorbs subsequent RX traffic. On the drop path (decrypt failure or __dev_alloc_skb() failure), handled_bytes becomes greater than original_bytes, status becomes CURR_RX_DROP, and *raw_buffer_len is set to 0. cc33xx_rx_handle_packet() then immediately calls cc33xx_rx_drop_packet_data(), where signed promotion makes (original_bytes - handled_bytes) negative: drivers/net/wireless/ti/cc33xx/rx.c:cc33xx_rx_drop_packet_data() { if (*raw_buffer_len >=3D (cc->partial_rx.original_bytes - cc->partial_rx.handled_bytes)) { *raw_buffer_len -=3D cc->partial_rx.original_bytes - cc->partial_rx.handled_bytes; cc->partial_rx.handled_bytes =3D 0; cc->partial_rx.status =3D CURR_RX_START; } } That increases *raw_buffer_len instead of decreasing it. Back in cc33xx_rx(), consumed_bytes becomes 0 (looping forever while holding cc->mutex) or underflows u16 if the descriptor was split across transfers, advancing pkt_offset ~65 KB past cc->aggr_buf. > + skb =3D __dev_alloc_skb(pkt_data_len, GFP_KERNEL); [ ... ] > + cc->partial_rx.skb =3D skb; > + cc->partial_rx.status =3D CURR_RX_DATA; [Severity: Medium] Does cc->partial_rx.skb leak if firmware recovery or device removal happens while a split RX frame is in CURR_RX_DATA? cc->partial_rx.skb is never cleared to NULL after being queued to deferred_rx_queue, and neither cc33xx_turn_off() nor cc33xx_free_hw() frees an in-progress partial_rx.skb. Adding an RX reset helper that frees and clears partial_rx.skb during teardown and recovery would prevent the leak. [ ... ] > + rx_align =3D cc->partial_rx.desc.header_alignment; > + if (rx_align =3D=3D CC33XX_RX_BUF_PADDED) > + skb_pull(cc->partial_rx.skb, RX_BUF_ALIGN); > + > + extra_bytes =3D cc->partial_rx.desc.pad_len; > + if (extra_bytes !=3D 0) > + skb_trim(cc->partial_rx.skb, > + cc->partial_rx.skb->len - extra_bytes); > + > + hdr =3D (struct ieee80211_hdr *)cc->partial_rx.skb->data; > + > + if (ieee80211_is_beacon(hdr->frame_control)) > + beacon =3D 1; > + if (ieee80211_is_probe_resp(hdr->frame_control)) > + is_probe_resp =3D 1; > + > + cc33xx_rx_status(cc, &cc->partial_rx.desc, > + IEEE80211_SKB_RXCB(cc->partial_rx.skb), > + beacon, is_probe_resp); > + > + seq_num =3D le16_get_bits(hdr->seq_ctrl, IEEE80211_SCTL_SEQ); [Severity: Medium] Can this read past skb->tail or underflow skb_trim() on short or malformed frames? skb_pull() and skb_trim() are called without checking that skb->len is at least RX_BUF_ALIGN or extra_bytes; if extra_bytes > skb->len, the unsigned subtraction wraps near UINT_MAX so skb_trim() leaves the frame untrimmed. In addition, hdr->frame_control and hdr->seq_ctrl (offset 22..23) are read unconditionally without checking skb->len. Any frame shorter than 24 bytes, such as an 802.11 control frame, reads past skb->tail into uninitialized buffer memory or skb_shared_info. > + cc33xx_debug(cc->dev, DEBUG_RX, "rx skb 0x%p: %d B %s seq %d link id %d= \n", > + cc->partial_rx.skb, > + cc->partial_rx.skb->len - cc->partial_rx.desc.pad_len, > + beacon ? "beacon" : "", seq_num, cc->partial_rx.desc.hlid); [Severity: Low] Does this debug log subtract cc->partial_rx.desc.pad_len twice? skb_trim() already removed extra_bytes from cc->partial_rx.skb->len just above. > + cc33xx_debug(cc->dev, DEBUG_RX, "rx frame. frame type 0x%x, frame lengt= h 0x%x, frame address %p\n", > + hdr->frame_control, cc->partial_rx.skb->len, > + cc->partial_rx.skb->data); [Severity: Low] Should hdr->frame_control here and desc->length in cc33xx_rx_handle_packet() be wrapped in le16_to_cpu()? Both are __le16 fields passed directly to 0x%= x, which causes sparse warnings and byte-swapped output on big-endian hosts. > + /* Adding frame to queue */ > + skb_queue_tail(&cc->deferred_rx_queue, cc->partial_rx.skb); > + cc->rx_counter++; > + cc->partial_rx.status =3D CURR_RX_START; > + > + /* Make sure the deferred queues don't get too long */ > + defer_count =3D skb_queue_len(&cc->deferred_tx_queue); > + defer_count +=3D skb_queue_len(&cc->deferred_rx_queue); > + if (defer_count >=3D CC33XX_RX_QUEUE_MAX_LEN) > + cc33xx_flush_deferred_work(cc); > + else > + queue_work(cc->freezable_netstack_wq, &cc->netstack_work); [Severity: High] Can calling cc33xx_flush_deferred_work() directly here race with cc33xx_netstack_work() and violate mac80211's RX serialization contract? CPU0 (freezable_wq) CPU1 (freezable_netstack_wq) cc33xx_irq_work() cc33xx_netstack_work() guard(mutex)(&cc->mutex) cc33xx_flush_deferred_work() cc33xx_rx() ieee80211_rx_ni() cc33xx_rx_get_packet_data() if (defer_count >=3D 256) cc33xx_flush_deferred_work() ieee80211_rx_ni() <-- concurrent mac80211 RX Under heavy traffic, both workers dequeue from deferred_rx_queue and deferred_tx_queue at the same time and call ieee80211_rx_ni() and ieee80211_tx_status_ni() concurrently for the same ieee80211_hw. mac80211 forbids concurrent calls to these functions; doing so races on unlocked fragment reassembly state in ieee80211_reassemble_add() (risking SKB list corruption or out-of-bounds cache indexing) and CCMP PN replay tracking in ieee80211_crypto_ccmp_decrypt(). Running the flush synchronously here also holds cc->mutex across network-stack delivery, stalling hardware I/O and mac80211 control ops. [Severity: High] Can this queue_work() path and cc33xx_turn_off() trigger a use-after-free on cc->hw during device removal? CPU0 CPU1 cc33xx_remove() cc33xx_unregister_hw() cc33xx_turn_off() cc33xx_flush_deferred_work() ieee80211_rx_ni() <-- hw already unregistered cancel_work_sync(&netstack_work) cc33xx_irq_work() cc33xx_rx_get_packet_data() queue_work(..., &netstack_work) cancel_work_sync(&irq_deferred_work) cc33xx_free_hw() destroy_workqueue(freezable_netstack_wq) cc33xx_netstack_work() ieee80211_rx_ni() <-- use-after-free In main.c, cc33xx_remove() calls cc33xx_unregister_hw() before cc33xx_turn_off(), so cc33xx_flush_deferred_work() feeds frames into an already-unregistered ieee80211_hw. Inside cc33xx_turn_off(), cancel_work_sync(&cc->netstack_work) also runs before cancel_work_sync(&cc->irq_deferred_work), allowing an in-flight cc33xx_irq_work() to re-queue netstack_work after it was cancelled. Stoppi= ng IRQs and cancelling irq_deferred_work before netstack_work, and shutting do= wn RX before ieee80211_unregister_hw(), would avoid both races. [ ... ] > + if (cc->partial_rx.status =3D=3D CURR_RX_START) { > + WARN_ON(*raw_buffer_len < 2); > + desc =3D (struct cc33xx_rx_descriptor *)raw_buffer_ptr; > + cc->partial_rx.original_bytes =3D le16_to_cpu(desc->length); > + cc->partial_rx.handled_bytes =3D 0; > + cc->partial_rx.status =3D CURR_RX_DESC; > + > + cc33xx_debug(cc->dev, DEBUG_RX, "rx frame. desc length 0x%x, alignment= 0x%x, padding 0x%x\n", > + desc->length, desc->header_alignment, desc->pad_len); > + } [Severity: Medium] Can a split RX descriptor cause an out-of-bounds read and corrupt cc->partial_rx.original_bytes here? WARN_ON(*raw_buffer_len < 2) does not stop execution. If a transfer bounda= ry leaves 1 byte, desc->length reads 1 byte past the valid RX buffer into partial_rx.original_bytes, and cc33xx_rx_get_packet_descriptor() never reloads original_bytes from cc->partial_rx.desc.length after reassembly completes, permanently desynchronizing the RX stream. Even for larger split descriptors (*raw_buffer_len < 16), the debug print reads desc->header_alignment and desc->pad_len (up to offset 14) past the valid buffer when DEBUG_RX is enabled. Deferring both the length read and the debug print until cc33xx_rx_get_packet_descriptor() finishes copying all 16 bytes would avoid reading incomplete descriptors. [ ... ] > +int cc33xx_rx(struct cc33xx *cc, u8 *rx_buf_ptr, u16 rx_buf_len) > +{ > + u16 local_rx_buffer_len =3D rx_buf_len; > + u16 pkt_offset =3D 0; > + u16 consumed_bytes; > + u16 prev_rx_buf_len; > + > + /* Split data into separate packets */ > + while (local_rx_buffer_len > 0) { [Severity: High] Can cc33xx_rx() read tens of kilobytes past cc->aggr_buf if nab_rx_header->len is smaller than 8 or larger than the read transfer? cc33xx_rx() trusts rx_buf_len directly, while its caller in main.c computes it without bounds checking: drivers/net/wireless/ti/cc33xx/main.c:cc33xx_irq_work() { ... nab_rx_header =3D (struct nab_rx_header *)cc->aggr_buf; rx_buf_len =3D le16_to_cpu(nab_rx_header->len) - 8; if (rx_buf_len !=3D 0) { rx_buf_ptr =3D (u8 *)cc->aggr_buf + sizeof(struct nab_rx_header); cc33xx_rx(cc, rx_buf_ptr, rx_buf_len); ... } If a bus glitch or hung firmware returns nab_rx_header->len < 8 (for example 0), u16 rx_buf_len underflows to 65528..65535, bypassing the rx_buf_len =3D= =3D 0 recovery path and causing cc33xx_rx() to parse well past the 32 KB cc->aggr_buf allocation. The caller should validate nab_rx_header->len >= =3D 8 and bound rx_buf_len against the actual read length and cc->aggr_buf_size. --=20 Sashiko AI review =C2=B7 https://sashiko.dev/#/patchset/20261203070906.1294= 171-1-r-ramalingam@ti.com?part=3D10