Devicetree
 help / color / mirror / Atom feed
From: sashiko-bot@kernel.org
To: "Ramesh Ramalingam" <r-ramalingam@ti.com>
Cc: devicetree@vger.kernel.org, robh@kernel.org, conor+dt@kernel.org
Subject: Re: [PATCH v6 13/17] wifi: cc33xx: Add scan.c, scan.h
Date: Thu, 03 Dec 2026 07:52:43 +0000	[thread overview]
Message-ID: <sashiko-outbox-247329@kernel.org> (raw)
In-Reply-To: <20261203070906.1294171-14-r-ramalingam@ti.com>

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 <michael.nemanov@ti.com>

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_BANDS];
> +	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 = cmd_channels->channels_5;
> +	for (j = 0; j < MAX_CHANNELS_5GHZ; ++i, ++j) {
> +		ch_info_list[i].channel = ch_params_list[j].channel;
> +		ch_info_list[i].flags = ch_params_list[j].flags;
> +		ch_info_list[i].tx_power_att = ch_params_list[j].tx_power_att;
> +	}
> +
> +	channel = &ch_params_list[0];
> +	band = NL80211_BAND_5GHZ;
> +	dwell_info[band].min_duration     = channel->min_duration;
> +	dwell_info[band].max_duration     = channel->max_duration;
> +	dwell_info[band].passive_duration = 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 = cc33xx_wlvif_to_vif(wlvif);
> +	struct sk_buff *skb = NULL;
> +	struct cc33xx_cmd_set_ies *cmd __free(kfree) = NULL;
> +	int ret;
> +
> +	cmd = 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 = 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 = 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 <= 5) {
> +		alloc_size += (n_ssids * sizeof(struct cc33xx_ssid));
> +	} else { /* n_ssids > 5 */
> +		ssid_list->scan_type = SCAN_REQUEST_CONNECT_PERIODIC_SCAN;
> +		ret = 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 = kzalloc(alloc_size, GFP_KERNEL);
> +	if (!cmd)
> +		return -ENOMEM;
> +
> +	cmd->role_id = wlvif->role_id;
> +
> +	if (WARN_ON(cmd->role_id == 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 = 1;
> +	cmd->num_of_ssids = 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 = 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 = {
> +		.aborted = false,
> +	};
> +
> +	cc = container_of(work, struct cc33xx, scan_complete_work.work);
> +
> +	if (unlikely(cc->state != CC33XX_STATE_ON))
> +		return;
> +
> +	if (cc->scan.state == CC33XX_SCAN_STATE_IDLE)
> +		return;
> +
> +	cc->scan.state = CC33XX_SCAN_STATE_IDLE;
> +	cc->scan.req = NULL;
> +	cc->scan_wlvif = 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 = wlvif;
> +	cc->scan.req = 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 (<softirq>)
__cc33xx_op_remove_interface()
  cc->scan.state = IDLE
  (timer not cancelled)
                                    wiphy_delayed_work_timer()
                                      wiphy_work_queue(scan_complete_work)
cc33xx_op_hw_scan() -> cc33xx_scan()
  cc->scan.state = ACTIVE
  cc->scan.failed = 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 = 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 (<softirq>)
                                    wiphy_delayed_work_timer()
cc33xx_scan_completed()
  cc->scan.failed = 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 = ACTIVE
      cc->scan.failed = 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().

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20261203070906.1294171-1-r-ramalingam@ti.com?part=13

  reply	other threads:[~2026-12-03  7:52 UTC|newest]

Thread overview: 30+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-12-03  7:08 [PATCH v6 00/17] wifi: cc33xx: Add driver for new TI CC33xx wireless device family Ramesh Ramalingam
2026-12-03  7:08 ` [PATCH v6 01/17] dt-bindings: net: wireless: cc33xx: Add ti,cc33xx.yaml Ramesh Ramalingam
2026-12-03  7:20   ` sashiko-bot
2026-12-03  7:08 ` [PATCH v6 02/17] wifi: cc33xx: Add cc33xx.h, cc33xx_i.h Ramesh Ramalingam
2026-12-03  7:31   ` sashiko-bot
2026-12-03  7:08 ` [PATCH v6 03/17] wifi: cc33xx: Add debug.h Ramesh Ramalingam
2026-12-03  7:26   ` sashiko-bot
2026-12-03  7:08 ` [PATCH v6 04/17] wifi: cc33xx: Add sdio.c, io.c, io.h Ramesh Ramalingam
2026-12-03  7:33   ` sashiko-bot
2026-12-03  7:08 ` [PATCH v6 05/17] wifi: cc33xx: Add cmd.c, cmd.h Ramesh Ramalingam
2026-12-03  7:42   ` sashiko-bot
2026-12-03  7:08 ` [PATCH v6 06/17] wifi: cc33xx: Add acx.c, acx.h Ramesh Ramalingam
2026-12-03  7:32   ` sashiko-bot
2026-12-03  7:08 ` [PATCH v6 07/17] wifi: cc33xx: Add event.c, event.h Ramesh Ramalingam
2026-12-03  7:31   ` sashiko-bot
2026-12-03  7:08 ` [PATCH v6 08/17] wifi: cc33xx: Add boot.c, boot.h Ramesh Ramalingam
2026-12-03  7:38   ` sashiko-bot
2026-12-03  7:08 ` [PATCH v6 09/17] wifi: cc33xx: Add main.c Ramesh Ramalingam
2026-12-03  7:08 ` [PATCH v6 10/17] wifi: cc33xx: Add rx.c, rx.h Ramesh Ramalingam
2026-12-03  7:33   ` sashiko-bot
2026-12-03  7:09 ` [PATCH v6 11/17] wifi: cc33xx: Add tx.c, tx.h Ramesh Ramalingam
2026-12-03  7:47   ` sashiko-bot
2026-12-03  7:09 ` [PATCH v6 12/17] wifi: cc33xx: Add init.c, init.h Ramesh Ramalingam
2026-12-03  7:43   ` sashiko-bot
2026-12-03  7:09 ` [PATCH v6 13/17] wifi: cc33xx: Add scan.c, scan.h Ramesh Ramalingam
2026-12-03  7:52   ` sashiko-bot [this message]
     [not found] ` <20261203070906.1294171-16-r-ramalingam@ti.com>
2026-12-03  7:43   ` [PATCH v6 15/17] wifi: cc33xx: Add ps.c, ps.h sashiko-bot
     [not found] ` <20261203070906.1294171-18-r-ramalingam@ti.com>
2026-12-03  7:46   ` [PATCH v6 17/17] wifi: cc33xx: Add Kconfig, Makefile sashiko-bot
     [not found] ` <20261203070906.1294171-17-r-ramalingam@ti.com>
2026-12-03  7:48   ` [PATCH v6 16/17] wifi: cc33xx: Add testmode.c, testmode.h sashiko-bot
     [not found] ` <20261203070906.1294171-15-r-ramalingam@ti.com>
2026-12-03  7:50   ` [PATCH v6 14/17] wifi: cc33xx: Add conf.h sashiko-bot

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=sashiko-outbox-247329@kernel.org \
    --to=sashiko-bot@kernel.org \
    --cc=conor+dt@kernel.org \
    --cc=devicetree@vger.kernel.org \
    --cc=r-ramalingam@ti.com \
    --cc=robh@kernel.org \
    --cc=sashiko-reviews@lists.linux.dev \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox