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=1796284106; b=znOe9BeAnnF2zU90W8O7hnWBu6D2cDjDXO4eQ1soNk6zeR5YCDvEOmbIg1txUv/T29IZ v56EHcdE4ZLyh6pafanwZZikWxdpukSCDc8hfmZPWGnymqzCkW8Ux73xC7DoXnJ+H4W7Y v/Lyx1aeG+MMYEhz4jAZ6U+3WX+OgpxNKbR5YLpeVknR4rJTxm/HM5zXnNeN4UY7RKPfY VdsWNUAdzQiXxmzyiv2IvRzl++c4sp+saI21b7KKeJgh8ov92u9+z293FUFf2x6qQ8oSf uFDsghe9Hi0LBsiORby8wIhINTakt5l9wL9fEl3tSpHqfKXpBP9LIKLVrYQtftv9kJQ== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796284106; h=Received:DKIM-Signature:Message-ID:From:Subject:Reply-To:To:Cc: In-Reply-To:References:Content-Type:Content-Transfer-Encoding:Date; bh=L0mjjl18aLB5RrHOZW3NG4uhcKcnp9cZBIAWg4IUtGE=; b=vUUu8VPer2PkBPJeV+IVcpoOxMGISB45ZWkAt84PFCHDMKsPic5Ca+ZqCwROv5x4fWDB Vc3PcV0tSkLt8N0+5+93i5tHDVWC0jXsPP7KQeQDDb7hLGPezUybMNbRqMJj5IQFqoTPa 2/mVbWVHCuqJ5Lmpx50hZAshtOA8tQ8mCtb194p6gWWfZS88uX2+qH1tNrWKysGdR149W ezsCvJo92H7uRVQ/DQ3JydmLiD77p4MRpuX1h42NnS25Z5FwZo70lEU7z1dWV/VLwKX/g q8hd31V+V3VhU9k3qBdJ5pkeJRq9QA+9sTM3K5x1p6IskmTdtZ9s/ktEpSFAxm1Ekxw== 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=kcXGoZAL; 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 3194F606A322 for ; Thu, 3 Dec 2026 07:48:26 +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=kcXGoZAL Received: by smtp.kernel.org (Postfix) with ESMTPSA id D33F41F00893; Thu, 3 Dec 2026 07:48:25 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1796284106; bh=L0mjjl18aLB5RrHOZW3NG4uhcKcnp9cZBIAWg4IUtGE=; h=From:Subject:Reply-To:To:Cc:In-Reply-To:References:Date; b=kcXGoZALMtexAvMuAAE3XYJa8OQS93m2KrNf1Pnl89bWlbG9Z8bzi0cUpWSxruJeG bkiGt6ZdXQ6H1iR896PiqWopidLG3ftqG4JV1b1DsBIcDj2i2O60Qf7LB5Go3hhfPn Atrn5TvJlE6pyadRG2v13eHFojaFBt/JeyiHVoqEFpHRQirDc6NhxpOi255kSk3tkF 8OlMLRp8SJLTHTm23Wf8iuTrALYdimCJ1djH/BdmhGTmE7OCRF6WhRJoKJTZq6nrul XAsQp//sPxESVT+Z+fkPKV6wzMYhHCyvKJxV5xNDzXN2EW/Xf/47s5MlSlbH652uN8 JNVZzAQL5tTWw== Message-ID: From: sashiko-bot@kernel.org Subject: Re: [PATCH v6 16/17] wifi: cc33xx: Add testmode.c, testmode.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-17-r-ramalingam@ti.com> References: <20261203070906.1294171-1-r-ramalingam@ti.com> <20261203070906.1294171-17-r-ramalingam@ti.com> Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable Date: Thu, 03 Dec 2026 07:48:25 +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 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 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/wire= less/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 =3D 0; > + > + if (!tb[CC33XX_TM_ATTR_DATA]) > + return -EINVAL; > + > + buf =3D nla_data(tb[CC33XX_TM_ATTR_DATA]); > + buf_len =3D 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 =3D 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 !=3D CC33XX_STATE_ON)) > + return -EINVAL; > + > + ret =3D 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 =3D buf_len for the netlink attribute buffer, and cc33xx_tm_cmd_interrogate() similarly passes res_len =3D sizeof(*cmd) for its kmalloc buffer. If cc->result_leng= th 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 *t= b[]) > +{ > + int ret; > + struct cc33xx_command *cmd __free(kfree) =3D 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 =3D 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 =3D 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 =3D=3D 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 =3D 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 =3D 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 =3D nla_total_size(sizeof(cc->fem_manuf)); > + skb =3D cfg80211_testmode_alloc_reply_skb(cc->hw->wiphy, len); > + if (!skb) { > + ret =3D -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 =3D nla_get_u32(tb[CC33XX_TM_ATTR_PLT_MODE]); > + > + switch (val) { > + case PLT_OFF: > + ret =3D cc33xx_plt_stop(cc); > + break; > + case PLT_ON: > + case PLT_CHIP_AWAKE: > + ret =3D cc33xx_plt_start(cc, val); > + break; > + case PLT_FEM_DETECT: > + ret =3D 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 =3D 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 =3D hw->priv; > + struct nlattr *tb[TM_ATTR_MAX + 1]; > + u32 nla_cmd; > + int err; > + > + err =3D 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/wire= less/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? --=20 Sashiko AI review =C2=B7 https://sashiko.dev/#/patchset/20261203070906.1294= 171-1-r-ramalingam@ti.com?part=3D16