From patchwork Thu Oct 5 01:29:45 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Justin Stitt X-Patchwork-Id: 13409701 Received: from lindbergh.monkeyblade.net (lindbergh.monkeyblade.net [23.128.96.19]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id D997C1112 for ; Thu, 5 Oct 2023 01:29:47 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="mk4Ts3hk" 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 7CE1EC1 for ; Wed, 4 Oct 2023 18:29:46 -0700 (PDT) Received: by mail-yw1-x1149.google.com with SMTP id 00721157ae682-5a234ffeb90so6176317b3.3 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=lpM4830yaILx94a9P5RzXdzHHeFrQJdDAWusv9CncnhtutwizvMmIw9MR5Dg+6GpOW 9pUHKjSQLmkNG44/SmgnclHmaiUdEywRK7ALauGUADhuydYlE+N06kFZy8AeuxIDG7+T cslxLcV2FOuQxO4TDKQL+1hYnz65Uv0YWrqfT3Mci6qEQscSkHWrOJSCXRSgWtKuOzPW VT33aZ4psxMx5Tw9kZhMIDY1Aiz6hIJoBURMyBHuAtBuNBJ6UJeU9h5nX74c7NXyQtmd dqETmI10GdWEgrIUm7kX+RE11JPFclKMd12J/qpuCDzcaTlGZCH/B3Hh27Fa0LfjkP6m qqfA== X-Gm-Message-State: AOJu0YxSTRcK7V/uBIWp5u9ym+GqYQkx89cTemmDEBTlaZwiXLDYe9Zs MlHChLwHA8FuxlRRWVeV7qts7wWZrorTvXc4GA== X-Google-Smtp-Source: AGHT+IHGlUdBnRQgAUkJbTUD5bhZpKVCzmIJHzuIezZEtvNkFHMjMTUnquqEGw5iJVx3Upqhvllv2Qm2UrKMLjL1QQ== 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 Precedence: bulk X-Mailing-List: linux-hardening@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: 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 X-Spam-Status: No, score=-9.6 required=5.0 tests=BAYES_00,DKIMWL_WL_MED, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF, RCVD_IN_DNSWL_BLOCKED,SPF_HELO_NONE,SPF_PASS,USER_IN_DEF_DKIM_WL autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net `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 Reviewed-by: Kees Cook --- Note: build-tested only. --- drivers/net/ethernet/atheros/atlx/atl2.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) --- base-commit: cbf3a2cb156a2c911d8f38d8247814b4c07f49a2 change-id: 20231005-strncpy-drivers-net-ethernet-atheros-atlx-atl2-c-d876945d6341 Best regards, -- Justin Stitt 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;