Received: by 2002:a05:7412:d8a:b0:e2:908c:2ebd with SMTP id b10csp1205016rdg; Fri, 13 Oct 2023 13:34:10 -0700 (PDT) X-Google-Smtp-Source: AGHT+IGh/2eM/H/zndcq2E6TXMkCLlmkG1xZVeqhLD8VFqv5+ArebmdLcyI6FQSd+M6GWdCcVq8h X-Received: by 2002:a05:6808:1059:b0:3ae:1888:16db with SMTP id c25-20020a056808105900b003ae188816dbmr23279668oih.56.1697229250031; Fri, 13 Oct 2023 13:34:10 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1697229249; cv=none; d=google.com; s=arc-20160816; b=As9MACecvjxIUU3QWJ4WQF5/YvqZRgCaTpzo5EzD6CdZswd50XUfq5CcU+AgpQRLqX SyRdW5AYBiGZNOBuPsdChxbOL61+kwjA+0+qYiWZ5yWRB+1F7ayaOdYdOZu+bg6EJD/b CXdOXhCe0R3nQSwUG8QN/O5VBdcHHDnRP5o0QR3/3aEZdHt64hsB1MtCN0IKWcffBU+Y JxXdslu4SuIfBPhH26N886TWjo1R7YLtKlKzYFol4VfiQFFvDihEHNb74m96NeXtsPDJ ZoN+8fWjajdCnPq+Qt9QcTQEHuCEWBsXc3n6McglC+LJdZTaJff6HoJgIFeQRa6daMib GBFQ== 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=eG6A8LXGdf5DishXidGUjCut3MBs3ddn444r7C+ElXE=; fh=PioQG4/XMIEUsRALhg6vVwlM6RQLJN9AQXGiXGQHe/o=; b=S3gZPEbbYZtx3hzlEgDCVphIPwghj0WGvY64emeHUPBIfoulKgvqRLrtqptJvJvvyo T5V+bTvcFjS3Cb+wSOp48r0ns9zd/WPLpqJugZqJYdHsVa6OSn9r5cp/rbMR+yXh/QaB Zs8i1yxDujGWSr/ARro58zcjzn6P80o+wnwgERMbDRopGFdpAchS3v4BuxZSuogVA9a7 nc3nCgbNx1sGFGDzdGpkRAnltL9+849+gFZ/Nd2aPPe8ICzDZnszkF4n9SlIqBNwD3rU z5I3vQ0Intj1EF4SOtDeSIHb8gQa5W7rO7JUXgn4gooq0UI90Vog9Tl7mh2XzmMc1a7H yhvQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20230601 header.b=2GLPtszD; spf=pass (google.com: domain of linux-wireless-owner@vger.kernel.org designates 2620:137:e000::3:4 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 howler.vger.email (howler.vger.email. [2620:137:e000::3:4]) by mx.google.com with ESMTPS id o9-20020a656a49000000b005aa0e024d5esi3008227pgu.656.2023.10.13.13.34.09 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 13 Oct 2023 13:34:09 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-wireless-owner@vger.kernel.org designates 2620:137:e000::3:4 as permitted sender) client-ip=2620:137:e000::3:4; Authentication-Results: mx.google.com; dkim=pass header.i=@google.com header.s=20230601 header.b=2GLPtszD; spf=pass (google.com: domain of linux-wireless-owner@vger.kernel.org designates 2620:137:e000::3:4 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 howler.vger.email (Postfix) with ESMTP id 05F6B8073296; Fri, 13 Oct 2023 13:34:06 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at howler.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232119AbjJMUdw (ORCPT + 51 others); Fri, 13 Oct 2023 16:33:52 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:38616 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231814AbjJMUdv (ORCPT ); Fri, 13 Oct 2023 16:33:51 -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 6B461BB for ; Fri, 13 Oct 2023 13:33:49 -0700 (PDT) Received: by mail-yb1-xb4a.google.com with SMTP id 3f1490d57ef6-d918aef0d0dso3593142276.3 for ; Fri, 13 Oct 2023 13:33:49 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1697229228; x=1697834028; darn=vger.kernel.org; h=cc:to:from:subject:message-id:mime-version:date:from:to:cc:subject :date:message-id:reply-to; bh=eG6A8LXGdf5DishXidGUjCut3MBs3ddn444r7C+ElXE=; b=2GLPtszDPum7mvEFFd7ZG16lA3MmeTdMHTlFft9GmpFMwSsT9ZZKIfhGdlCfmHi2FX ZjuZMfsxXLbPvhhi9NdsObNaE1pZl3cT2P3AACBXiPkjpHetoMx+yFIlOBfPq0rHmE6m Q0bEOF9BoBUd4FAmDDRMlCIMmHn93EOhLLtbGVCIlJbTXnOpPFNOX+wWDSXZD2xMsZbt gsa7AgLr/5atERjPTKUu+h1H4OB6LMzbK19DxVYEST6XziN3W2B36hLiSY/N83IIXsYp eS6l0gdaGQtgaooXyrDGtquM0gA2prIzokC3X/Xu7upj5Q96JW1+ZiHNPIs8Hol87akv 4exw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1697229228; x=1697834028; h=cc:to:from:subject:message-id:mime-version:date:x-gm-message-state :from:to:cc:subject:date:message-id:reply-to; bh=eG6A8LXGdf5DishXidGUjCut3MBs3ddn444r7C+ElXE=; b=S0DrLxKMd0Np1ssYIl8ww3o1Z2zQT8VKw1LSWnPF2uhxA7s3zNwNi36GVymE2AiPvS XXo4A6H2M4hzc8L8inJBhUtZaQmGTWdDsLVSCVkoCVt3MgdchnZG2WDIzg6gfgkUXTH4 CHbzrg5mGUFdU5a2Js3sbOe1KTa2CH0I3Aq1n67T76xKAqWZRKSEj4wliaexsxC3lmsj Y7sEs7WTkR6PtpLEUreBAvzQ/J1u5HSjSNtKdWrubViiXviiWWwgITcQAj183cqEgXs8 ng9q0Q0QsyeSsTlNeTGVLIHWaf4qxSScK1ctKQ5Ef3QwXCPz3q2io4B3OW6d64pZwXZm BNyA== X-Gm-Message-State: AOJu0YzyVef3Bwm495Gb+MCG7kPLzZy5gtGor3qOPMOeXytyb8zmxwO/ kNmob+mSwAbCQgNKoyl4h1XQYE/L11GS4SzGrg== X-Received: from jstitt-linux1.c.googlers.com ([fda3:e722:ac3:cc00:2b:ff92:c0a8:23b5]) (user=justinstitt job=sendgmr) by 2002:a25:5056:0:b0:d9a:3dac:6c1a with SMTP id e83-20020a255056000000b00d9a3dac6c1amr284177ybb.11.1697229228652; Fri, 13 Oct 2023 13:33:48 -0700 (PDT) Date: Fri, 13 Oct 2023 20:33:48 +0000 Mime-Version: 1.0 X-B4-Tracking: v=1; b=H4sIAKupKWUC/x2NQQrCMBBFr1Jm7UDS0AheRVyE9GsHNZaZ0Cqld zfK4y/e5r+NDCowOnUbKRYxeZUm/tBRnlK5gWVsTr3rg3c+sFUtef7wqLJAjQsqr6J4wIxTnX7 z7s7PlLlxDGkYYoyIidrnrLjK+987X/b9C0V4zo5/AAAA X-Developer-Key: i=justinstitt@google.com; a=ed25519; pk=tC3hNkJQTpNX/gLKxTNQKDmiQl6QjBNCGKJINqAdJsE= X-Developer-Signature: v=1; a=ed25519-sha256; t=1697229227; l=2804; i=justinstitt@google.com; s=20230717; h=from:subject:message-id; bh=bIMAUwS6tKmB9c3Rk81R/5V5UUFo1cBwPXaV7yFWMoA=; b=CMqSCYBAwjGQ8NqCJLEe3oWu/b2U+C4UYTWSlc/PUeeYHnfx5MQOccK4vtSKlHLLgk37gUzWa wuqPSkQzuGcBq8W/yBQzKG3d3WsDrMe0sr4hx8u6ZKodNLkDgwsgk/2 X-Mailer: b4 0.12.3 Message-ID: <20231013-strncpy-drivers-net-wireless-ath-ath10k-mac-c-v1-1-24e40201afa3@google.com> Subject: [PATCH] ath10k: replace deprecated strncpy with strtomem_pad 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 howler.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 (howler.vger.email [0.0.0.0]); Fri, 13 Oct 2023 13:34:06 -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, although by virtue of using strtomem_pad (with NUL-byte pad character) and having a destination size larger than the source, ssid will, incidentally, be NUL-terminated here. As strtomem_pad() docs say: * @dest: Pointer of destination character array (marked as __nonstring) * @src: Pointer to NUL-terminated string * @pad: Padding character to fill any remaining bytes of @dest after copy * * This is a replacement for strncpy() uses where the destination is not * a NUL-terminated string, but with bounds checking on the source size, and * an explicit padding character. If padding is not required, use strtomem(). Let's also mark ath10k_vif.u.ap.ssid as __nonstring. It is unclear to me whether padding is strictly necessary. Perhaps we should opt for just strtomem() -- padding certainly doesn't hurt, though. 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 --- 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..7daa007bd8b3 100644 --- a/drivers/net/wireless/ath/ath10k/mac.c +++ b/drivers/net/wireless/ath/ath10k/mac.c @@ -6125,8 +6125,7 @@ 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)); + strtomem_pad(arvif->u.ap.ssid, "mesh", '\0'); arvif->u.ap.ssid_len = 4; } } --- base-commit: cbf3a2cb156a2c911d8f38d8247814b4c07f49a2 change-id: 20231013-strncpy-drivers-net-wireless-ath-ath10k-mac-c-c73a55666e6a Best regards, -- Justin Stitt