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=1796284364; b=NTouvJUNCL/yCLCXnyYpvuw9fc/lUpeSnieyf2ccXPtUvrSbrdZETk5+EckXDG4y5fHD Q0y39PH02CnGUE0OS06pUBxSbjmjf8Js81cljPdS8Pu8gpU2fzpB7XPEB8o8TvYfCuBm/ 7iR/w1qliMiJKiRagrVQlQ3DQyMG8ZtD9zcKE5pyR+TzeSNJ2euOQse/S9Mt/JqdC1/wp 9RlvOHUGRvDgKw8rEudSw+B7rVSrPBvGNbyqAhBR6zV1XehZkPnjP5dopAhIBpS+sd0sw Ew+yBqI4nZazmJc9DTLW8o+f1HaSJl2xejHHPYhfrwrfiI0R3A5Zy34n1juch1hsuaw== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796284364; h=Received:DKIM-Signature:Message-ID:From:Subject:Reply-To:To:Cc: In-Reply-To:References:Content-Type:Content-Transfer-Encoding:Date; bh=JVapcpstRfZOKjTrx/XkIQMSRGPVDFb1PINS9wC7+Ac=; b=u0ymvvbd+Me8pL1ZoaZllafEI3eKE/3aMVpOtMLtL9YCgErflQJva/raDM18hWhjH5H5 YJb8xEavaMxURSwowwncg4t/AYnmRhaRf9raqE9BoZOo0ACnWMfwTbLdq4xX1Jik2PRIJ Z2hbUgYBgqJtCGXApVPk1bl7wRt/hjLE5JLzmjgtq4MXnb/TloqDgHBsTYfd+yZr7E/Kh BxSv0aTl09uD6zV/YBufbgC1/VvujjH2q6SyxB8UZ4u/arsCRQcCU7jI0699sPJgs1UkR T2hbaXijloEcEDr5cSc3fXKcCVyhWy4BVk9Epdn3sjAOtYAxkNMwrRnrhUaUG0SNdWw== 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=VUvIDzgl; 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 B80B0606A330 for ; Thu, 3 Dec 2026 07:52:44 +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=VUvIDzgl Received: by smtp.kernel.org (Postfix) with ESMTPSA id 2F9F61F000C1; Thu, 3 Dec 2026 07:52:44 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1796284364; bh=JVapcpstRfZOKjTrx/XkIQMSRGPVDFb1PINS9wC7+Ac=; h=From:Subject:Reply-To:To:Cc:In-Reply-To:References:Date; b=VUvIDzgl2csmVRdJ/3oo7HAXU03qKWS5aangL59DQLHL4Nw/++zez/l7kIFm6jU7D k0lCSGk4O/1jsiA/qTOIaNIJtyXYxgi/sH9MmYXvQU/w+5DOiINPUFGbYWIiq0R8ln JLX5pDv5wgXd7qNDJ2b5Np+0VxRviDfdLY4FSS3Ocn3vnR+saix333BfF3G74Dc78W WE97ElNKxy79tFbcpGcH2ZH4tVYOS+6c6sijJWI7vzbD2VU1fTxYfaXDt7yO8u40At zuteQ30F2gZVf+AuIjgArsZuzXymH4JL/pnVUMKYsXdHF4BO2tXpsVDfkdiyFKwVDy UsHOoNVGJ7Fnw== Message-ID: From: sashiko-bot@kernel.org Subject: Re: [PATCH v6 13/17] wifi: cc33xx: Add scan.c, scan.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-14-r-ramalingam@ti.com> References: <20261203070906.1294171-1-r-ramalingam@ti.com> <20261203070906.1294171-14-r-ramalingam@ti.com> Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable Date: Thu, 03 Dec 2026 07:52:43 +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 13 potential issues to consider: - [High] wifi: cc33xx: heap buffer overflow in cc33xx_cmd_build_probe_req() - [High] wifi: cc33xx: AB-BA deadlock in cc33xx_scan_completed() via wiphy_lock() - [Medium] wifi: cc33xx: host-endian fields in scheduled scan plan commands - [Medium] wifi: cc33xx: info.aborted left false on timeout in cc33xx_scan_complete_work() - [Medium] wifi: cc33xx: __cc33xx_op_remove_interface() omits scan_complete_work cancel - [Medium] wifi: cc33xx: CC33XX_SCAN_STATE_DONE never set in cc33xx_scan_completed() - [Medium] wifi: cc33xx: unconditional 10 ms sleep under wiphy_lock on every scan - [Medium] wifi: cc33xx: unconditional SSID filtering in cc33xx_sched_scan_start() - [Medium] wifi: cc33xx: ignore return value of cc33xx_set_scan_chan_params() - [Medium] wifi: cc33xx: race between scan timeout timer and cc33xx_scan_completed() - [Low] wifi: cc33xx: __free(kfree) pointers split from allocation in scan.c - [Low] wifi: cc33xx: DFS dwell time discarded in cc33xx_adjust_channels() - [Low] wifi: cc33xx: cc33xx_sched_scan_start() checks role_id after sending FW cmd -- commit 0ac5043da0c566dad2178179ebf5d815a65e98df Author: Michael Nemanov wifi: cc33xx: Add scan.c, scan.h This commit adds one-shot and scheduled hardware scan support for the cc33xx wireless driver, including channel packing, probe request IE configuration, scan start/stop commands, and completion handling. > diff --git a/drivers/net/wireless/ti/cc33xx/scan.c b/drivers/net/wireless= /ti/cc33xx/scan.c > new file mode 100644 > index 0000000000000..a109ea034396c > --- /dev/null > +++ b/drivers/net/wireless/ti/cc33xx/scan.c [ ... ] > +struct scan_one_shot_info { > + u8 passive[CONN_SCAN_MAX_BAND]; > + u8 active[CONN_SCAN_MAX_BAND]; > + u8 dfs; > + > + struct conn_scan_ch_info channel_list[CONN_SCAN_MAX_CHANNELS_ALL_BAN= DS]; > + struct conn_scan_dwell_info dwell_info[CONN_SCAN_MAX_BAND]; > + u8 reserved; > +}; > + > +struct sched_scan_plan_cmd { > + u32 interval; > + u32 iterations; > +}; > + > +struct scan_periodic_info { > + struct sched_scan_plan_cmd sched_scan_plans[SCAN_MAX_SCHED_SCAN_PLANS]; > + u16 sched_scan_plans_num; [Severity: Medium] Should sched_scan_plan_cmd and scan_periodic_info use __le32 and __le16 instead of host-endian u32 and u16? Other firmware command structures in this driver are little-endian and packed, but cc33xx_sched_scan_start() copies req->scan_plans with a raw memcpy() and assigns req->n_scan_plans directly without byte swapping, sending byte-swapped scheduled scan parameters on big-endian hosts. Both struct sched_scan_plan_cmd and struct scan_one_shot_info also omit __packed even though they are embedded inside packed cc33xx_cmd_scan_params at a 2-byte aligned offset. Converting each plan element with cpu_to_le32() and the count with cpu_to_le16() would also decouple the firmware ABI from struct cfg80211_sched_scan_plan. [ ... ] > + ch_params_list =3D cmd_channels->channels_5; > + for (j =3D 0; j < MAX_CHANNELS_5GHZ; ++i, ++j) { > + ch_info_list[i].channel =3D ch_params_list[j].channel; > + ch_info_list[i].flags =3D ch_params_list[j].flags; > + ch_info_list[i].tx_power_att =3D ch_params_list[j].tx_power_att; > + } > + > + channel =3D &ch_params_list[0]; > + band =3D NL80211_BAND_5GHZ; > + dwell_info[band].min_duration =3D channel->min_duration; > + dwell_info[band].max_duration =3D channel->max_duration; > + dwell_info[band].passive_duration =3D channel->passive_duration; > +} [Severity: Low] Does taking passive_duration from channels_5[0] silently discard dwell_time_dfs? cc33xx_set_scan_chan_params() places non-DFS passive 5 GHz channels at the start of channels_5[] before DFS channels. When a 5 GHz passive scan includes both non-DFS and DFS channels, channels_5[0] is a non-DFS entry, so dwell_info[NL80211_BAND_5GHZ].passive_duration gets dwell_time_passive instead of the longer dwell_time_dfs configured in cc33xx_scan_get_channels(). > + > +static int cc33xx_cmd_build_probe_req(struct cc33xx *cc, > + struct cc33xx_vif *wlvif, u8 role_id, > + u8 scan_type, const u8 *ssid, > + size_t ssid_len, const u8 *ie0, > + size_t ie0_len, const u8 *ie1, > + size_t ie1_len) > +{ > + struct ieee80211_vif *vif =3D cc33xx_wlvif_to_vif(wlvif); > + struct sk_buff *skb =3D NULL; > + struct cc33xx_cmd_set_ies *cmd __free(kfree) =3D NULL; > + int ret; > + > + cmd =3D kzalloc_obj(*cmd); [Severity: Low] This isn't a bug, but per cleanup.h conventions __free(kfree) pointers should be declared and initialized at their allocation site rather than initialized to NULL at the top of the function. The same pattern appears in cc33xx_scan_send(), cc33xx_sched_scan_start(), and __cc33xx_scan_stop(). [ ... ] > + cmd->len =3D cpu_to_le16(skb->len - sizeof(struct ieee80211_hdr_3addr)); > + > + if (skb->data) { > + memcpy(cmd->data, > + skb->data + sizeof(struct ieee80211_hdr_3addr), le16_to_cpu(cmd= ->len)); > + } [Severity: High] Can this memcpy() overflow cmd->data? cmd->data is MAX_EXTRA_IES_LEN (512) bytes, while cc33xx_init_ieee80211() in drivers/net/wireless/ti/cc33xx/main.c sets wiphy->max_sched_scan_ie_len to 488 bytes (512 - 24). For scheduled scans, ieee80211_register_hw() does not subtract mac80211's own band IEs from max_sched_scan_ie_len, so cc33xx_sched_scan_start() passes up to 488 bytes of userspace common_ies plus the 2.4 GHz band IEs and the SSID IE (2 + ssid_len bytes) into cc33xx_cmd_build_probe_req(), overflowing the heap-allocated cc33xx_cmd_set_ies (or panicking under CONFIG_FORTIFY_SOURCE). One-shot scans can also exceed 512 bytes by the up to 34-byte SSID IE. Validating the IE length against sizeof(cmd->data) before copying (and freeing skb on error) and reserving SSID and band IE headroom in max_scan_ie_len and max_sched_scan_ie_len would prevent the overflow. > + > + usleep_range(10000, 11000); > + ret =3D cc33xx_cmd_send(cc, CMD_SET_PROBE_IE, cmd, sizeof(*cmd), 0); [Severity: Medium] Why is this unconditional 10-11 ms sleep needed before the synchronous CMD_SET_PROBE_IE command? cc33xx_cmd_build_probe_req() runs under wiphy_lock (twice per dual-band scan because SINGLE_SCAN_ON_ALL_BANDS is not set), so this stalls cfg80211/mac80211 control paths on every scan. If a firmware event that takes wiphy_lock arrives during the sleep, it also blocks irq_deferred_work and netstack_work on the single-threaded cc->freezable_wq, stalling RX and TX processing for 10-11 ms. If this delay is required by a firmware timing constraint, it should be documented; otherwise it can be removed. [ ... ] > + cc33xx_set_scan_chan_params(cc, cmd_channels, req->channels, > + req->n_channels, req->n_ssids, > + SCAN_TYPE_SEARCH); > + > + cc33xx_adjust_channels(&cmd->params, cmd_channels, cmd->scan_type); [Severity: Medium] Should cc33xx_scan_send() check the boolean return value of cc33xx_set_scan_chan_params() and return -EINVAL when it is false? If a regulatory update disables all channels in a pending or multi-band scan request before mac80211 invokes drv_hw_scan(), cc33xx_scan_get_channels() skips every channel and cc33xx_set_scan_chan_params() returns false, yet the driver still sends CMD_SCAN with zero channels and zero dwell times, risking a 30-second scan timeout and hardware recovery. cc33xx_sched_scan_start() similarly ignores the return value, which prevents ieee80211_reconfig() from stopping a restarted scheduled scan whose channels were disabled by a regulatory update. [ ... ] > + if (n_ssids <=3D 5) { > + alloc_size +=3D (n_ssids * sizeof(struct cc33xx_ssid)); > + } else { /* n_ssids > 5 */ > + ssid_list->scan_type =3D SCAN_REQUEST_CONNECT_PERIODIC_SCAN; > + ret =3D cc33xx_cmd_send(cc, CMD_CONNECTION_SCAN_SSID_CFG, > + ssid_list, sizeof(*ssid_list), 0); > + if (ret < 0) { > + dev_err(cc->dev, "cmd sched scan ssid list failed\n"); > + return ret; > + } > + } > + > + cmd =3D kzalloc(alloc_size, GFP_KERNEL); > + if (!cmd) > + return -ENOMEM; > + > + cmd->role_id =3D wlvif->role_id; > + > + if (WARN_ON(cmd->role_id =3D=3D CC33XX_INVALID_ROLE_ID)) > + return -EINVAL; [Severity: Low] Can CMD_CONNECTION_SCAN_SSID_CFG be sent with CC33XX_INVALID_ROLE_ID here? During hardware recovery, cc33xx_recovery_work() removes the interface (setting wlvif->role_id to CC33XX_INVALID_ROLE_ID) and cc33xx_init_fw() sets cc->state to CC33XX_STATE_ON before ieee80211_restart_hw() re-adds interfaces. If a scheduled scan with more than 5 SSIDs arrives in that window, cc33xx_sched_scan_start() sends CMD_CONNECTION_SCAN_SSID_CFG with role_id 0xff before the WARN_ON() check runs, which can fail and re-queue recovery. Moving the role_id check to the start of the function avoids sending the invalid command. [ ... ] > + cmd->filter =3D 1; > + cmd->num_of_ssids =3D n_ssids; [Severity: Medium] Should cmd->filter be set to 1 only when req->match_sets contains SSID filters? cc33xx_scan_sched_scan_ssid_list() handles unfiltered scheduled scans (when no match_sets have SSIDs) but only returns cmd->n_ssids, so cc33xx_sched_scan_start() unconditionally sets cmd->filter =3D 1. That tells the firmware to forward only results matching the configured SSID list, silently dropping discovered BSSes on unfiltered scheduled scans. [ ... ] > +void cc33xx_scan_complete_work(struct wiphy *wiphy, > + struct wiphy_work *work) > + > +{ > + struct cc33xx *cc; > + struct cfg80211_scan_info info =3D { > + .aborted =3D false, > + }; > + > + cc =3D container_of(work, struct cc33xx, scan_complete_work.work); > + > + if (unlikely(cc->state !=3D CC33XX_STATE_ON)) > + return; > + > + if (cc->scan.state =3D=3D CC33XX_SCAN_STATE_IDLE) > + return; > + > + cc->scan.state =3D CC33XX_SCAN_STATE_IDLE; > + cc->scan.req =3D NULL; > + cc->scan_wlvif =3D NULL; > + > + if (cc->scan.failed) { > + dev_info(cc->dev, "Scan completed due to error.\n"); > + cc33xx_queue_recovery_work(cc); > + } > + > + ieee80211_scan_completed(cc->hw, &info); > +} [Severity: Medium] Should info.aborted be set to true when cc->scan.failed is true? Leaving info.aborted false on a scan timeout tells mac80211 that the scan succeeded. Because SINGLE_SCAN_ON_ALL_BANDS is not set, __ieee80211_scan_completed() immediately calls drv_hw_scan() for the next band against the wedged firmware while holding wiphy_lock, and on the final band cfg80211 reports normal scan completion instead of an abort. [ ... ] > + cc->scan_wlvif =3D wlvif; > + cc->scan.req =3D req; > + > + wiphy_delayed_work_queue(cc->hw->wiphy, &cc->scan_complete_work, > + msecs_to_jiffies(CC33XX_SCAN_TIMEOUT)); [Severity: Medium] Can a stale scan_complete_work timer from a removed interface abort a later scan on another interface? If cc33xx_op_cancel_hw_scan() fails during interface teardown, __cc33xx_op_remove_interface() in drivers/net/wireless/ti/cc33xx/main.c resets cc->scan.state and calls ieee80211_scan_completed() without cancelling cc->scan_complete_work. When another interface stays up, the 30-second timer remains armed: CPU0 CPU1 () __cc33xx_op_remove_interface() cc->scan.state =3D IDLE (timer not cancelled) wiphy_delayed_work_timer() wiphy_work_queue(scan_complete_work) cc33xx_op_hw_scan() -> cc33xx_scan() cc->scan.state =3D ACTIVE cc->scan.failed =3D true wiphy_delayed_work_queue(..., 30s) cfg80211_wiphy_work() cc33xx_scan_complete_work() <-- completes new scan, queues recovery Because wiphy_delayed_work_queue() with a non-zero delay only calls mod_timer() and does not dequeue an already-queued work item, the stale work runs immediately after cc33xx_op_hw_scan() releases wiphy_lock, prematurely finishing the new scan and triggering hardware recovery. Calling wiphy_delayed_work_cancel() in __cc33xx_op_remove_interface() would close this window. [ ... ] > +void cc33xx_scan_completed(struct cc33xx *cc) > +{ > + wiphy_lock(cc->hw->wiphy); [Severity: High] Can taking wiphy_lock() here ABBA deadlock with cc33xx_cmd_remove_peer()? cc33xx_scan_completed() runs inside process_deferred_events() on the single-threaded cc->freezable_wq, which is also the only context that processes PEER_REMOVE_COMPLETE_EVENT_ID and completes cc->peer_remove_complete. If a station disconnects from an AP interface while a scan completes: CPU0 CPU1 ---- ---- lock(&wiphy->mtx) process_deferred_events() cc33xx_scan_completed() lock(&wiphy->mtx) wait_for_completion_timeout( &cc->peer_remove_complete) *** DEADLOCK *** CPU0: drv_sta_state() -> cc33xx_op_sta_state() -> cc33xx_sta_remove() -> cc33xx_cmd_remove_peer() CPU1: cc33xx_irq_work() -> process_deferred_events() -> cc33xx_scan_completed() This stalls wiphy->mtx and cc->freezable_wq (blocking RX, TX completion, and event handling) until the 5-second CC33XX_EVENT_TIMEOUT expires, causing cc33xx_cmd_remove_peer() to fail with -ETIMEDOUT and trigger hardware recovery. > + if (cc->scan_wlvif) { > + cc->scan.failed =3D false; [Severity: Medium] Should cc->scan.state be set to CC33XX_SCAN_STATE_DONE here? cc33xx_op_cancel_hw_scan() in drivers/net/wireless/ti/cc33xx/main.c checks for CC33XX_SCAN_STATE_DONE to skip sending CMD_STOP_SCAN once the firmware has finished scanning, but CC33XX_SCAN_STATE_DONE is never assigned anywhere in the driver. If a scan cancel arrives between cc33xx_scan_completed() and scan_complete_work, the driver sends a spurious CMD_STOP_SCAN for an already-completed scan, which if rejected by firmware causes cc33xx_op_cancel_hw_scan() to return early and queue hardware recovery. > + wiphy_delayed_work_queue(cc->hw->wiphy, &cc->scan_complete_work, > + msecs_to_jiffies(0)); > + } > + wiphy_unlock(cc->hw->wiphy); > +} [Severity: Medium] Can an in-flight timeout timer race with wiphy_delayed_work_queue(..., 0) and abort the next band's scan? On the zero-delay path, wiphy_delayed_work_queue() calls non-synchronous timer_delete() instead of waiting for a running timer callback. Because rdev->wiphy_work_list is processed FIFO and SINGLE_SCAN_ON_ALL_BANDS is not set, an in-flight timer from scan 1 can queue scan_complete_work behind local->scan_work: CPU0 CPU1 () wiphy_delayed_work_timer() cc33xx_scan_completed() cc->scan.failed =3D false wiphy_delayed_work_queue(..., 0) timer_delete() (no wait) wiphy_work_queue(scan_complete) cfg80211_wiphy_work() cc33xx_scan_complete_work() ieee80211_scan_completed() queue local->scan_work wiphy_work_queue(scan_complete) ieee80211_scan_work() cc33xx_scan() (next band) cc->scan.state =3D ACTIVE cc->scan.failed =3D true cc33xx_scan_complete_work() <-- aborts scan 2, queues recovery Calling wiphy_delayed_work_cancel() before queuing scan_complete_work would synchronize with the timer callback via timer_delete_sync(). --=20 Sashiko AI review =C2=B7 https://sashiko.dev/#/patchset/20261203070906.1294= 171-1-r-ramalingam@ti.com?part=3D13