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 16/17] wifi: cc33xx: Add testmode.c, testmode.h
Date: Thu, 03 Dec 2026 07:48:25 +0000	[thread overview]
Message-ID: <sashiko-outbox-247323@kernel.org> (raw)
In-Reply-To: <20261203070906.1294171-17-r-ramalingam@ti.com>

Thank you for your contribution! Sashiko AI review found 14 potential
issues to consider:
- [High] wifi: cc33xx: OOB write by nab_header size in
  __cc33xx_cmd_send()
- [High] wifi: cc33xx: broken PLT state transitions in
  cc33xx_plt_start()/stop()
- [Medium] wifi: cc33xx: NLA_U32 IE ID read with nla_get_u8() in
  testmode
- [Medium] wifi: cc33xx: missing data length and alignment checks in
  testmode
- [Medium] wifi: cc33xx: in-place mutation of netlink SKB payload in
  testmode
- [Medium] wifi: cc33xx: missing state check and recovery sync in
  testmode
- [Medium] wifi: cc33xx: transceiver role leak on error in
  cc33xx_plt_init()
- [Medium] wifi: cc33xx: unsafe init_completion() re-init in
  __cc33xx_cmd_send()
- [Medium] wifi: cc33xx: cc33xx_tm_detect_fem() returns unpopulated
  cc->fem_manuf
- [Medium] wifi: cc33xx: PLT_FEM_DETECT re-entry leaks role and stops
  active PLT
- [Medium] wifi: cc33xx: PLT state race between cc33xx_tm_cmd() and
  cc33xx_unregister_hw()
- [Low] wifi: cc33xx: nla_parse_deprecated() and non-const policy in
  testmode.c
- [Low] wifi: cc33xx: testmode.h missing mac80211.h include or struct
  declarations
- [Low] wifi: cc33xx: split __free(kfree) declaration in
  cc33xx_tm_cmd_interrogate()
--

commit e8cb943041cb92e4309b9948db961256bccd677e
Author: Michael Nemanov <michael.nemanov@ti.com>

wifi: cc33xx: Add testmode.c, testmode.h

This commit adds cfg80211 testmode support to the cc33xx driver, allowing
userspace tools to send firmware test and debug commands, control PLT mode,
and query the efuse MAC address.

> diff --git a/drivers/net/wireless/ti/cc33xx/testmode.c b/drivers/net/wireless/ti/cc33xx/testmode.c
> new file mode 100644
> index 0000000000000..5d149f958b69d
> --- /dev/null
> +++ b/drivers/net/wireless/ti/cc33xx/testmode.c

[ ... ]

