Received: by 2002:a05:7412:518d:b0:e2:908c:2ebd with SMTP id fn13csp15011rdb; Wed, 4 Oct 2023 18:30:02 -0700 (PDT) X-Google-Smtp-Source: AGHT+IHo3E4Ek4mllSm7ypC/Th+5kbiV4TdTr4q2tXV8sV65+hNcA+ejIjNh/xSzvIhL/VRDCKA1 X-Received: by 2002:a17:90b:4a07:b0:279:7963:cdf2 with SMTP id kk7-20020a17090b4a0700b002797963cdf2mr3701111pjb.0.1696469402052; Wed, 04 Oct 2023 18:30:02 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1696469402; cv=none; d=google.com; s=arc-20160816; b=BAVhFaz9Tzec1zVs23ExSoI7CAVD88NjFlserGnHhAVqMt5HwteDytGuPdk7tzQmXF 1xRXtYlmMYc/DHMICb50ZWeq1GwNALO6M/4/g8ROvjcSnnE8soIl1XONLAOWSuBPcUK4 qFUTzmvrPtLEdBHFCPO2WTzVr8mXMQcqWc5MuuH/mMARJ6n9dXaXR8zxQkuHcEm+cE3J hSTpLuYJwDeOoB4KmIM/UzHcorBP08PTeC6PLB3EOqSW4+6qzjKbqZBZaX66Ysxs7hKc WOtwNGq8XL6mXSV7/QGhhYaOXXggt+qiyNGPTVDFl6zbn7wm4EgU57+z5kYC/kWW5Ivj RVFg== 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=seOtURC6fBxwejJy6k6WWhSAcd7bSEPQZUE94/fyJ08=; fh=85daWdZuPQnMvkrLEuRZ1faaC9chevC8TXDuGimeveg=; b=O/bMstCCdz6N+ddasaMqFOXPxR5tRSVGFxRUyRRWSgCTay1zDCnzlch3KRCeiBAXLh KdsZzqs960VFh+Rz0vdQdFzEdk3MwlcyxpBxM67Z2f/ySDsDuFU6JY0PBM48tN3ng+3t Dqqj9s0yVSSEJdOhjK8tOZsdgeHGuDFFeJBztCAu8Sx6SFCIbXJfrECYNQt9Uphm8xGk kckEYb5gC3MB0XI1z/UrviFQB2DsXBKnIDL6E0DPkQHcJV/i7UMBQvMI0cr49nJs/JCb 8l4AHH07oDZUbGfja0l1ASWuQkou30GKhNVf+3brkEjOyJNx7Yy4Sb0rQqkhFKlH7fMk Qnlw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20230601 header.b=mk4Ts3hk; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.35 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Return-Path: Received: from groat.vger.email (groat.vger.email. [23.128.96.35]) by mx.google.com with ESMTPS id lx2-20020a17090b4b0200b0026b74f6aaa8si2899638pjb.63.2023.10.04.18.30.00 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 04 Oct 2023 18:30:02 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.35 as permitted sender) client-ip=23.128.96.35; Authentication-Results: mx.google.com; dkim=pass header.i=@google.com header.s=20230601 header.b=mk4Ts3hk; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.35 as permitted sender) smtp.mailfrom=linux-kernel-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 groat.vger.email (Postfix) with ESMTP id 5291E8315497; Wed, 4 Oct 2023 18:29:58 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at groat.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S244261AbjJEB3v (ORCPT + 99 others); Wed, 4 Oct 2023 21:29:51 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:51212 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231650AbjJEB3u (ORCPT ); Wed, 4 Oct 2023 21:29:50 -0400 Received: from mail-yw1-x1149.google.com (mail-yw1-x1149.google.com [IPv6:2607:f8b0:4864:20::1149]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 83E52C6 for ; Wed, 4 Oct 2023 18:29:46 -0700 (PDT) Received: by mail-yw1-x1149.google.com with SMTP id 00721157ae682-59f7d109926so6221447b3.2 for ; Wed, 04 Oct 2023 18:29:46 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1696469385; x=1697074185; darn=vger.kernel.org; h=cc:to:from:subject:message-id:mime-version:date:from:to:cc:subject :date:message-id:reply-to; bh=seOtURC6fBxwejJy6k6WWhSAcd7bSEPQZUE94/fyJ08=; b=mk4Ts3hk9+gNSaj9j1fALfv2XOxIpoXKA1wjNfttziQRjOwmpee+SLP/tE9bmk5S1m 70hR7OtsylHTPeJDRP0JASE0VtKMvsFYthfslrdRwIwk2F23AOJP94yPGF5zgyUNcGs2 eOQRt5JJSO9GL41t5pAABACAL0XHeFyxWGTLgFz0JRX7IA7zJmDED1PwP8u74OutNHus 0c1JqhIyrfty29Sjy7194BvaBnkOlnmxeyRaoPPeKesDVbsOEgWtGezbp3Rlg4ti7lDD Ivpn70uEJxUsLg4FDoB1sG3wvNvtbyEUjphfTGHjQcPU6u3/4b23m0GotFSO+cXnFp2+ bSJw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1696469385; x=1697074185; h=cc:to:from:subject:message-id:mime-version:date:x-gm-message-state :from:to:cc:subject:date:message-id:reply-to; bh=seOtURC6fBxwejJy6k6WWhSAcd7bSEPQZUE94/fyJ08=; b=ipbRSOTyHzUZyA3mk4J4M8bGUItZz9LtupdsRI7osDtFir0B6OcXFgpyI0x5PK0hUr lUTcfFyHfFu/YJQhfJh6/Ijidq+/h5c16vo8WXznZ7eE+iYpdAfPaK21OYWTP2YehLRW H+j5GRMEw5iRdVMGRybL3DbkVh/GF4LKF6wUqzuNukNLKEcflxdoqwxD95+cnBkEcoc+ wZDElmnVMmco8MFBMBpoaSgUOC59G5mdH4wsgmWnTQ2biz9uuvPop84Fc6339IU4ZZ+n ntqWONtR2gjPobMqfUrxLytJS8jWV1W11MBNBaiClDGsSSNr4yrBAB1VZpFMYPf4gH2k zPOA== X-Gm-Message-State: AOJu0Yw+8PE+jZVqrRMrnTiCwFzRYG9l2fVvH3CQ902Y7M71YKhQPdiG Ob2ffyVBY8CzBySylOF+mflsY39OaLG3FNTVaw== X-Received: from jstitt-linux1.c.googlers.com ([fda3:e722:ac3:cc00:2b:ff92:c0a8:23b5]) (user=justinstitt job=sendgmr) by 2002:a25:d42:0:b0:d7f:8e0a:4b3f with SMTP id 63-20020a250d42000000b00d7f8e0a4b3fmr58588ybn.3.1696469385723; Wed, 04 Oct 2023 18:29:45 -0700 (PDT) Date: Thu, 05 Oct 2023 01:29:45 +0000 Mime-Version: 1.0 X-B4-Tracking: v=1; b=H4sIAIgRHmUC/x2NzQqDMBCEX0X23IUk/rV9FfEgybYuSJTdIIr47 k16mfm+y8wFSsKk8K4uENpZeY1Z7KMCP0/xS8ghOzjjamtMi5ok+u3EILyTKEZKSGkmKTAVWDX 3cpRw6DE8++7VtKGrGwt5dhP68PG/HMb7/gGZNBCkggAAAA== X-Developer-Key: i=justinstitt@google.com; a=ed25519; pk=tC3hNkJQTpNX/gLKxTNQKDmiQl6QjBNCGKJINqAdJsE= X-Developer-Signature: v=1; a=ed25519-sha256; t=1696469384; l=2106; i=justinstitt@google.com; s=20230717; h=from:subject:message-id; bh=X2VGMiD2VyU3UNmwOeb3Zcy55vlwL+eXR2GtGCju9sw=; b=Na69FtdFYr6hWbOU/LN2ileJHX4Vn+VWR5fpviGG/UesKWcaHIRD05Hj/H0r1oeNn8TTEdQYY 5SCvfX7QZAGB2eaD8GVNAjSMnK+zuim5ZrxZ1T4ZtpSiUZXLb5qHBAr X-Mailer: b4 0.12.3 Message-ID: <20231005-strncpy-drivers-net-ethernet-atheros-atlx-atl2-c-v1-1-493f113ebfc7@google.com> Subject: [PATCH] net: atheros: replace deprecated strncpy with strscpy From: Justin Stitt To: Chris Snook , "David S. Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni Cc: netdev@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=-4.8 required=5.0 tests=DKIMWL_WL_MED,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,RCVD_IN_SBL_CSS,SPF_HELO_NONE,SPF_PASS, USER_IN_DEF_DKIM_WL autolearn=no autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on groat.vger.email Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (groat.vger.email [0.0.0.0]); Wed, 04 Oct 2023 18:29:58 -0700 (PDT) `strncpy` is deprecated for use on NUL-terminated destination strings [1] and as such we should prefer more robust and less ambiguous string interfaces. We expect netdev->name to be NUL-terminated based on its use with format strings and dev_info(): | dev_info(&adapter->pdev->dev, | "%s link is up %d Mbps %s\n", | netdev->name, adapter->link_speed, | adapter->link_duplex == FULL_DUPLEX ? | "full duplex" : "half duplex"); Furthermore, NUL-padding is not required as netdev is already zero-initialized through alloc_etherdev(). Considering the above, a suitable replacement is `strscpy` [2] due to the fact that it guarantees NUL-termination on the destination buffer without unnecessarily NUL-padding. Link: https://www.kernel.org/doc/html/latest/process/deprecated.html#strncpy-on-nul-terminated-strings [1] Link: https://manpages.debian.org/testing/linux-manual-4.8/strscpy.9.en.html [2] Link: https://github.com/KSPP/linux/issues/90 Cc: linux-hardening@vger.kernel.org Signed-off-by: Justin Stitt --- Note: build-tested only. --- drivers/net/ethernet/atheros/atlx/atl2.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/drivers/net/ethernet/atheros/atlx/atl2.c b/drivers/net/ethernet/atheros/atlx/atl2.c index 1b487c071cb6..bcfc9488125b 100644 --- a/drivers/net/ethernet/atheros/atlx/atl2.c +++ b/drivers/net/ethernet/atheros/atlx/atl2.c @@ -1377,7 +1377,7 @@ static int atl2_probe(struct pci_dev *pdev, const struct pci_device_id *ent) netdev->watchdog_timeo = 5 * HZ; netdev->min_mtu = 40; netdev->max_mtu = ETH_DATA_LEN + VLAN_HLEN; - strncpy(netdev->name, pci_name(pdev), sizeof(netdev->name) - 1); + strscpy(netdev->name, pci_name(pdev), sizeof(netdev->name)); netdev->mem_start = mmio_start; netdev->mem_end = mmio_start + mmio_len; --- base-commit: cbf3a2cb156a2c911d8f38d8247814b4c07f49a2 change-id: 20231005-strncpy-drivers-net-ethernet-atheros-atlx-atl2-c-d876945d6341 Best regards, -- Justin Stitt