wifi: ath10k: replace deprecated strncpy with memcpy
authorJustin Stitt <justinstitt@google.com>
Wed, 25 Oct 2023 17:47:56 +0000 (20:47 +0300)
committerKalle Valo <quic_kvalo@quicinc.com>
Tue, 31 Oct 2023 07:46:11 +0000 (09:46 +0200)
strncpy() is deprecated [1] and we should prefer less ambiguous
interfaces.

In this case, arvif->u.ap.ssid has its length maintained by
arvif->u.ap.ssid_len which indicates it may not need to be
NUL-terminated. Make this explicit with __nonstring and use a plain old
memcpy.

This is also consistent with future copies into arvif->u.ap.ssid:

if (changed & BSS_CHANGED_SSID &&
    vif->type == NL80211_IFTYPE_AP) {
arvif->u.ap.ssid_len = vif->cfg.ssid_len;
if (vif->cfg.ssid_len)
memcpy(arvif->u.ap.ssid, vif->cfg.ssid,
       vif->cfg.ssid_len);
arvif->u.ap.hidden_ssid = info->hidden_ssid;
}

Link: https://www.kernel.org/doc/html/latest/process/deprecated.html#strncpy-on-nul-terminated-strings
Link: https://github.com/KSPP/linux/issues/90
Cc: linux-hardening@vger.kernel.org
Signed-off-by: Justin Stitt <justinstitt@google.com>
Acked-by: Jeff Johnson <quic_jjohnson@quicinc.com>
Signed-off-by: Kalle Valo <quic_kvalo@quicinc.com>
Link: https://lore.kernel.org/r/20231024-strncpy-drivers-net-wireless-ath-ath10k-mac-c-v2-1-4c1f4cd4b4df@google.com
drivers/net/wireless/ath/ath10k/core.h
drivers/net/wireless/ath/ath10k/mac.c

index 4b5239de401840b628bb776ef2f585edb31f310e..ba9795a8378afd1899273e71402cdfda2b156c13 100644 (file)
@@ -607,7 +607,7 @@ struct ath10k_vif {
                        u8 tim_bitmap[64];
                        u8 tim_len;
                        u32 ssid_len;
-                       u8 ssid[IEEE80211_MAX_SSID_LEN];
+                       u8 ssid[IEEE80211_MAX_SSID_LEN] __nonstring;
                        bool hidden_ssid;
                        /* P2P_IE with NoA attribute for P2P_GO case */
                        u32 noa_len;
index 2cf693f3fea96e10fca84996d35d7b1a1bad2245..e18427f724921550f7c80d9547cea5a8ecb51249 100644 (file)
@@ -6121,9 +6121,8 @@ static void ath10k_bss_info_changed(struct ieee80211_hw *hw,
 
                if (ieee80211_vif_is_mesh(vif)) {
                        /* mesh doesn't use SSID but firmware needs it */
-                       strncpy(arvif->u.ap.ssid, "mesh",
-                               sizeof(arvif->u.ap.ssid));
                        arvif->u.ap.ssid_len = 4;
+                       memcpy(arvif->u.ap.ssid, "mesh", arvif->u.ap.ssid_len);
                }
        }