> +static int cc33xx_tm_cmd_test(struct cc33xx *cc, struct nlattr *tb[])
> +{
> +	int ret, len;
> +	u16 buf_len;
> +	struct sk_buff *skb;
> +	void *buf;
> +	u8 answer = 0;
> +
> +	if (!tb[CC33XX_TM_ATTR_DATA])
> +		return -EINVAL;
> +
> +	buf = nla_data(tb[CC33XX_TM_ATTR_DATA]);
> +	buf_len = nla_len(tb[CC33XX_TM_ATTR_DATA]);

[Severity: Medium]
Can passing buf directly into cc33xx_cmd_test() mutate a shared netlink
sk_buff?

netlink_unicast_kernel() clones incoming skbs for netlink taps via
skb_clone() before invoking nl80211_testmode_do().  Both cc33xx_cmd_test()
and cc33xx_cmd_debug() (called the same way from cc33xx_tm_cmd_configure())
overwrite headers and response data in place inside buf, which races with
and corrupts packets observed by nlmon.  Copying CC33XX_TM_ATTR_DATA into a
driver-owned buffer before calling the command helpers would avoid this.

> +	if (tb[CC33XX_TM_ATTR_ANSWER])
> +		answer = nla_get_u8(tb[CC33XX_TM_ATTR_ANSWER]);
> +
> +	if (buf_len > sizeof(struct cc33xx_command))
> +		return -EMSGSIZE;

[Severity: Medium]
Should this also reject undersized or unaligned buf_len values?

If userspace sends a payload shorter than sizeof(struct cc33xx_cmd_header)
or not 4-byte aligned, __cc33xx_cmd_send() hits WARN_ON() and returns -EIO,
which makes cc33xx_cmd_send_failsafe() queue recovery work and reset the
chip instead of returning -EINVAL.  cc33xx_tm_cmd_configure() has the same
missing minimum-length (sizeof(struct debug_header)) and 4-byte alignment
checks.

> +	if (unlikely(cc->state != CC33XX_STATE_ON))
> +		return -EINVAL;
> +
> +	ret = cc33xx_cmd_test(cc, buf, buf_len, answer);

[Severity: High]
Can __cc33xx_cmd_send() write up to 8 bytes past the end of buf here?

__cc33xx_cmd_send() checks cc->result_length against res_len, then copies
at offset sizeof(struct nab_header):

drivers/net/wireless/ti/cc33xx/cmd.c:__cc33xx_cmd_send() {
	...
	if (WARN_ON(cc->result_length > res_len)) {
		dev_err(cc->dev, "Error, insufficient response buffer\n");
		return -EINVAL;
	}

	switch (id) {
	case CMD_INTERROGATE:
	case CMD_DEBUG_READ:
	case CMD_TEST_MODE:
	case CMD_BM_READ_DEVICE_INFO:
		memcpy(buf + sizeof(struct nab_header), cc->command_result,
		       cc->result_length);
		break;
	...
}

When answer is non-zero, cc33xx_tm_cmd_test() passes res_len = buf_len for
the netlink attribute buffer, and cc33xx_tm_cmd_interrogate() similarly
passes res_len = sizeof(*cmd) for its kmalloc buffer.  If cc->result_length
is within 7 bytes of res_len (or res_len is smaller than
sizeof(struct nab_header)), the memcpy() overruns buf by up to 8 bytes.

[Severity: Medium]
Does calling init_completion(&cc->command_complete) inside
__cc33xx_cmd_send() race with late command completion interrupts?

cc->command_complete is never initialized once at allocation time and is
instead re-initialized on every command send under cc->cmd_lock, while
parse_control_message() calls complete(&cc->command_complete) without
holding cc->cmd_lock:

CPU0                              IRQ / kworker
__cc33xx_cmd_send()
  wait_for_completion_timeout()
    /* times out, returns -EIO */
__cc33xx_cmd_send() /* next cmd */
  guard(mutex)(&cc->cmd_lock)
  init_completion(&cc->command_complete)
                                  parse_control_message()
                                    complete(&cc->command_complete)
                                      <-- races on waitqueue spinlock

Re-initializing the waitqueue spinlock while a late IRQ completion uses it
can corrupt the completion state.  Initializing cc->command_complete once in
cc33xx_alloc_hw() and using reinit_completion() in __cc33xx_cmd_send()
would prevent this.

[ ... ]

> +static int cc33xx_tm_cmd_interrogate(struct cc33xx *cc, struct nlattr *tb[])
> +{
> +	int ret;
> +	struct cc33xx_command *cmd __free(kfree) = NULL;

[Severity: Low]
This isn't a bug, but per Cleanup API conventions, cmd can be defined and
initialized directly at the kzalloc_obj(*cmd) call instead of being
declared as NULL at the top of the function.

> +	struct sk_buff *skb;
> +	u8 ie_id;
> +
> +	if (!tb[CC33XX_TM_ATTR_IE_ID])
> +		return -EINVAL;
> +
> +	ie_id = nla_get_u8(tb[CC33XX_TM_ATTR_IE_ID]);

[Severity: Medium]
Should CC33XX_TM_ATTR_IE_ID be read with nla_get_u32() instead of
nla_get_u8()?

cc33xx_tm_policy declares CC33XX_TM_ATTR_IE_ID as NLA_U32, so nla_get_u8()
reads the most-significant byte on big-endian hosts (dispatching ID 0 for
all valid debug commands) and silently truncates 16-bit IDs above 255 even
though cc33xx_cmd_debug_inter() takes a u16.  cc33xx_tm_cmd_configure() has
the same issue.

[ ... ]

> +static int cc33xx_tm_cmd_configure(struct cc33xx *cc, struct nlattr *tb[])
> +{

[ ... ]

> +	ret = cc33xx_cmd_debug(cc, ie_id, buf, buf_len);

[Severity: Medium]
Can cc33xx_tm_cmd_configure() and cc33xx_tm_cmd_set_plt_mode() issue
firmware commands while the chip is powered off or mid-recovery?

Unlike cc33xx_tm_cmd_test() and cc33xx_tm_cmd_interrogate(), neither
cc33xx_tm_cmd_configure() nor cc33xx_plt_start() checks cc->state ==
CC33XX_STATE_ON.  In addition, cc33xx_tm_cmd() runs under wiphy_lock only
without cc->mutex or a CC33XX_FLAG_RECOVERY_IN_PROGRESS check, while
cc33xx_recovery_work() drops wiphy_lock before power-off and firmware boot:

CPU0                              CPU1
cc33xx_recovery_work()
  wiphy_unlock(cc->hw->wiphy)
  cc33xx_turn_off(cc)
                                  cc33xx_tm_cmd() /* holds wiphy_lock */
                                    cc33xx_tm_cmd_configure()
                                      cc33xx_cmd_debug() <-- I/O while OFF
  msleep(500)
  cc33xx_init_fw(cc)
    cc->state = CC33XX_STATE_ON

This can attempt SDIO command I/O against a powered-off or booting chip
(stalling wiphy_lock until timeout and re-triggering recovery) and races on
cc->state, cc->roles_map, and firmware download state.

[ ... ]

> +static int cc33xx_tm_detect_fem(struct cc33xx *cc)
> +{
> +	/* return FEM type */
> +	int ret, len;
> +	struct sk_buff *skb;
> +
> +	ret = cc33xx_plt_start(cc, PLT_FEM_DETECT);

[Severity: Medium]
What happens if PLT_FEM_DETECT is requested while PLT mode is already
active?

cc33xx_plt_start() only rejects re-entry when both the requested and
current modes are PLT_ON.  Calling PLT_FEM_DETECT while already in PLT_ON
runs cc33xx_plt_init() a second time, overwriting cc->plt_role_id and
leaking the first firmware transceiver role and its cc->roles_map bit, and
then out_stop unconditionally calls cc33xx_plt_stop() and tears down the
active PLT session.

> +	if (ret < 0)
> +		return ret;
> +
> +	len = nla_total_size(sizeof(cc->fem_manuf));
> +	skb = cfg80211_testmode_alloc_reply_skb(cc->hw->wiphy, len);
> +	if (!skb) {
> +		ret = -ENOMEM;
> +		goto out_stop;
> +	}
> +
> +	if (nla_put(skb, CC33XX_TM_ATTR_DATA, sizeof(cc->fem_manuf),
> +		    &cc->fem_manuf)) {

[Severity: Medium]
Is cc->fem_manuf ever populated anywhere in the driver?

Nothing in drivers/net/wireless/ti/cc33xx/ assigns cc->fem_manuf, so
PLT_FEM_DETECT always returns 0 to userspace instead of an actual FEM
manufacturer ID or -EOPNOTSUPP.

[ ... ]

> +static int cc33xx_tm_cmd_set_plt_mode(struct cc33xx *cc, struct nlattr *tb[])
> +{
> +	u32 val;
> +	int ret;
> +
> +	if (!tb[CC33XX_TM_ATTR_PLT_MODE])
> +		return -EINVAL;
> +
> +	val = nla_get_u32(tb[CC33XX_TM_ATTR_PLT_MODE]);
> +
> +	switch (val) {
> +	case PLT_OFF:
> +		ret = cc33xx_plt_stop(cc);
> +		break;
> +	case PLT_ON:
> +	case PLT_CHIP_AWAKE:
> +		ret = cc33xx_plt_start(cc, val);
> +		break;
> +	case PLT_FEM_DETECT:
> +		ret = cc33xx_tm_detect_fem(cc);
> +		break;

[Severity: High]
Can switching to PLT_CHIP_AWAKE and then PLT_OFF disable an active role or
permanently wedge the driver in PLT_CHIP_AWAKE?

cc33xx_plt_start() skips cc33xx_plt_init() for PLT_CHIP_AWAKE, so no
transceiver role is allocated, yet cc33xx_plt_stop() unconditionally calls
cc33xx_cmd_role_stop_transceiver() and cc33xx_cmd_role_disable() before
clearing cc->plt and cc->plt_mode.  Because cc->plt_role_id starts at 0,
exiting PLT_CHIP_AWAKE either disables role 0 (which may belong to an
active interface) or, after a prior PLT session leaves it at
CC33XX_INVALID_ROLE_ID, hits WARN_ON() in cc33xx_cmd_role_disable() and
returns early with cc->plt_mode permanently stuck at PLT_CHIP_AWAKE.

cc33xx_plt_start() also never checks list_empty(&cc->wlvif_list), allowing
PLT mode to start while normal interfaces are active.

[Severity: Medium]
Does cc33xx_plt_init() leak the transceiver role if cc33xx_cmd_plt_enable()
fails?

If cc33xx_cmd_plt_enable() returns an error, cc33xx_plt_init() returns
without stopping or disabling cc->plt_role_id, and cc33xx_plt_start()
leaves cc->plt false so cc33xx_plt_stop() never cleans it up.

[Severity: Medium]
Can cc33xx_tm_cmd_set_plt_mode() race with cc33xx_unregister_hw() on PLT
state and corrupt struct cc33xx?

cc33xx_unregister_hw() checks cc->plt and calls cc33xx_plt_stop() before
ieee80211_unregister_hw() without holding wiphy_lock or cc->mutex, while
cc33xx_tm_cmd() holds only wiphy_lock:

CPU0                              CPU1
cc33xx_unregister_hw()
  if (cc->plt) /* unlocked */
  cc33xx_plt_stop()
    cc33xx_cmd_role_disable()
      /* checks *role_id valid */
                                  cc33xx_tm_cmd_set_plt_mode(PLT_OFF)
                                    cc33xx_plt_stop()
                                      cc33xx_cmd_role_disable()
                                        __clear_bit(*role_id, ...)
                                        *role_id = CC33XX_INVALID_ROLE_ID
      __clear_bit(*role_id, ...)
        <-- clears bit 255 past cc->roles_map

Because CC33XX_INVALID_ROLE_ID is 0xff while cc->roles_map only holds 4
bits, a racing double stop can clear bit 255 past cc->roles_map.  A
concurrent PLT_ON can also start PLT during teardown, and cc33xx_plt_stop()
resets cc->rx_counter without cc->mutex, racing with
cc33xx_rx_handle_packet().

[ ... ]

> +int cc33xx_tm_cmd(struct ieee80211_hw *hw, struct ieee80211_vif *vif,
> +		  void *data, int len)
> +{
> +	struct cc33xx *cc = hw->priv;
> +	struct nlattr *tb[TM_ATTR_MAX + 1];
> +	u32 nla_cmd;
> +	int err;
> +
> +	err = nla_parse_deprecated(tb, TM_ATTR_MAX, data, len,
> +				   cc33xx_tm_policy, NULL);

[Severity: Low]
Should this new netlink parser use strict nla_parse() instead of
nla_parse_deprecated(), and can cc33xx_tm_policy be declared static const?

> diff --git a/drivers/net/wireless/ti/cc33xx/testmode.h b/drivers/net/wireless/ti/cc33xx/testmode.h
> new file mode 100644
> index 0000000000000..adb98c117b608
> --- /dev/null
> +++ b/drivers/net/wireless/ti/cc33xx/testmode.h
> @@ -0,0 +1,12 @@
> +/* SPDX-License-Identifier: GPL-2.0-only
> + *
> + * Copyright (C) 2022-2026 Texas Instruments Incorporated - https://www.ti.com/
> + */
> +
> +#ifndef __TESTMODE_H__
> +#define __TESTMODE_H__
> +
> +int cc33xx_tm_cmd(struct ieee80211_hw *hw, struct ieee80211_vif *vif,
> +		  void *data, int len);

[Severity: Low]
Should testmode.h include net/mac80211.h or forward-declare struct
ieee80211_hw and struct ieee80211_vif so the header is self-contained?

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

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

Thread overview: 34+ 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
2026-12-03  7:09 ` [PATCH v6 14/17] wifi: cc33xx: Add conf.h Ramesh Ramalingam
2026-12-03  7:50   ` sashiko-bot
2026-12-03  7:09 ` [PATCH v6 15/17] wifi: cc33xx: Add ps.c, ps.h Ramesh Ramalingam
2026-12-03  7:43   ` sashiko-bot
2026-12-03  7:09 ` [PATCH v6 16/17] wifi: cc33xx: Add testmode.c, testmode.h Ramesh Ramalingam
2026-12-03  7:48   ` sashiko-bot [this message]
2026-12-03  7:09 ` [PATCH v6 17/17] wifi: cc33xx: Add Kconfig, Makefile Ramesh Ramalingam
2026-12-03  7:46   ` 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-247323@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