Received: by 2002:a05:7412:251c:b0:e2:908c:2ebd with SMTP id w28csp2049233rda; Tue, 24 Oct 2023 10:42:28 -0700 (PDT) X-Google-Smtp-Source: AGHT+IGWzjXK8BtVDZLcf0RjnzkewQP9LGhZZAnxCAnd9bVUcu5/bk9gsyHDHINtpsggcz74h9cG X-Received: by 2002:a17:902:e311:b0:1ca:4ad7:6878 with SMTP id q17-20020a170902e31100b001ca4ad76878mr9458245plc.8.1698169348656; Tue, 24 Oct 2023 10:42:28 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1698169348; cv=none; d=google.com; s=arc-20160816; b=atRobMAT5xUiHr7hJ4IaG1g6jMYbeCiZUdvt0FNPJ0r+DPrSHLRK9oqUs80zKFhGFi 18GFpp4a2gBLXMXmwDroABJdT8fYGvJ9I8MlTv4JzaERIob23ue9CerSzqn/8c1BQfRX Y7VjXvgasEbqOYAylQCZ3HbkWsP3RQXRYiHJfxKQkwcnSBPu/Y/UMyH77zsIAfWucqZf lxZkDSFhEO44S6lhhgnGDfkX22e/KLHQb6BQOKB+yAiP1hFSz8pM8yU3yY51bjD8xJBW iaHmqRnhnBvSSgFMQ8jADoNQ/rcpacnNc5W9QqU60oXvPosCNk5hdscyHTX1AIcpzJ8J LpAw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:cc:to:from:subject:message-id:mime-version:date :dkim-signature; bh=IiUyQYP0TuoT75NL7ZUXuVLk1dlI1JfFc9pMS1xuxEY=; fh=PioQG4/XMIEUsRALhg6vVwlM6RQLJN9AQXGiXGQHe/o=; b=UkJCLdjzgoIcBac743E2mM9DXKFhVG5tiaOcPi8OeaAvRStq8WX1P9WFieRd3LzGqY sZv3aRiYSehRttYwMeJXxO335+8vuXuRSCY3aH7Q2Q9g4/LxECeQ+aUMTWbkX65o51nk f1qV4dMzr/HhrHTkcs+mJewdMoVlxKwS4dJCT3Vxj+Xm8f5HBbSXR3DjD4GlzAAEVF9a nm0RLUufWmofWn8dcGZS8d/kHjmuQbP5uUZ5OFDd89h3y9cTzI3w0fzXGxuqtiEYWEpA POK6wM4zWQ32DoQLDSSR/29U8o95XfhCJHiumXDZRQaO78Ae7x0BbAOQzAT3EKfi9mAh FXXA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20230601 header.b=t2S8tvDU; spf=pass (google.com: domain of linux-wireless-owner@vger.kernel.org designates 23.128.96.33 as permitted sender) smtp.mailfrom=linux-wireless-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Return-Path: Received: from lipwig.vger.email (lipwig.vger.email. [23.128.96.33]) by mx.google.com with ESMTPS id ij26-20020a170902ab5a00b001c9cc838d72si8343254plb.125.2023.10.24.10.42.27 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 24 Oct 2023 10:42:28 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-wireless-owner@vger.kernel.org designates 23.128.96.33 as permitted sender) client-ip=23.128.96.33; Authentication-Results: mx.google.com; dkim=pass header.i=@google.com header.s=20230601 header.b=t2S8tvDU; spf=pass (google.com: domain of linux-wireless-owner@vger.kernel.org designates 23.128.96.33 as permitted sender) smtp.mailfrom=linux-wireless-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by lipwig.vger.email (Postfix) with ESMTP id 5069C80278CF; Tue, 24 Oct 2023 10:42:23 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at lipwig.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1344077AbjJXRmW (ORCPT + 52 others); Tue, 24 Oct 2023 13:42:22 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:33822 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1343855AbjJXRmV (ORCPT ); Tue, 24 Oct 2023 13:42:21 -0400 Received: from mail-yb1-xb4a.google.com (mail-yb1-xb4a.google.com [IPv6:2607:f8b0:4864:20::b4a]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id B5D0D10CC for ; Tue, 24 Oct 2023 10:42:18 -0700 (PDT) Received: by mail-yb1-xb4a.google.com with SMTP id 3f1490d57ef6-da04fb79246so753739276.2 for ; Tue, 24 Oct 2023 10:42:18 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1698169338; x=1698774138; darn=vger.kernel.org; h=cc:to:from:subject:message-id:mime-version:date:from:to:cc:subject :date:message-id:reply-to; bh=IiUyQYP0TuoT75NL7ZUXuVLk1dlI1JfFc9pMS1xuxEY=; b=t2S8tvDUUejCeZ24leQtjT9hpGKC3oyQqn2VVxA/2T9M++timZ+6N76fw7Mx9if+cw dhP18KcJiRHPNp1rn6pKvLSrv2l305m8UVej+yFIM7n73RUUTgfB4TXudIekTsUhDBVP h5yEdUS7ybCGUQHb4TFRMwmUcDB5/s0jGjK+76OMfBXIeg2lwScjbQkkGtHCCfqOJ9YM mWNcsE/PLgsxu59DVatz/ox8YiQsn36/nKAFcpclC0g7+f35iZW4KUO6zPVTKXDxGs6L llHmekKdTAoi+fWQrCRloWSepECx3zPJz9fb/k6GxjMY5NimB1yxY3EWORWKyd+vmfTJ 8+jg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1698169338; x=1698774138; h=cc:to:from:subject:message-id:mime-version:date:x-gm-message-state :from:to:cc:subject:date:message-id:reply-to; bh=IiUyQYP0TuoT75NL7ZUXuVLk1dlI1JfFc9pMS1xuxEY=; b=S052WrKfU9HlA/ZLxX0thb0Y5br1tJkxPxAgaR4u8EFJtRUG+yinb8Hq9yvZD6RoWX N/8CQFPUfoJpBd4OSMDBx1RJXALXoY7MSbx8NLSQjNqm1pC5dgYQNBozDngGhAWOnGn0 IkTCkMqAmIkanlXV7nKZ9rY5TtZaGZETiQjB/GVvhWntFzrm6Mcujbc+2U//3uMEDqt9 XQ4aGnqtgnZUUDMdDAZxDWDwU8FtMOfxNpfph2pWsX7Sb+hJjB13SP1yz0rnw9waetou lo6B1X+iT+NnrLjH9kyx5pgDUKfkfyexZDkPwZ+taGSRuk6/Jesv2j4iiSyYUh4L6/Vz nOkA== X-Gm-Message-State: AOJu0Yw9784uNpjPZhVPEK3Asa7HJ5EswFlQNMwC7o20HFI8P3Hfktfh Z0kMbRQ2KB4uhL8x/aChWqd7xkdwhm06imsPlA== X-Received: from jstitt-linux1.c.googlers.com ([fda3:e722:ac3:cc00:2b:ff92:c0a8:23b5]) (user=justinstitt job=sendgmr) by 2002:a05:6902:1083:b0:d9a:c3b8:4274 with SMTP id v3-20020a056902108300b00d9ac3b84274mr332751ybu.7.1698169337984; Tue, 24 Oct 2023 10:42:17 -0700 (PDT) Date: Tue, 24 Oct 2023 17:42:16 +0000 Mime-Version: 1.0 X-B4-Tracking: v=1; b=H4sIAPcBOGUC/52NTQqDMBCFryJZd0p+NIWueo/iIsRRQ9WUmZBWx Ls3eoTyeIvvLd63CUYKyOJebYIwBw5xKaAvlfCjWwaE0BUWWmqjpDLAiRb/XqGjkJEYFkzwCYQ TMoNL41ElXzA7DyU345rGWovWifL5JuzD9/Q928Jj4BRpPfVZHeu/pqxAga6xlloq1zvzGGIcJ rz6OIt23/cfmGU7pusAAAA= X-Developer-Key: i=justinstitt@google.com; a=ed25519; pk=tC3hNkJQTpNX/gLKxTNQKDmiQl6QjBNCGKJINqAdJsE= X-Developer-Signature: v=1; a=ed25519-sha256; t=1698169336; l=2664; i=justinstitt@google.com; s=20230717; h=from:subject:message-id; bh=v7X6AgaYGtLwlN3x1yqa0dzr/NEuarCPk3n9BpO0sN0=; b=t/Ub/yzQiuI1fBkkvEt7r+RmgkE6N5jCyDcKYYtcuRX0JU7I4tPXvRrsG8ukYhxbLdofgXYK5 fRSaupgp7LWCw9dftF9BYantl62Zrfybz6X6RRUqMFlL8hHOmRxfTbl X-Mailer: b4 0.12.3 Message-ID: <20231024-strncpy-drivers-net-wireless-ath-ath10k-mac-c-v2-1-4c1f4cd4b4df@google.com> Subject: [PATCH v2] wifi: ath10k: replace deprecated strncpy with memcpy From: Justin Stitt To: Kalle Valo , Jeff Johnson Cc: ath10k@lists.infradead.org, linux-wireless@vger.kernel.org, linux-kernel@vger.kernel.org, linux-hardening@vger.kernel.org, Justin Stitt Content-Type: text/plain; charset="utf-8" X-Spam-Status: No, score=-8.4 required=5.0 tests=DKIMWL_WL_MED,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,USER_IN_DEF_DKIM_WL autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lipwig.vger.email Precedence: bulk List-ID: X-Mailing-List: linux-wireless@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (lipwig.vger.email [0.0.0.0]); Tue, 24 Oct 2023 10:42:23 -0700 (PDT) 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 [1] Link: https://github.com/KSPP/linux/issues/90 Cc: linux-hardening@vger.kernel.org Signed-off-by: Justin Stitt --- Changes in v2: - update subject to include wifi - prefer memcpy() over strtomem() (thanks Kalle, Jeff) - rebase onto 6.6-rc7 @d88520ad73b79e71 - Link to v1: https://lore.kernel.org/r/20231013-strncpy-drivers-net-wireless-ath-ath10k-mac-c-v1-1-24e40201afa3@google.com --- Note: build-tested only. Found with: $ rg "strncpy\(" --- drivers/net/wireless/ath/ath10k/core.h | 2 +- drivers/net/wireless/ath/ath10k/mac.c | 3 +-- 2 files changed, 2 insertions(+), 3 deletions(-) diff --git a/drivers/net/wireless/ath/ath10k/core.h b/drivers/net/wireless/ath/ath10k/core.h index 4b5239de4018..ba9795a8378a 100644 --- a/drivers/net/wireless/ath/ath10k/core.h +++ b/drivers/net/wireless/ath/ath10k/core.h @@ -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; diff --git a/drivers/net/wireless/ath/ath10k/mac.c b/drivers/net/wireless/ath/ath10k/mac.c index 03e7bc5b6c0b..f3f6deb354c6 100644 --- a/drivers/net/wireless/ath/ath10k/mac.c +++ b/drivers/net/wireless/ath/ath10k/mac.c @@ -6125,9 +6125,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); } } --- base-commit: d88520ad73b79e71e3ddf08de335b8520ae41c5c change-id: 20231013-strncpy-drivers-net-wireless-ath-ath10k-mac-c-c73a55666e6a Best regards, -- Justin Stitt