From patchwork Tue Oct 10 22:26:54 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Justin Stitt X-Patchwork-Id: 1847751 X-Patchwork-Delegate: anthony.l.nguyen@intel.com Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=osuosl.org header.i=@osuosl.org header.a=rsa-sha256 header.s=default header.b=fQWn4/XA; dkim-atps=neutral Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=osuosl.org (client-ip=2605:bc80:3010::136; helo=smtp3.osuosl.org; envelope-from=intel-wired-lan-bounces@osuosl.org; receiver=patchwork.ozlabs.org) Received: from smtp3.osuosl.org (smtp3.osuosl.org [IPv6:2605:bc80:3010::136]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (secp384r1) server-digest SHA384) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4S5zfc2ngyz23jX for ; Fri, 13 Oct 2023 06:07:36 +1100 (AEDT) Received: from localhost (localhost [127.0.0.1]) by smtp3.osuosl.org (Postfix) with ESMTP id 895B26103B; Thu, 12 Oct 2023 19:07:34 +0000 (UTC) DKIM-Filter: OpenDKIM Filter v2.11.0 smtp3.osuosl.org 895B26103B DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=osuosl.org; s=default; t=1697137654; bh=3lNBKGJUSyc9tIvHi0pgaZqf71Hn/2o3dAcBeNjLKDc=; h=Date:In-Reply-To:References:From:To:Subject:List-Id: List-Unsubscribe:List-Archive:List-Post:List-Help:List-Subscribe: Cc:From; b=fQWn4/XArme2+jAE2EWDDDq3WOllyIM6nblPk9e78Bw4xTFUzvHLBig1haGtPlDck IfCFU3avj9gjCRjl75rMbNvldn++PksG4lWY7Y9ZB+5wOxvaODOVCV6YB1AzzVPwdM EjbYbR2iwnW3kHLrRg848OIIWgFobnZorMlCjCjR8p21nk+LGuaRxO/HDk2NjJWF76 hXuk+xlazfimqfXETy7xt+THD4/56mSpuCAXFeR6YFvSrZJ2hukgQ2OJfpMW7IBHX4 DIJxBoTTM2Lxe7QpdbCehKIHM+a+DqcJcnpm96uXch835AJZCKG0PtJTvjyaL9bseE 8EcSS8TN/m6eQ== X-Virus-Scanned: amavisd-new at osuosl.org Received: from smtp3.osuosl.org ([127.0.0.1]) by localhost (smtp3.osuosl.org [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id 5d0Xlf97LjcY; Thu, 12 Oct 2023 19:07:32 +0000 (UTC) Received: from ash.osuosl.org (ash.osuosl.org [140.211.166.34]) by smtp3.osuosl.org (Postfix) with ESMTP id B4461610A7; Thu, 12 Oct 2023 19:07:31 +0000 (UTC) DKIM-Filter: OpenDKIM Filter v2.11.0 smtp3.osuosl.org B4461610A7 X-Original-To: intel-wired-lan@lists.osuosl.org Delivered-To: intel-wired-lan@lists.osuosl.org Received: from smtp2.osuosl.org (smtp2.osuosl.org [140.211.166.133]) by ash.osuosl.org (Postfix) with ESMTP id 885951BF25F for ; Tue, 10 Oct 2023 22:27:09 +0000 (UTC) Received: from localhost (localhost [127.0.0.1]) by smtp2.osuosl.org (Postfix) with ESMTP id 61A0A4044D for ; Tue, 10 Oct 2023 22:27:09 +0000 (UTC) DKIM-Filter: OpenDKIM Filter v2.11.0 smtp2.osuosl.org 61A0A4044D X-Virus-Scanned: amavisd-new at osuosl.org Received: from smtp2.osuosl.org ([127.0.0.1]) by localhost (smtp2.osuosl.org [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id kHHb3i2E03tE for ; Tue, 10 Oct 2023 22:27:08 +0000 (UTC) Received: from mail-oo1-xc4a.google.com (mail-oo1-xc4a.google.com [IPv6:2607:f8b0:4864:20::c4a]) by smtp2.osuosl.org (Postfix) with ESMTPS id 1956D40012 for ; Tue, 10 Oct 2023 22:27:08 +0000 (UTC) DKIM-Filter: OpenDKIM Filter v2.11.0 smtp2.osuosl.org 1956D40012 Received: by mail-oo1-xc4a.google.com with SMTP id 006d021491bc7-57b78a20341so7466307eaf.0 for ; Tue, 10 Oct 2023 15:27:08 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1696976827; x=1697581627; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=oRxxfOpYGYsMYGCPD0LU0Gx9K2SMiFZ6T4X3/eq+2Jo=; b=Qupo9i4BT4Tsie/irslCz5Uo/DFS84ygsPLxZT3q4TQpecJpp1q2bzEdJzl3U9SQtZ Qk2DLaziw3eNupcZQhKMgaaWxeg3g2RaRcUlTvFh+yF0QFOPUGp1AV0JkuV2/tXrPRLN VFLcEasd8+75AHtsZOpokdpLH4h6W1s8iMZ6mm1OVsSlH20VOxBQ4uAzA1VpesRf7L3a LgIwWQLJ7KqTOfNngCroxwahpTY3rQJicJlmR7SAp6J9jyFOk99A2/Xol/8mM2A1e/6I mQK5iQpMYe7ShbrfHr6+ovUHnAOC3+/rMNdtE5nnIWjikvs7+8mUi2cvGWV4SZp+vOtK xSEQ== X-Gm-Message-State: AOJu0YwseG31QZvkZTEdAmREbHY8+uFAJVr2WtOgqbYLaxREPnx+DoQX 7SgF/PEsAzS+XinFOwPBLQtCn1RKG4Gcjv/lww== X-Google-Smtp-Source: AGHT+IF7Z0F3Kme/HBMNT7IsdnfUyQ7lDRY4xVZb2ZtGQ3g2V9x0IBedcSSdWdeMcYlxHd4de/rHK0jPUa+aQGw4QA== X-Received: from jstitt-linux1.c.googlers.com ([fda3:e722:ac3:cc00:2b:ff92:c0a8:23b5]) (user=justinstitt job=sendgmr) by 2002:a05:6870:9891:b0:1d6:5e45:3bc7 with SMTP id eg17-20020a056870989100b001d65e453bc7mr8002308oab.5.1696976826877; Tue, 10 Oct 2023 15:27:06 -0700 (PDT) Date: Tue, 10 Oct 2023 22:26:54 +0000 In-Reply-To: <20231010-netdev-replace-strncpy-resend-as-series-v1-0-caf9f0f2f021@google.com> Mime-Version: 1.0 References: <20231010-netdev-replace-strncpy-resend-as-series-v1-0-caf9f0f2f021@google.com> X-Developer-Key: i=justinstitt@google.com; a=ed25519; pk=tC3hNkJQTpNX/gLKxTNQKDmiQl6QjBNCGKJINqAdJsE= X-Developer-Signature: v=1; a=ed25519-sha256; t=1696976824; l=2047; i=justinstitt@google.com; s=20230717; h=from:subject:message-id; bh=OWWhQIBafVgfDlqmMd0xlq6kW1ggHRaXB3P7V35piho=; b=VuwZhA1UAIYHpGKXaFjSv1uwbivUM+rFKhtVdtifrMMZE3YsgHH/o4bhCiH0jMRbuplw/zZ5l Sq50xVfC9K1BbFHqYK+Q9zMPrzpmcn1bglNfo7vqJwP60dNdZLWRsiu X-Mailer: b4 0.12.3 Message-ID: <20231010-netdev-replace-strncpy-resend-as-series-v1-1-caf9f0f2f021@google.com> From: Justin Stitt To: Jesse Brandeburg , Tony Nguyen , "David S. Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni X-Mailman-Approved-At: Thu, 12 Oct 2023 19:06:39 +0000 X-Mailman-Original-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1696976827; x=1697581627; darn=lists.osuosl.org; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:from:to:cc:subject:date:message-id:reply-to; bh=oRxxfOpYGYsMYGCPD0LU0Gx9K2SMiFZ6T4X3/eq+2Jo=; b=JhNm2rTTSpaNv0e1z9g9MFpwSK2b49Skm5DDHEEsk5ngkLPL2ZiRTKKsy2rz4jIN+q yVP8XAH6/mpdKgnDWVJjiskUqXI4esxxYQUx76Im5U43uxuYuc76ByRPyZEoW8Ii3nzs bxI/X7/xcPFtorNPjFKfb674KyHBVgJD9vO+Tk7aTSVgX8CrkfK5BsK7ZsQs4kv+zGPp zPiZYQICem5NdUhTGkCp2vU7HxCL1uLLeO+84pxd15Fmg6F+ifm1lu5/j9O6sZXHHu7a 5BofUiQEot5RbYv8z36WMjziFBVWVyJgTp1w/xw/CBt/Jffzxim0aOk36Ho7aIhmN2Vn 8/KA== X-Mailman-Original-Authentication-Results: smtp2.osuosl.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.a=rsa-sha256 header.s=20230601 header.b=JhNm2rTT Subject: [Intel-wired-lan] [PATCH v1 net-next 1/7] e100: replace deprecated strncpy with strscpy X-BeenThere: intel-wired-lan@osuosl.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Intel Wired Ethernet Linux Kernel Driver Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: netdev@vger.kernel.org, Justin Stitt , intel-wired-lan@lists.osuosl.org, linux-hardening@vger.kernel.org, linux-kernel@vger.kernel.org Errors-To: intel-wired-lan-bounces@osuosl.org Sender: "Intel-wired-lan" `strncpy` is deprecated for use on NUL-terminated destination strings [1] and as such we should prefer more robust and less ambiguous string interfaces. The "...-1" pattern makes it evident that netdev->name is expected to be NUL-terminated. Meanwhile, it seems NUL-padding is not required due to alloc_etherdev zero-allocating the buffer. 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. This is in line with other uses of strscpy on netdev->name: $ rg "strscpy\(netdev\->name.*pci.*" drivers/net/ethernet/intel/e1000e/netdev.c 7455: strscpy(netdev->name, pci_name(pdev), sizeof(netdev->name)); drivers/net/ethernet/intel/ixgbe/ixgbe_main.c 10839: strscpy(netdev->name, pci_name(pdev), sizeof(netdev->name)); 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/intel/e100.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/drivers/net/ethernet/intel/e100.c b/drivers/net/ethernet/intel/e100.c index d3fdc290937f..01f0f12035ca 100644 --- a/drivers/net/ethernet/intel/e100.c +++ b/drivers/net/ethernet/intel/e100.c @@ -2841,7 +2841,7 @@ static int e100_probe(struct pci_dev *pdev, const struct pci_device_id *ent) netdev->netdev_ops = &e100_netdev_ops; netdev->ethtool_ops = &e100_ethtool_ops; netdev->watchdog_timeo = E100_WATCHDOG_PERIOD; - strncpy(netdev->name, pci_name(pdev), sizeof(netdev->name) - 1); + strscpy(netdev->name, pci_name(pdev), sizeof(netdev->name)); nic = netdev_priv(netdev); netif_napi_add_weight(netdev, &nic->napi, e100_poll, E100_NAPI_WEIGHT); From patchwork Tue Oct 10 22:26:55 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Justin Stitt X-Patchwork-Id: 1847752 X-Patchwork-Delegate: anthony.l.nguyen@intel.com Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=osuosl.org header.i=@osuosl.org header.a=rsa-sha256 header.s=default header.b=pmGExFN8; dkim-atps=neutral Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=osuosl.org (client-ip=2605:bc80:3010::136; helo=smtp3.osuosl.org; envelope-from=intel-wired-lan-bounces@osuosl.org; receiver=patchwork.ozlabs.org) Received: from smtp3.osuosl.org (smtp3.osuosl.org [IPv6:2605:bc80:3010::136]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (secp384r1) server-digest SHA384) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4S5zff4cB1z23jX for ; Fri, 13 Oct 2023 06:07:38 +1100 (AEDT) Received: from localhost (localhost [127.0.0.1]) by smtp3.osuosl.org (Postfix) with ESMTP id DB1B761060; Thu, 12 Oct 2023 19:07:36 +0000 (UTC) DKIM-Filter: OpenDKIM Filter v2.11.0 smtp3.osuosl.org DB1B761060 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=osuosl.org; s=default; t=1697137656; bh=fNpjQnuPzLjVWdwdCBv9qW++8Oi9ub1/BcMSohKI5rE=; h=Date:In-Reply-To:References:From:To:Subject:List-Id: List-Unsubscribe:List-Archive:List-Post:List-Help:List-Subscribe: Cc:From; b=pmGExFN80i10HTFhXFr1iscEH1fAwc/5bIr9NGZXlndkSq23/NmB6pHkO1g6AnUPp msauPaAcanCMPuNJ7F6AxJAk6P/loHqRYGREddwUuFg6d1xvnzXMk88QWQE0bd/haD W8KCSN9jkir4ALHBe4w5zTBkZK09taFs+nMFz2q0gmegTjpp8XI3L7dfAk4swuKV4K 7B3/BKmhy+USdb+MZ8Ss4WirsqA3vpsC3RlzFVbtYCrhC1L4Ylhc99b9xvJdvHepAB ldSNCquXAb9b3+cvRite2wONi+2wRvwzJvYWUio8GN7JSUL5pZiouNJ49vo2Nx3gkr E+67+YB4zH68A== X-Virus-Scanned: amavisd-new at osuosl.org Received: from smtp3.osuosl.org ([127.0.0.1]) by localhost (smtp3.osuosl.org [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id tvdfKaWYJp9O; Thu, 12 Oct 2023 19:07:36 +0000 (UTC) Received: from ash.osuosl.org (ash.osuosl.org [140.211.166.34]) by smtp3.osuosl.org (Postfix) with ESMTP id EE5DB610A7; Thu, 12 Oct 2023 19:07:35 +0000 (UTC) DKIM-Filter: OpenDKIM Filter v2.11.0 smtp3.osuosl.org EE5DB610A7 X-Original-To: intel-wired-lan@lists.osuosl.org Delivered-To: intel-wired-lan@lists.osuosl.org Received: from smtp4.osuosl.org (smtp4.osuosl.org [140.211.166.137]) by ash.osuosl.org (Postfix) with ESMTP id C593A1BF25F for ; Tue, 10 Oct 2023 22:27:10 +0000 (UTC) Received: from localhost (localhost [127.0.0.1]) by smtp4.osuosl.org (Postfix) with ESMTP id 9C86541E40 for ; Tue, 10 Oct 2023 22:27:10 +0000 (UTC) DKIM-Filter: OpenDKIM Filter v2.11.0 smtp4.osuosl.org 9C86541E40 X-Virus-Scanned: amavisd-new at osuosl.org Received: from smtp4.osuosl.org ([127.0.0.1]) by localhost (smtp4.osuosl.org [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id hD9qhePKXBYY for ; Tue, 10 Oct 2023 22:27:09 +0000 (UTC) Received: from mail-oa1-x49.google.com (mail-oa1-x49.google.com [IPv6:2001:4860:4864:20::49]) by smtp4.osuosl.org (Postfix) with ESMTPS id 3D72041DD2 for ; Tue, 10 Oct 2023 22:27:09 +0000 (UTC) DKIM-Filter: OpenDKIM Filter v2.11.0 smtp4.osuosl.org 3D72041DD2 Received: by mail-oa1-x49.google.com with SMTP id 586e51a60fabf-1e981a23e59so983425fac.0 for ; Tue, 10 Oct 2023 15:27:09 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1696976828; x=1697581628; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=pa7deZDH3/y1FuC+NXYPP7L7Yz4eW2ecVvy54MDyytM=; b=Kz1j8it5k6y0t9bBF93kBVJWXUbINh7O0greRFI7FO8edxzsF8BoQUoMDeTpbM2k3w ttuomg6ytEou5f7pHCndiIdd8ar//ELzWIdqPzar/52J8c2ooyaBu0PLsVYYqKWQU4Vx iJzbjGqFaqiRV5eonRntFY8Z7SHnhHrVaUe6sxDRQFLJ6MaqXkVjCOLeYx2t1XDtAfMi 4VUPov2t307eTrhKxwzo+jNR0WU9cKJHVwBOv4sN/wXKr8XK80PGKVijwPkH6U07DpyJ iqnkHWmFZBZepYgTBVnRLX2//keZdJtHt02/vPEbpI9EfPMdtZPHobMYCKoe4J46Krpr dhuA== X-Gm-Message-State: AOJu0YzD1Tkp6f/glbYTriJa+sKAU3hGpB+cIattxALyrsrk9iU0IlYz m6wj0B/pJqsJ8QkSrFLOHg08YtUG5loOatXwlw== X-Google-Smtp-Source: AGHT+IEadZBbjvmTPKL6ZoF9E9/8NzOm+22mrGAZMVtdJWKWPzsgKk+C0ltQCmzXV0c0zTmFQFZqIhheM6Siw0DEMQ== X-Received: from jstitt-linux1.c.googlers.com ([fda3:e722:ac3:cc00:2b:ff92:c0a8:23b5]) (user=justinstitt job=sendgmr) by 2002:a05:6870:b7b5:b0:1dd:7381:e05 with SMTP id ed53-20020a056870b7b500b001dd73810e05mr8328180oab.3.1696976828369; Tue, 10 Oct 2023 15:27:08 -0700 (PDT) Date: Tue, 10 Oct 2023 22:26:55 +0000 In-Reply-To: <20231010-netdev-replace-strncpy-resend-as-series-v1-0-caf9f0f2f021@google.com> Mime-Version: 1.0 References: <20231010-netdev-replace-strncpy-resend-as-series-v1-0-caf9f0f2f021@google.com> X-Developer-Key: i=justinstitt@google.com; a=ed25519; pk=tC3hNkJQTpNX/gLKxTNQKDmiQl6QjBNCGKJINqAdJsE= X-Developer-Signature: v=1; a=ed25519-sha256; t=1696976824; l=1965; i=justinstitt@google.com; s=20230717; h=from:subject:message-id; bh=rxi6aLNd8v6Nf40hnmQomEOrEb/86fYL7CHbZkLYeOc=; b=j6JQnwbowPf3dzuBaUDjGqeCKA2qyFTP3KIo3eNBNMZczwWVdcd3sWaiujAjoY1XHmfpZr4MB wYA0z04z+jOBph3+HO6oqCmF+03nCsxlBi/fNo6z+SwJCX6k5QcwpK9 X-Mailer: b4 0.12.3 Message-ID: <20231010-netdev-replace-strncpy-resend-as-series-v1-2-caf9f0f2f021@google.com> From: Justin Stitt To: Jesse Brandeburg , Tony Nguyen , "David S. Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni X-Mailman-Approved-At: Thu, 12 Oct 2023 19:06:39 +0000 X-Mailman-Original-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1696976828; x=1697581628; darn=lists.osuosl.org; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:from:to:cc:subject:date:message-id:reply-to; bh=pa7deZDH3/y1FuC+NXYPP7L7Yz4eW2ecVvy54MDyytM=; b=kgRxQ7AnJujNFQmBHAY7mxv64TFa0tNUTp142sXBjBmGzvf2+jrGpqWtMTgVbjgD7P wfVy3YZXnmTZ2JaALqydnKdoAnTlsW79VTWyXj0toQnDGDe4+z99alIJxRVmQe3MusB3 P2+aHVFZmkvpgUA65t0I4DS8JSpGI3vOfmplL6d2qy1r/YWpkdZNoOZ6nAbGlzKh+RXk FyGnSM01BDQlF2K2FcrT8ls35CqJ+NQXyaR8JrGsbVHlSHN/DmKcc0j4F/7o+aSA4OJy 8xO94DeCWDpaBbwph3L5+H7w6wNGTeJqCJZsQ/z+GoA9Bs9BJxZNv+mJnOGRsIcjUGek IPdg== X-Mailman-Original-Authentication-Results: smtp4.osuosl.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.a=rsa-sha256 header.s=20230601 header.b=kgRxQ7An Subject: [Intel-wired-lan] [PATCH v1 net-next 2/7] e1000: replace deprecated strncpy with strscpy X-BeenThere: intel-wired-lan@osuosl.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Intel Wired Ethernet Linux Kernel Driver Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: netdev@vger.kernel.org, Justin Stitt , intel-wired-lan@lists.osuosl.org, linux-hardening@vger.kernel.org, linux-kernel@vger.kernel.org Errors-To: intel-wired-lan-bounces@osuosl.org Sender: "Intel-wired-lan" `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 can see that netdev->name is expected to be NUL-terminated based on it's usage with format strings: | pr_info("%s NIC Link is Down\n", | netdev->name); A suitable replacement is `strscpy` [2] due to the fact that it guarantees NUL-termination on the destination buffer without unnecessarily NUL-padding. This is in line with other uses of strscpy on netdev->name: $ rg "strscpy\(netdev\->name.*pci.*" drivers/net/ethernet/intel/e1000e/netdev.c 7455: strscpy(netdev->name, pci_name(pdev), sizeof(netdev->name)); drivers/net/ethernet/intel/ixgbe/ixgbe_main.c 10839: strscpy(netdev->name, pci_name(pdev), sizeof(netdev->name)); 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/intel/e1000/e1000_main.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/drivers/net/ethernet/intel/e1000/e1000_main.c b/drivers/net/ethernet/intel/e1000/e1000_main.c index da6e303ad99b..1d1e93686af2 100644 --- a/drivers/net/ethernet/intel/e1000/e1000_main.c +++ b/drivers/net/ethernet/intel/e1000/e1000_main.c @@ -1014,7 +1014,7 @@ static int e1000_probe(struct pci_dev *pdev, const struct pci_device_id *ent) netdev->watchdog_timeo = 5 * HZ; netif_napi_add(netdev, &adapter->napi, e1000_clean); - strncpy(netdev->name, pci_name(pdev), sizeof(netdev->name) - 1); + strscpy(netdev->name, pci_name(pdev), sizeof(netdev->name)); adapter->bd_number = cards_found; From patchwork Tue Oct 10 22:26:56 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Justin Stitt X-Patchwork-Id: 1847753 X-Patchwork-Delegate: anthony.l.nguyen@intel.com Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=osuosl.org header.i=@osuosl.org header.a=rsa-sha256 header.s=default header.b=6/DWSek3; dkim-atps=neutral Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=osuosl.org (client-ip=140.211.166.136; helo=smtp3.osuosl.org; envelope-from=intel-wired-lan-bounces@osuosl.org; receiver=patchwork.ozlabs.org) Received: from smtp3.osuosl.org (smtp3.osuosl.org [140.211.166.136]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (secp384r1) server-digest SHA384) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4S5zfl0bCfz23jX for ; Fri, 13 Oct 2023 06:07:43 +1100 (AEDT) Received: from localhost (localhost [127.0.0.1]) by smtp3.osuosl.org (Postfix) with ESMTP id 4F9A560F26; Thu, 12 Oct 2023 19:07:41 +0000 (UTC) DKIM-Filter: OpenDKIM Filter v2.11.0 smtp3.osuosl.org 4F9A560F26 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=osuosl.org; s=default; t=1697137661; bh=oNxmGK1Tev9J+7xzZGg+vw2+0WbWBcU45xXtY8Y5lVM=; h=Date:In-Reply-To:References:From:To:Subject:List-Id: List-Unsubscribe:List-Archive:List-Post:List-Help:List-Subscribe: Cc:From; b=6/DWSek3s+lcQ6Tf4xZuajeyxOgd0uDHcgJSQfWloxIHdvUeX4/DPZzwh4HGaeCj4 uUZ3bD4EaaIoaRK9+Gsl+EwBRA+drx1iLx2Rnhe+SM9t1cVZYUzOg0KW0YzMXMjzNR /E7Z4ck5jK/bV7Uyk69eB15qqmb+aAXbE9/EUpfl7qRJW7IowUUCNDt7JZ2FAnK8q3 7NElg77VJVxreJ73huctav/Pt5G8UEEDTGH2uZGjdRrxNxUMpE/pKd+932gQ3b7Vs8 lcLp3adg+Nydvom6nLDIP2btRBmXwU4kyBLzF04kI5ZiCMzGBxs7zh634i+HEI6g6G OWLmm85zHUieQ== X-Virus-Scanned: amavisd-new at osuosl.org Received: from smtp3.osuosl.org ([127.0.0.1]) by localhost (smtp3.osuosl.org [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id hLhm0J5XwpIL; Thu, 12 Oct 2023 19:07:40 +0000 (UTC) Received: from ash.osuosl.org (ash.osuosl.org [140.211.166.34]) by smtp3.osuosl.org (Postfix) with ESMTP id 2D747611EE; Thu, 12 Oct 2023 19:07:40 +0000 (UTC) DKIM-Filter: OpenDKIM Filter v2.11.0 smtp3.osuosl.org 2D747611EE X-Original-To: intel-wired-lan@lists.osuosl.org Delivered-To: intel-wired-lan@lists.osuosl.org Received: from smtp3.osuosl.org (smtp3.osuosl.org [140.211.166.136]) by ash.osuosl.org (Postfix) with ESMTP id BFACD1BF25F for ; Tue, 10 Oct 2023 22:27:11 +0000 (UTC) Received: from localhost (localhost [127.0.0.1]) by smtp3.osuosl.org (Postfix) with ESMTP id A59E560EA5 for ; Tue, 10 Oct 2023 22:27:11 +0000 (UTC) DKIM-Filter: OpenDKIM Filter v2.11.0 smtp3.osuosl.org A59E560EA5 X-Virus-Scanned: amavisd-new at osuosl.org Received: from smtp3.osuosl.org ([127.0.0.1]) by localhost (smtp3.osuosl.org [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id jPZCVrQkOe2A for ; Tue, 10 Oct 2023 22:27:10 +0000 (UTC) Received: from mail-yb1-xb4a.google.com (mail-yb1-xb4a.google.com [IPv6:2607:f8b0:4864:20::b4a]) by smtp3.osuosl.org (Postfix) with ESMTPS id A190C60E6D for ; Tue, 10 Oct 2023 22:27:10 +0000 (UTC) DKIM-Filter: OpenDKIM Filter v2.11.0 smtp3.osuosl.org A190C60E6D Received: by mail-yb1-xb4a.google.com with SMTP id 3f1490d57ef6-d86dac81f8fso8682697276.1 for ; Tue, 10 Oct 2023 15:27:10 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1696976829; x=1697581629; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=lTnwaqL2jLBaxkmW2WMaRMaHCldHf8+/MXLc/TIFT4c=; b=FW21M79vjLJjKBBDuOJcvsDhgivD9SCGqWp1091+nB7DODM9sXJRpniVTCplv80xSP BT9K3Q4nEo5tR8xSW6pqpfvZaW8FYKYFM5ZgEpzpSsJjkvcLzp92DtIoxq+E9xTXo9rh Jrg8OhUSxwXKzWmufmS8H+Bgu2FBeXxROtUzvbJV2WSV4l9L6THh4RspjPhVQidzvDyx UJeRkwPQFkGh5P3d/syqON+xbvrc7AdJquszzbw926QKwUeQpXv5jyBFClDJeDBQq9rT O5PFFBsdniQb9ScaTbW2fgAtseTxRPH2vneIdEaNIhgi06Oi676U8ke501AUvYL5aavB EzXw== X-Gm-Message-State: AOJu0Yz79vI4FSjZCMJfzqTy4oPiOlu/3PlXh3Wp9KLrGZjzv6/UyiiU eHV5etR+b8Hsk0M80RCaaXDQgssRlwYgvgc2uA== X-Google-Smtp-Source: AGHT+IEhKRo7Fa50WHzFdWOO31BMGB9F9TmfVk9lGMD83bOfMPCZJRqBjhsWFbscP5Go+W8LBaXKuS+3ektW2jj+vA== X-Received: from jstitt-linux1.c.googlers.com ([fda3:e722:ac3:cc00:2b:ff92:c0a8:23b5]) (user=justinstitt job=sendgmr) by 2002:a25:9349:0:b0:d80:12c:d49b with SMTP id g9-20020a259349000000b00d80012cd49bmr352222ybo.8.1696976829556; Tue, 10 Oct 2023 15:27:09 -0700 (PDT) Date: Tue, 10 Oct 2023 22:26:56 +0000 In-Reply-To: <20231010-netdev-replace-strncpy-resend-as-series-v1-0-caf9f0f2f021@google.com> Mime-Version: 1.0 References: <20231010-netdev-replace-strncpy-resend-as-series-v1-0-caf9f0f2f021@google.com> X-Developer-Key: i=justinstitt@google.com; a=ed25519; pk=tC3hNkJQTpNX/gLKxTNQKDmiQl6QjBNCGKJINqAdJsE= X-Developer-Signature: v=1; a=ed25519-sha256; t=1696976825; l=2155; i=justinstitt@google.com; s=20230717; h=from:subject:message-id; bh=OVZJsM7ldFpBAzherL0f3bvpgvacQBDrwKwi/3HnF5o=; b=VAP1FhD196P2wXpYtHTj+oub2FKXyLs035gJ11JD9BWHTobZWE7G6hG6hva6AMypTOMJugLLr iU1NTx0gyFVACLLcwaYcZNUqVriQ4UPkUi7BGHg/1QJ/x1taOIyXHl8 X-Mailer: b4 0.12.3 Message-ID: <20231010-netdev-replace-strncpy-resend-as-series-v1-3-caf9f0f2f021@google.com> From: Justin Stitt To: Jesse Brandeburg , Tony Nguyen , "David S. Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni X-Mailman-Approved-At: Thu, 12 Oct 2023 19:06:39 +0000 X-Mailman-Original-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1696976829; x=1697581629; darn=lists.osuosl.org; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:from:to:cc:subject:date:message-id:reply-to; bh=lTnwaqL2jLBaxkmW2WMaRMaHCldHf8+/MXLc/TIFT4c=; b=ONdykWFmqlhd60mb3+lCRitQorKpTVmEbPi+/WaHMwgyeTYbeXNsKAwb19A+20326M fXBqBkt0cQz2mxfG4nyFNG8A9btLq7Ypt3A6koqll/Py61aupwnnHNE8syC7rnjCenh9 ej6Py+5jIl945hQ963rQc19MBCOYBE7z+dblwb1KKq64ItjVxUqGFPqCEf93FyfjCmmg fp6zUtWyiz2AYdF69z5ZNzx8TvGcILAPQ751QCRplHWscPCxjiG3b2Ad2phMSqn3CWsm o3qa9gvSCN7toWWI6H9ZJ4rcTlqzpjxreP4HPDtFjxIKZRq3VAzJWpN5YJR8rhhSosXH ctbg== X-Mailman-Original-Authentication-Results: smtp3.osuosl.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.a=rsa-sha256 header.s=20230601 header.b=ONdykWFm Subject: [Intel-wired-lan] [PATCH v1 net-next 3/7] fm10k: replace deprecated strncpy with strscpy X-BeenThere: intel-wired-lan@osuosl.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Intel Wired Ethernet Linux Kernel Driver Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: netdev@vger.kernel.org, Justin Stitt , intel-wired-lan@lists.osuosl.org, linux-hardening@vger.kernel.org, linux-kernel@vger.kernel.org Errors-To: intel-wired-lan-bounces@osuosl.org Sender: "Intel-wired-lan" `strncpy` is deprecated for use on NUL-terminated destination strings [1] and as such we should prefer more robust and less ambiguous string interfaces. A suitable replacement is `strscpy` [2] due to the fact that it guarantees NUL-termination on the destination buffer without unnecessarily NUL-padding. Other implementations of .*get_drvinfo also use strscpy so this patch brings fm10k_get_drvinfo in line as well: igb/igb_ethtool.c +851 static void igb_get_drvinfo(struct net_device *netdev, igbvf/ethtool.c 167:static void igbvf_get_drvinfo(struct net_device *netdev, i40e/i40e_ethtool.c 1999:static void i40e_get_drvinfo(struct net_device *netdev, e1000/e1000_ethtool.c 529:static void e1000_get_drvinfo(struct net_device *netdev, ixgbevf/ethtool.c 211:static void ixgbevf_get_drvinfo(struct net_device *netdev, 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/intel/fm10k/fm10k_ethtool.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/drivers/net/ethernet/intel/fm10k/fm10k_ethtool.c b/drivers/net/ethernet/intel/fm10k/fm10k_ethtool.c index d53369e30040..13a05604dcc0 100644 --- a/drivers/net/ethernet/intel/fm10k/fm10k_ethtool.c +++ b/drivers/net/ethernet/intel/fm10k/fm10k_ethtool.c @@ -448,10 +448,10 @@ static void fm10k_get_drvinfo(struct net_device *dev, { struct fm10k_intfc *interface = netdev_priv(dev); - strncpy(info->driver, fm10k_driver_name, - sizeof(info->driver) - 1); - strncpy(info->bus_info, pci_name(interface->pdev), - sizeof(info->bus_info) - 1); + strscpy(info->driver, fm10k_driver_name, + sizeof(info->driver)); + strscpy(info->bus_info, pci_name(interface->pdev), + sizeof(info->bus_info)); } static void fm10k_get_pauseparam(struct net_device *dev, From patchwork Tue Oct 10 22:26:57 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Justin Stitt X-Patchwork-Id: 1847754 X-Patchwork-Delegate: anthony.l.nguyen@intel.com Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=osuosl.org header.i=@osuosl.org header.a=rsa-sha256 header.s=default header.b=wtf5fC6x; dkim-atps=neutral Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=osuosl.org (client-ip=140.211.166.136; helo=smtp3.osuosl.org; envelope-from=intel-wired-lan-bounces@osuosl.org; receiver=patchwork.ozlabs.org) Received: from smtp3.osuosl.org (smtp3.osuosl.org [140.211.166.136]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (secp384r1) server-digest SHA384) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4S5zfq1Mmjz23jX for ; Fri, 13 Oct 2023 06:07:47 +1100 (AEDT) Received: from localhost (localhost [127.0.0.1]) by smtp3.osuosl.org (Postfix) with ESMTP id 65320611FD; Thu, 12 Oct 2023 19:07:45 +0000 (UTC) DKIM-Filter: OpenDKIM Filter v2.11.0 smtp3.osuosl.org 65320611FD DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=osuosl.org; s=default; t=1697137665; bh=q4JZNHJUJF2LUSMH7A09xCjiR8Fvnglp3mwinSH/mYI=; h=Date:In-Reply-To:References:From:To:Subject:List-Id: List-Unsubscribe:List-Archive:List-Post:List-Help:List-Subscribe: Cc:From; b=wtf5fC6x49GI7OhOCMAGwONdpdsj8v1KgvJqJYOV1Y4BlyfRzREZ5aWnkbk6tGRbu Yf7WKeKVircqr+qYrsq4C3eyW7WDt8n6lUckOa1uGsbwDn0zl+65PoMt8A2/bEetLo gAaA+EbjhGAXZHoUOrVcICJ9n8ZLakwklByR/pFMkdSL18dGyO7/8Z1Pl6x1SUkZ8Q 4b0EpDYB092iyVOEm++YlpaJjkJQ/T6ZfC+I9uilU5IfcsMUaee/QldPRNcKcqHNl/ jB3W46UFyMPvDBX55ZGBfBWfqXqRY2aXrKI9hM3HYAeWxhSzB4amtVCNpUxwJ9UwWh XNnnykdudPA7A== X-Virus-Scanned: amavisd-new at osuosl.org Received: from smtp3.osuosl.org ([127.0.0.1]) by localhost (smtp3.osuosl.org [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id RIhJCSHUIwZu; Thu, 12 Oct 2023 19:07:44 +0000 (UTC) Received: from ash.osuosl.org (ash.osuosl.org [140.211.166.34]) by smtp3.osuosl.org (Postfix) with ESMTP id 637C7606DC; Thu, 12 Oct 2023 19:07:44 +0000 (UTC) DKIM-Filter: OpenDKIM Filter v2.11.0 smtp3.osuosl.org 637C7606DC X-Original-To: intel-wired-lan@lists.osuosl.org Delivered-To: intel-wired-lan@lists.osuosl.org Received: from smtp2.osuosl.org (smtp2.osuosl.org [140.211.166.133]) by ash.osuosl.org (Postfix) with ESMTP id 5BDEC1BF969 for ; Tue, 10 Oct 2023 22:27:13 +0000 (UTC) Received: from localhost (localhost [127.0.0.1]) by smtp2.osuosl.org (Postfix) with ESMTP id 42D4D4044D for ; Tue, 10 Oct 2023 22:27:13 +0000 (UTC) DKIM-Filter: OpenDKIM Filter v2.11.0 smtp2.osuosl.org 42D4D4044D X-Virus-Scanned: amavisd-new at osuosl.org Received: from smtp2.osuosl.org ([127.0.0.1]) by localhost (smtp2.osuosl.org [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id yg0yaG10Aakv for ; Tue, 10 Oct 2023 22:27:12 +0000 (UTC) Received: from mail-yb1-xb49.google.com (mail-yb1-xb49.google.com [IPv6:2607:f8b0:4864:20::b49]) by smtp2.osuosl.org (Postfix) with ESMTPS id 03A4C40012 for ; Tue, 10 Oct 2023 22:27:11 +0000 (UTC) DKIM-Filter: OpenDKIM Filter v2.11.0 smtp2.osuosl.org 03A4C40012 Received: by mail-yb1-xb49.google.com with SMTP id 3f1490d57ef6-d85fc6261ffso7776482276.1 for ; Tue, 10 Oct 2023 15:27:11 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1696976831; x=1697581631; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=oWOmRc+XZmwUYDYQzA9Y2kZz6fI7UsCc4iSNlP1q3ak=; b=UZQuwXIMM+QE+ydOQsYZE9S+2pX28ssSy7OqW6nVHGVFwlFRf+qgMOjVtQCTdpx094 tkzOb4f688AU8x4IJHKa/gCzIA4/T4WDEPxiu+riYxx2VnCoXNIJ3AvjSA1Yt0RY10bi XEWPafwk4YPUx5Lm+ZX3dCW8PallVfkUiVHf0Zx/kiwR8DW9mTTfnXXgOaoJ9ybZNFBg MVnKtwbu7KfQ6fYhldU28lv0EktEUtlvnJWOEZxWrl6C+mLUU9/TvLG3jX4lnBxjoD6k J9qgO4yrV09HRs4HDwXcBPwZAMGQpnRymk5+tL5cCDzdD0b6H2CowgHziwnD71/1sU27 IASQ== X-Gm-Message-State: AOJu0YyWQbnZu5O+QLH+7NB/OrSjA4UCQ38u+Yv7U7Q26QjcwAVPRc2I /YXKlZJIEv1aZztkra7Fgvd3ZiQUCi1MRcxZCw== X-Google-Smtp-Source: AGHT+IFkc91aNuPbdgNMKkpApTBJBwoJdK74m18bTrvbP5UnyOxaDLY5NiS6TA4MHAZJINXqQEimpa3GEQg6j8fOtQ== X-Received: from jstitt-linux1.c.googlers.com ([fda3:e722:ac3:cc00:2b:ff92:c0a8:23b5]) (user=justinstitt job=sendgmr) by 2002:a5b:b50:0:b0:d80:904d:c211 with SMTP id b16-20020a5b0b50000000b00d80904dc211mr300318ybr.7.1696976830823; Tue, 10 Oct 2023 15:27:10 -0700 (PDT) Date: Tue, 10 Oct 2023 22:26:57 +0000 In-Reply-To: <20231010-netdev-replace-strncpy-resend-as-series-v1-0-caf9f0f2f021@google.com> Mime-Version: 1.0 References: <20231010-netdev-replace-strncpy-resend-as-series-v1-0-caf9f0f2f021@google.com> X-Developer-Key: i=justinstitt@google.com; a=ed25519; pk=tC3hNkJQTpNX/gLKxTNQKDmiQl6QjBNCGKJINqAdJsE= X-Developer-Signature: v=1; a=ed25519-sha256; t=1696976825; l=1944; i=justinstitt@google.com; s=20230717; h=from:subject:message-id; bh=vWykgd1iTIJF2QxHf+tyASmo5uKe5mdTGzeWp73J3yY=; b=dzlYZaGDxURN55XtwFmYQSEtTx4wp18WY6OhgjXTiLw5YGpZ7hnkSxOnVmHET2lNMcPyKfgGC QVaHSfcsAGGCOAoWF6TUtQ+jGaiCMlbEXkYYAyMsry5Pgk0nUS2vgl1 X-Mailer: b4 0.12.3 Message-ID: <20231010-netdev-replace-strncpy-resend-as-series-v1-4-caf9f0f2f021@google.com> From: Justin Stitt To: Jesse Brandeburg , Tony Nguyen , "David S. Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni X-Mailman-Approved-At: Thu, 12 Oct 2023 19:06:39 +0000 X-Mailman-Original-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1696976831; x=1697581631; darn=lists.osuosl.org; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:from:to:cc:subject:date:message-id:reply-to; bh=oWOmRc+XZmwUYDYQzA9Y2kZz6fI7UsCc4iSNlP1q3ak=; b=iPtVB8teXisTZVzmFth9mGyolubVBD8Rj1Smd/xtUlWbpXlC7kV9FkyvXkoPgpLf1t JOj2pnjyBv7dASycSQFFkk7QdQf9BuMEj5XxzRCsp0IVMwabHmFYGO31e55GLzIm5Ikc 6PRe/0Wq7gqIQ5buOCtOSkW0XKmTzFgkXDcPFZK0Do4o35ajQJtti2LJsFMsF0YSb/OP 7Lt4Z23gqzKUjNtOIQsQaDcqE6x3Ezufcto+xcGyV1MkTl/QSjD2lMtS30Sp/Z9ad+ec 5rtOkp0C5KLd/Qw6fyHNik8CCg0BR5wKparudvTE7ll/q+aYJbUs4EupYzWz7c++9PKj Q0OA== X-Mailman-Original-Authentication-Results: smtp2.osuosl.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.a=rsa-sha256 header.s=20230601 header.b=iPtVB8te Subject: [Intel-wired-lan] [PATCH v1 net-next 4/7] i40e: use scnprintf over strncpy+strncat X-BeenThere: intel-wired-lan@osuosl.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Intel Wired Ethernet Linux Kernel Driver Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: netdev@vger.kernel.org, Justin Stitt , intel-wired-lan@lists.osuosl.org, linux-hardening@vger.kernel.org, linux-kernel@vger.kernel.org Errors-To: intel-wired-lan-bounces@osuosl.org Sender: "Intel-wired-lan" `strncpy` is deprecated for use on NUL-terminated destination strings [1] and as such we should prefer more robust and less ambiguous string interfaces. Moreover, `strncat` shouldn't really be used either as per fortify-string.h: * Do not use this function. While FORTIFY_SOURCE tries to avoid * read and write overflows, this is only possible when the sizes * of @p and @q are known to the compiler. Prefer building the * string with formatting, via scnprintf() or similar. Instead, use `scnprintf` with "%s%s" format string. This code is now more readable and robust. 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 Tested-by: Pucha Himasekhar Reddy (A Contingent worker at Intel) --- Note: build-tested only. --- drivers/net/ethernet/intel/i40e/i40e_ddp.c | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/drivers/net/ethernet/intel/i40e/i40e_ddp.c b/drivers/net/ethernet/intel/i40e/i40e_ddp.c index 0e72abd178ae..ec25e4be250f 100644 --- a/drivers/net/ethernet/intel/i40e/i40e_ddp.c +++ b/drivers/net/ethernet/intel/i40e/i40e_ddp.c @@ -438,10 +438,9 @@ int i40e_ddp_flash(struct net_device *netdev, struct ethtool_flash *flash) char profile_name[sizeof(I40E_DDP_PROFILE_PATH) + I40E_DDP_PROFILE_NAME_MAX]; - profile_name[sizeof(profile_name) - 1] = 0; - strncpy(profile_name, I40E_DDP_PROFILE_PATH, - sizeof(profile_name) - 1); - strncat(profile_name, flash->data, I40E_DDP_PROFILE_NAME_MAX); + scnprintf(profile_name, sizeof(profile_name), "%s%s", + I40E_DDP_PROFILE_PATH, flash->data); + /* Load DDP recipe. */ status = request_firmware(&ddp_config, profile_name, &netdev->dev); From patchwork Tue Oct 10 22:26:58 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Justin Stitt X-Patchwork-Id: 1847755 X-Patchwork-Delegate: anthony.l.nguyen@intel.com Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=osuosl.org header.i=@osuosl.org header.a=rsa-sha256 header.s=default header.b=CV76x7kZ; dkim-atps=neutral Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=osuosl.org (client-ip=2605:bc80:3010::136; helo=smtp3.osuosl.org; envelope-from=intel-wired-lan-bounces@osuosl.org; receiver=patchwork.ozlabs.org) Received: from smtp3.osuosl.org (smtp3.osuosl.org [IPv6:2605:bc80:3010::136]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (secp384r1) server-digest SHA384) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4S5zfx6Sq6z23jX for ; Fri, 13 Oct 2023 06:07:53 +1100 (AEDT) Received: from localhost (localhost [127.0.0.1]) by smtp3.osuosl.org (Postfix) with ESMTP id 287A1610A7; Thu, 12 Oct 2023 19:07:52 +0000 (UTC) DKIM-Filter: OpenDKIM Filter v2.11.0 smtp3.osuosl.org 287A1610A7 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=osuosl.org; s=default; t=1697137672; bh=XBT4/T0+lkJ2hcHG7rMFPHk5q5eV3jHMjR2UFnS6p58=; h=Date:In-Reply-To:References:From:To:Subject:List-Id: List-Unsubscribe:List-Archive:List-Post:List-Help:List-Subscribe: Cc:From; b=CV76x7kZfGuCtJ5ss9WFraM5uXqpDPIBl1I8ZtpcmNZpuntu/UjcLVFTbUEgMOYmW a8AXXqJasvZ9JCGQNbQtfL4njVfzTA5bgHweCWazf7JifIOJq+ZiezWG5gvCvIxSY6 Oq/azrFa4GmC1cPQpyDBSOLc0I3k26igj3H5rdbNL8ol6A2BCLMOpH8jVPgIfE/w+y AfayDh+UYWyh5rKX08XIfdl8RUNyFl5SmHHM03X/8CbhKlfBosllJ5eq0d+Sue5mvG gJ1n8p7OPSyCvq7qxfk5Fm6QwzrxO5nvhw/uOtNPMubVAysc4AJ7Ib0yQye3qAI3/4 EyOQQr0Gzubjg== X-Virus-Scanned: amavisd-new at osuosl.org Received: from smtp3.osuosl.org ([127.0.0.1]) by localhost (smtp3.osuosl.org [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id M3SWahZccLOG; Thu, 12 Oct 2023 19:07:49 +0000 (UTC) Received: from ash.osuosl.org (ash.osuosl.org [140.211.166.34]) by smtp3.osuosl.org (Postfix) with ESMTP id 8C76160634; Thu, 12 Oct 2023 19:07:48 +0000 (UTC) DKIM-Filter: OpenDKIM Filter v2.11.0 smtp3.osuosl.org 8C76160634 X-Original-To: intel-wired-lan@lists.osuosl.org Delivered-To: intel-wired-lan@lists.osuosl.org Received: from smtp2.osuosl.org (smtp2.osuosl.org [140.211.166.133]) by ash.osuosl.org (Postfix) with ESMTP id 79E351BF25F for ; Tue, 10 Oct 2023 22:27:14 +0000 (UTC) Received: from localhost (localhost [127.0.0.1]) by smtp2.osuosl.org (Postfix) with ESMTP id 4E9474044D for ; Tue, 10 Oct 2023 22:27:14 +0000 (UTC) DKIM-Filter: OpenDKIM Filter v2.11.0 smtp2.osuosl.org 4E9474044D X-Virus-Scanned: amavisd-new at osuosl.org Received: from smtp2.osuosl.org ([127.0.0.1]) by localhost (smtp2.osuosl.org [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id DX17hevwDrRp for ; Tue, 10 Oct 2023 22:27:13 +0000 (UTC) Received: from mail-yb1-xb49.google.com (mail-yb1-xb49.google.com [IPv6:2607:f8b0:4864:20::b49]) by smtp2.osuosl.org (Postfix) with ESMTPS id 5FA8F40012 for ; Tue, 10 Oct 2023 22:27:13 +0000 (UTC) DKIM-Filter: OpenDKIM Filter v2.11.0 smtp2.osuosl.org 5FA8F40012 Received: by mail-yb1-xb49.google.com with SMTP id 3f1490d57ef6-d9a509861acso1944604276.2 for ; Tue, 10 Oct 2023 15:27:13 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1696976832; x=1697581632; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=GtM0w+J9cw3jjb0usGEHfb5iDugSjDgb6JSiT+iZymc=; b=eTzJsnwFHqFfCH/jU2bwueMDONwl70zofdHV5ryMWRmtVTTjEdXqxP9CDToTnKurzl pjPXNdjRNKd0UADBXp0O1HcXLE37AQ3CB2yMrwcuDjpD5fTFtwDaFRctcUmANEkHdBD0 QiFebgHRU1XpzgkIA6kbahPLsT8xvK72kU5EG5BdCrMwZ1mm1uH/YyfzTVps7K5nOWWf sABjHRvb+n8+TCz2LAgFJ5E5Zr1KumT/c5NNthIwrLQHecV6LIXnnuYar42hJxZwNN42 YjfQ9k6WbITCWKhsasye6PzLt8S3ddLHakVSl4y8d++rAVHd+wghBRHCqDSJJiUqKjws 6Axw== X-Gm-Message-State: AOJu0YwPtvt0vAfOSeeer0IciCmAYx6ypiAMkypw1WeeGk7pMT5fO6ZP XcKwbkzMLuTUiehnHcaUqxBQUdhw6oul4mDCrA== X-Google-Smtp-Source: AGHT+IE90IMRLxbCtK+FWTfBYeHC+U5Cy3qc2KOUif/Mw4hAnclXZq/qXjDbI29Vfn0ZPUuW4ixhfNcK0Pbgbem5bA== X-Received: from jstitt-linux1.c.googlers.com ([fda3:e722:ac3:cc00:2b:ff92:c0a8:23b5]) (user=justinstitt job=sendgmr) by 2002:a25:ced3:0:b0:d9a:634d:4400 with SMTP id x202-20020a25ced3000000b00d9a634d4400mr53292ybe.5.1696976832282; Tue, 10 Oct 2023 15:27:12 -0700 (PDT) Date: Tue, 10 Oct 2023 22:26:58 +0000 In-Reply-To: <20231010-netdev-replace-strncpy-resend-as-series-v1-0-caf9f0f2f021@google.com> Mime-Version: 1.0 References: <20231010-netdev-replace-strncpy-resend-as-series-v1-0-caf9f0f2f021@google.com> X-Developer-Key: i=justinstitt@google.com; a=ed25519; pk=tC3hNkJQTpNX/gLKxTNQKDmiQl6QjBNCGKJINqAdJsE= X-Developer-Signature: v=1; a=ed25519-sha256; t=1696976825; l=2053; i=justinstitt@google.com; s=20230717; h=from:subject:message-id; bh=tIBhN0dI5KQV25Dn8IjDZp+7IelZH6PsmdLrTBm66Xc=; b=hRT8DAV5FRqqSXsHAHmPSGPSEQbQBGx13G3GU53NmuUbzuZgGmmwVJqw/B2WprCOy7JOSEs7A JUBcK+9dOy2Bis775R/QWrp3y4385KpGI7leBfVy2b+aVrSU/y1pH0a X-Mailer: b4 0.12.3 Message-ID: <20231010-netdev-replace-strncpy-resend-as-series-v1-5-caf9f0f2f021@google.com> From: Justin Stitt To: Jesse Brandeburg , Tony Nguyen , "David S. Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni X-Mailman-Approved-At: Thu, 12 Oct 2023 19:06:39 +0000 X-Mailman-Original-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1696976832; x=1697581632; darn=lists.osuosl.org; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:from:to:cc:subject:date:message-id:reply-to; bh=GtM0w+J9cw3jjb0usGEHfb5iDugSjDgb6JSiT+iZymc=; b=HCZhogpfqvjds7uNBfhVwTX4Eq8Uw663hvqpitFaKyMEcE59il4keVd4kt7nY6wV6v 3IpYCYMCEey2XeTf1ckMj7vwSgd7Wnoch7EtSXBiSKe2LsYFi5WMwt6+fFBRH8mzWwZH LuKH8Xk78CzFcQQH58RlJKyzL+wg4YiQvbKne6TmkZ8YYHdHWtJOpeZ9LPgOqJ+pseWH cMd2trTaqXlJoYyuJQcXeplsh77NjHRq6kM937u8BNSo+7JliUnQv+FBxOcHe1wtlcgk VVaRKXOu51MGzvZaBv/rrCav+T3U5S3YaXAkqqLdDc3/n3HcLLoT7DMwN4X7lXKBrjv8 EEBQ== X-Mailman-Original-Authentication-Results: smtp2.osuosl.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.a=rsa-sha256 header.s=20230601 header.b=HCZhogpf Subject: [Intel-wired-lan] [PATCH v1 net-next 5/7] igb: replace deprecated strncpy with strscpy X-BeenThere: intel-wired-lan@osuosl.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Intel Wired Ethernet Linux Kernel Driver Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: netdev@vger.kernel.org, Justin Stitt , intel-wired-lan@lists.osuosl.org, linux-hardening@vger.kernel.org, linux-kernel@vger.kernel.org Errors-To: intel-wired-lan-bounces@osuosl.org Sender: "Intel-wired-lan" `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 see that netdev->name is expected to be NUL-terminated based on its usage with format strings: | sprintf(q_vector->name, "%s-TxRx-%u", netdev->name, | q_vector->rx.ring->queue_index); Furthermore, NUL-padding is not required as netdev is already zero-allocated: | netdev = alloc_etherdev_mq(sizeof(struct igb_adapter), | IGB_MAX_TX_QUEUES); ... alloc_etherdev_mq() -> alloc_etherdev_mqs() -> alloc_netdev_mqs() ... | p = kvzalloc(alloc_size, GFP_KERNEL_ACCOUNT | __GFP_RETRY_MAYFAIL); 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 Tested-by: Pucha Himasekhar Reddy (A Contingent worker at Intel) --- Note: build-tested only. --- drivers/net/ethernet/intel/igb/igb_main.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/drivers/net/ethernet/intel/igb/igb_main.c b/drivers/net/ethernet/intel/igb/igb_main.c index 76b34cee1da3..9de103bd3ad3 100644 --- a/drivers/net/ethernet/intel/igb/igb_main.c +++ b/drivers/net/ethernet/intel/igb/igb_main.c @@ -3264,7 +3264,7 @@ static int igb_probe(struct pci_dev *pdev, const struct pci_device_id *ent) igb_set_ethtool_ops(netdev); netdev->watchdog_timeo = 5 * HZ; - strncpy(netdev->name, pci_name(pdev), sizeof(netdev->name) - 1); + strscpy(netdev->name, pci_name(pdev), sizeof(netdev->name)); netdev->mem_start = pci_resource_start(pdev, 0); netdev->mem_end = pci_resource_end(pdev, 0); From patchwork Tue Oct 10 22:26:59 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Justin Stitt X-Patchwork-Id: 1847756 X-Patchwork-Delegate: anthony.l.nguyen@intel.com Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=osuosl.org header.i=@osuosl.org header.a=rsa-sha256 header.s=default header.b=Ok218b6r; dkim-atps=neutral Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=osuosl.org (client-ip=2605:bc80:3010::136; helo=smtp3.osuosl.org; envelope-from=intel-wired-lan-bounces@osuosl.org; receiver=patchwork.ozlabs.org) Received: from smtp3.osuosl.org (smtp3.osuosl.org [IPv6:2605:bc80:3010::136]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (secp384r1) server-digest SHA384) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4S5zg05ZBdz23jX for ; Fri, 13 Oct 2023 06:07:56 +1100 (AEDT) Received: from localhost (localhost [127.0.0.1]) by smtp3.osuosl.org (Postfix) with ESMTP id AED7860634; Thu, 12 Oct 2023 19:07:53 +0000 (UTC) DKIM-Filter: OpenDKIM Filter v2.11.0 smtp3.osuosl.org AED7860634 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=osuosl.org; s=default; t=1697137673; bh=60UefcizznLBx6M2vGYK5o7Bg/AxO2I0ZISRtOkt6gY=; h=Date:In-Reply-To:References:From:To:Subject:List-Id: List-Unsubscribe:List-Archive:List-Post:List-Help:List-Subscribe: Cc:From; b=Ok218b6rvEbO6DpyJbv4v31+5yEA4zAfNLFP5fwhtxkwLguqdDDwkWtEv7FUA2VcW ITDCSvETu/nFn6gEXiCNlG2CjV8fEcYWe3qhyDa22QoDy36vb0OVYQgan2FwgVLtdB Mwi0sUTTWwmjCK7njkIuHucRReuHanmOO+hpkDVbloHT7La/oDShCV/0kipZ0fBFzH pgFq3blur0YDkR0U6Y6omaSaElS+kwvjvtopgkws945eH4fOpoE4wnHHeDjJQEw38a V/DjBgPcj2LVIsNEUOKtaBlYZ0I3Kf6XLv4JrNKbauEY6L2vHYoWsR11X7+Cr/geHK CcHSZQN3Uw/0g== X-Virus-Scanned: amavisd-new at osuosl.org Received: from smtp3.osuosl.org ([127.0.0.1]) by localhost (smtp3.osuosl.org [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id H6gyEuVEoGYW; Thu, 12 Oct 2023 19:07:52 +0000 (UTC) Received: from ash.osuosl.org (ash.osuosl.org [140.211.166.34]) by smtp3.osuosl.org (Postfix) with ESMTP id B67B26103B; Thu, 12 Oct 2023 19:07:52 +0000 (UTC) DKIM-Filter: OpenDKIM Filter v2.11.0 smtp3.osuosl.org B67B26103B X-Original-To: intel-wired-lan@lists.osuosl.org Delivered-To: intel-wired-lan@lists.osuosl.org Received: from smtp2.osuosl.org (smtp2.osuosl.org [140.211.166.133]) by ash.osuosl.org (Postfix) with ESMTP id A33B01BF969 for ; Tue, 10 Oct 2023 22:27:15 +0000 (UTC) Received: from localhost (localhost [127.0.0.1]) by smtp2.osuosl.org (Postfix) with ESMTP id 7C5A74044D for ; Tue, 10 Oct 2023 22:27:15 +0000 (UTC) DKIM-Filter: OpenDKIM Filter v2.11.0 smtp2.osuosl.org 7C5A74044D X-Virus-Scanned: amavisd-new at osuosl.org Received: from smtp2.osuosl.org ([127.0.0.1]) by localhost (smtp2.osuosl.org [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id fhRk5r4I1G9G for ; Tue, 10 Oct 2023 22:27:14 +0000 (UTC) Received: from mail-yw1-x1149.google.com (mail-yw1-x1149.google.com [IPv6:2607:f8b0:4864:20::1149]) by smtp2.osuosl.org (Postfix) with ESMTPS id A302240012 for ; Tue, 10 Oct 2023 22:27:14 +0000 (UTC) DKIM-Filter: OpenDKIM Filter v2.11.0 smtp2.osuosl.org A302240012 Received: by mail-yw1-x1149.google.com with SMTP id 00721157ae682-5a7bcbb95b2so20484297b3.3 for ; Tue, 10 Oct 2023 15:27:14 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1696976833; x=1697581633; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=no1ezg/K8vqwwloDW/HES3GQ/s3OFKPTQdEopkcO670=; b=nuk0xsb6ahM6u+vYiui6YNsnl9G0XTvvGQ9ELR0neT4GrImeEnArXLyo2LgrzklTuv 1rutxWYtq6gxEWsirzmAWgpUkpRrDCgH72SLkgKdWiMlG8CexaHs2rAVopSa43Mx67Lq dWzsfjcpgKjDTDPN8ZS6B6H6FYVeHYrVzX0axfZITJ1vBNvf/HwmVKk0KhRjenFPVUdJ aXxOK6gWnWVGsNOLdFCqOY+PvCx8o7ACML1tFmp1cgWlPm5OEfKhhju8XI50AgVJ8hG1 kPSeRn4+1irwSlFqcVOByMxBhJYBcA8TT1xfP/lxvahRMz6pcHZnLAS1fS17kSYmFXuZ qXYQ== X-Gm-Message-State: AOJu0YxsuHQdbF6eEZ68at4OQRwYR+XrAc/ndlSDOyngpouZEtg2Z2Rc KZge4jzH31g+N3Fl1hAlUUQjB7MNp/LShWM+OQ== X-Google-Smtp-Source: AGHT+IGbG6IYsWKztc9eojIXUzVD3Isy/9hlxzBlyjEVNI0A4VM2MItv3Gt9eZ20f/xkZ1g/F2q2V2ckLAz9494wcg== X-Received: from jstitt-linux1.c.googlers.com ([fda3:e722:ac3:cc00:2b:ff92:c0a8:23b5]) (user=justinstitt job=sendgmr) by 2002:a25:3290:0:b0:d9a:5b63:a682 with SMTP id y138-20020a253290000000b00d9a5b63a682mr53542yby.13.1696976833634; Tue, 10 Oct 2023 15:27:13 -0700 (PDT) Date: Tue, 10 Oct 2023 22:26:59 +0000 In-Reply-To: <20231010-netdev-replace-strncpy-resend-as-series-v1-0-caf9f0f2f021@google.com> Mime-Version: 1.0 References: <20231010-netdev-replace-strncpy-resend-as-series-v1-0-caf9f0f2f021@google.com> X-Developer-Key: i=justinstitt@google.com; a=ed25519; pk=tC3hNkJQTpNX/gLKxTNQKDmiQl6QjBNCGKJINqAdJsE= X-Developer-Signature: v=1; a=ed25519-sha256; t=1696976825; l=1977; i=justinstitt@google.com; s=20230717; h=from:subject:message-id; bh=l7ud0vzH9yZbaC9lpRM0yEoQEtXO/RLFBqfqu9zutis=; b=jQcCLbxmGWObHnArcKoYj2/zN6/Nnp7Y3bIItQSofJOQ0w5NrEaAgjJZ8R6E+xsT14D0zxpeI a7KQJh8W8O7AWC0AJvaq/NMmrGf75By+asp4Xl/fMav25g/6JTazc+A X-Mailer: b4 0.12.3 Message-ID: <20231010-netdev-replace-strncpy-resend-as-series-v1-6-caf9f0f2f021@google.com> From: Justin Stitt To: Jesse Brandeburg , Tony Nguyen , "David S. Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni X-Mailman-Approved-At: Thu, 12 Oct 2023 19:06:39 +0000 X-Mailman-Original-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1696976833; x=1697581633; darn=lists.osuosl.org; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:from:to:cc:subject:date:message-id:reply-to; bh=no1ezg/K8vqwwloDW/HES3GQ/s3OFKPTQdEopkcO670=; b=OO0khsc3IrhIR26Q4wPVt+KfF+7kuyCAuiWiBb1OPg926djLESZxpZjAvlDBUgN8gh dWN+rFwxcrNWRA7ml67Rh7ttA1zX+30r1ovORCCMzZJZS5OyFcqu50+u4sgvVOaxiPFI IRnAFTCe1rwflJReLdRA/RH91Vr3O3njyt9XqFlsVxCfIeYeRisIANI5UMTITbzkwyj4 C5e/r3+vXlQR74MjHM4V7Cd+V10sABWKSWOBo++ufIHGFDrV9rcpL3AD2hQl2SaStpMJ jWgL10JK8Zi5u20ctdEcERsFPRpHfrOl261sew3hvGr+Jpz9ws7p8SIvm3UO37u79d3v o4Ag== X-Mailman-Original-Authentication-Results: smtp2.osuosl.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.a=rsa-sha256 header.s=20230601 header.b=OO0khsc3 Subject: [Intel-wired-lan] [PATCH v1 net-next 6/7] igbvf: replace deprecated strncpy with strscpy X-BeenThere: intel-wired-lan@osuosl.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Intel Wired Ethernet Linux Kernel Driver Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: netdev@vger.kernel.org, Justin Stitt , intel-wired-lan@lists.osuosl.org, linux-hardening@vger.kernel.org, linux-kernel@vger.kernel.org Errors-To: intel-wired-lan-bounces@osuosl.org Sender: "Intel-wired-lan" `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 usage with `strlen` and format strings: | if (strlen(netdev->name) < (IFNAMSIZ - 5)) { | sprintf(adapter->tx_ring->name, "%s-tx-0", netdev->name); Moreover, we do not need NUL-padding as netdev is already zero-allocated: | netdev = alloc_etherdev(sizeof(struct igbvf_adapter)); ... alloc_etherdev() -> alloc_etherdev_mq() -> alloc_etherdev_mqs() -> alloc_netdev_mqs() ... | p = kvzalloc(alloc_size, GFP_KERNEL_ACCOUNT | __GFP_RETRY_MAYFAIL); 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 Tested-by: Pucha Himasekhar Reddy (A Contingent worker at Intel) --- Note: build-tested only. --- drivers/net/ethernet/intel/igbvf/netdev.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/drivers/net/ethernet/intel/igbvf/netdev.c b/drivers/net/ethernet/intel/igbvf/netdev.c index 7ff2752dd763..fd712585af27 100644 --- a/drivers/net/ethernet/intel/igbvf/netdev.c +++ b/drivers/net/ethernet/intel/igbvf/netdev.c @@ -2785,7 +2785,7 @@ static int igbvf_probe(struct pci_dev *pdev, const struct pci_device_id *ent) igbvf_set_ethtool_ops(netdev); netdev->watchdog_timeo = 5 * HZ; - strncpy(netdev->name, pci_name(pdev), sizeof(netdev->name) - 1); + strscpy(netdev->name, pci_name(pdev), sizeof(netdev->name)); adapter->bd_number = cards_found++; From patchwork Tue Oct 10 22:27:00 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Justin Stitt X-Patchwork-Id: 1847757 X-Patchwork-Delegate: anthony.l.nguyen@intel.com Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=osuosl.org header.i=@osuosl.org header.a=rsa-sha256 header.s=default header.b=oIdb7CQp; dkim-atps=neutral Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=osuosl.org (client-ip=2605:bc80:3010::136; helo=smtp3.osuosl.org; envelope-from=intel-wired-lan-bounces@osuosl.org; receiver=patchwork.ozlabs.org) Received: from smtp3.osuosl.org (smtp3.osuosl.org [IPv6:2605:bc80:3010::136]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (secp384r1) server-digest SHA384) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4S5zg44P7Zz23jm for ; Fri, 13 Oct 2023 06:08:00 +1100 (AEDT) Received: from localhost (localhost [127.0.0.1]) by smtp3.osuosl.org (Postfix) with ESMTP id B75C1611C1; Thu, 12 Oct 2023 19:07:58 +0000 (UTC) DKIM-Filter: OpenDKIM Filter v2.11.0 smtp3.osuosl.org B75C1611C1 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=osuosl.org; s=default; t=1697137678; bh=B+w3ioGTY78cx+jfLG7QrjNtyULebmtKvOKFJNl4xzE=; h=Date:In-Reply-To:References:From:To:Subject:List-Id: List-Unsubscribe:List-Archive:List-Post:List-Help:List-Subscribe: Cc:From; b=oIdb7CQpsO+Wr4Vg2LeujDvA6LWRFhhHxDQqEGKGrBnXCEny3swvmFo/9n6cIw+LU 6uuAckW4/mvU+XlP9xEnam+hlmCgwOZ878v/Pr8vLijWDY4++4xORXdFI5GchLUNIt DeOLDAiZQyVC1hSshKHcAC3cgJBHQxcvJvlx9WR1yxJ5tlvVuOswGtfQyQzUTaBdzk v4j4ZQFFKUdcwRwuPg6L0lgEynu6JrjCHwz5EkkZV+kqQoPqWVKQBN8fZ7TRcF+PBT +nqSmy2/oleipOoZnDJ3wP9+Rw6QU3X4QPdpUgf3XJDXq60Ks4UWDrfzU4lQD/Ag6Y 61xjb56bSnZ2A== X-Virus-Scanned: amavisd-new at osuosl.org Received: from smtp3.osuosl.org ([127.0.0.1]) by localhost (smtp3.osuosl.org [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id Ys0QYKP1RKZd; Thu, 12 Oct 2023 19:07:57 +0000 (UTC) Received: from ash.osuosl.org (ash.osuosl.org [140.211.166.34]) by smtp3.osuosl.org (Postfix) with ESMTP id E5BCE6105A; Thu, 12 Oct 2023 19:07:56 +0000 (UTC) DKIM-Filter: OpenDKIM Filter v2.11.0 smtp3.osuosl.org E5BCE6105A X-Original-To: intel-wired-lan@lists.osuosl.org Delivered-To: intel-wired-lan@lists.osuosl.org Received: from smtp2.osuosl.org (smtp2.osuosl.org [140.211.166.133]) by ash.osuosl.org (Postfix) with ESMTP id 1FB241BF25F for ; Tue, 10 Oct 2023 22:27:19 +0000 (UTC) Received: from localhost (localhost [127.0.0.1]) by smtp2.osuosl.org (Postfix) with ESMTP id ED2EB4044D for ; Tue, 10 Oct 2023 22:27:18 +0000 (UTC) DKIM-Filter: OpenDKIM Filter v2.11.0 smtp2.osuosl.org ED2EB4044D X-Virus-Scanned: amavisd-new at osuosl.org Received: from smtp2.osuosl.org ([127.0.0.1]) by localhost (smtp2.osuosl.org [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id E_9dlxzN_nxb for ; Tue, 10 Oct 2023 22:27:16 +0000 (UTC) Received: from mail-yb1-xb4a.google.com (mail-yb1-xb4a.google.com [IPv6:2607:f8b0:4864:20::b4a]) by smtp2.osuosl.org (Postfix) with ESMTPS id 1C48B40012 for ; Tue, 10 Oct 2023 22:27:15 +0000 (UTC) DKIM-Filter: OpenDKIM Filter v2.11.0 smtp2.osuosl.org 1C48B40012 Received: by mail-yb1-xb4a.google.com with SMTP id 3f1490d57ef6-d85fc108f0eso8309439276.2 for ; Tue, 10 Oct 2023 15:27:15 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1696976835; x=1697581635; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=TlakbgGWTqcDQ2xuVKeK3nhNuDzBfPQq0/+GRmlX5C8=; b=cV4DUrSnw/oNaFtfFFWsWBS5Tp5KpRDFWe11l1hUQH/BPB5MXbUDxWHKo9lFN2yjHb dOGTwtapgbvxucM8WC/f4vaar6oFxxvDzvYrhVaPpq5NNpsRm8y0SWxPFHF+f67fIUs/ DYRT1YWkLIaOC2RvD+cr9jHHsTkDOgQu3V26x6YT6f7gry8cKM22ygLGxALNGzoUR0N0 5Lk+1vUeRQOTO3aN9XCkqhtqrrwLDu6W5eqS8u9cOGhdr2v5yu6xvmkLzktjrlflfDnp xWKZajiozWdnU3F3HPf69Iptd93ndMfOYUY/ZWxb2GyT0T77ymKuj42UkWa6nDGLs+/8 Hw5A== X-Gm-Message-State: AOJu0Yz0eBRnGVXjKZH7NjnY3IHpov68yX8jCabizM56kUhX7p6Y7EWz Jrr+KsF0B9rHE9REMmgsr5nrpfjOJMx3jG8Qng== X-Google-Smtp-Source: AGHT+IGzYEq54Il7W2YEgs1cfyYc8gNX6HEw1AL6yXL3SCPfuWpHyotzmuT619yMLidQOlA9hNzRlpWN7L1xRgRrQA== X-Received: from jstitt-linux1.c.googlers.com ([fda3:e722:ac3:cc00:2b:ff92:c0a8:23b5]) (user=justinstitt job=sendgmr) by 2002:a25:a162:0:b0:d85:ad61:1591 with SMTP id z89-20020a25a162000000b00d85ad611591mr315298ybh.11.1696976835057; Tue, 10 Oct 2023 15:27:15 -0700 (PDT) Date: Tue, 10 Oct 2023 22:27:00 +0000 In-Reply-To: <20231010-netdev-replace-strncpy-resend-as-series-v1-0-caf9f0f2f021@google.com> Mime-Version: 1.0 References: <20231010-netdev-replace-strncpy-resend-as-series-v1-0-caf9f0f2f021@google.com> X-Developer-Key: i=justinstitt@google.com; a=ed25519; pk=tC3hNkJQTpNX/gLKxTNQKDmiQl6QjBNCGKJINqAdJsE= X-Developer-Signature: v=1; a=ed25519-sha256; t=1696976825; l=1942; i=justinstitt@google.com; s=20230717; h=from:subject:message-id; bh=6jGMK+cCOOSLNNUn0TBt6IBLIOJaTfgy8BwlGd7P468=; b=35oBACPXlL3wg2v3AbE8axFEM9yJJX/Bfv5dcLDCY+rrP7a8HRLOAFEg/ZA8gNWEWwSfT6QVK J4O6EmvMtglD6nXKST7OY8ieVbM+DsbZ81c8dF/wyiqDDJWJ1HsPtah X-Mailer: b4 0.12.3 Message-ID: <20231010-netdev-replace-strncpy-resend-as-series-v1-7-caf9f0f2f021@google.com> From: Justin Stitt To: Jesse Brandeburg , Tony Nguyen , "David S. Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni X-Mailman-Approved-At: Thu, 12 Oct 2023 19:06:39 +0000 X-Mailman-Original-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1696976835; x=1697581635; darn=lists.osuosl.org; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:from:to:cc:subject:date:message-id:reply-to; bh=TlakbgGWTqcDQ2xuVKeK3nhNuDzBfPQq0/+GRmlX5C8=; b=N0cuKKNORpHLC6glYvyrOeO9GsC041g6RHfVAT1ST6OdUOjkxI66edZsUm9zcMpeww YX5HBjm7kDRUyZjOkR1a0PLLKu3Qv7ybBEloTVedmW6FA0UpP/oWH84perb7+4zKo9fM ViUgurKOSKlyV0UbBXbB+mv7KX8Uubpx/9JgeVVJc4QjcfsBsIGSnGyq7QU2Pw8dywt1 SzIBPUM6w28n6RkyFXu+X0nndPUcCyarqUs9kfrpf9WBqG6zLbv4aq3+XbY1ruml95Qi wW0dZ4urlFklZHTq5nbIlBRz03a8I3TbzL3+oinjPVB8kXg/a/nDb2vUvraG0stHxqFW vl/w== X-Mailman-Original-Authentication-Results: smtp2.osuosl.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.a=rsa-sha256 header.s=20230601 header.b=N0cuKKNO Subject: [Intel-wired-lan] [PATCH v1 net-next 7/7] igc: replace deprecated strncpy with strscpy X-BeenThere: intel-wired-lan@osuosl.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Intel Wired Ethernet Linux Kernel Driver Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: netdev@vger.kernel.org, Justin Stitt , intel-wired-lan@lists.osuosl.org, linux-hardening@vger.kernel.org, linux-kernel@vger.kernel.org Errors-To: intel-wired-lan-bounces@osuosl.org Sender: "Intel-wired-lan" `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: | if (q_vector->rx.ring && q_vector->tx.ring) | sprintf(q_vector->name, "%s-TxRx-%u", netdev->name, Furthermore, we do not need NUL-padding as netdev is already zero-allocated: | netdev = alloc_etherdev_mq(sizeof(struct igc_adapter), | IGC_MAX_TX_QUEUES); ... alloc_etherdev() -> alloc_etherdev_mq() -> alloc_etherdev_mqs() -> alloc_netdev_mqs() ... | p = kvzalloc(alloc_size, GFP_KERNEL_ACCOUNT | __GFP_RETRY_MAYFAIL); 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 Tested-by: Pucha Himasekhar Reddy (A Contingent worker at Intel) --- Note: build-tested only. --- drivers/net/ethernet/intel/igc/igc_main.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/drivers/net/ethernet/intel/igc/igc_main.c b/drivers/net/ethernet/intel/igc/igc_main.c index 98de34d0ce07..e9bb403bbacf 100644 --- a/drivers/net/ethernet/intel/igc/igc_main.c +++ b/drivers/net/ethernet/intel/igc/igc_main.c @@ -6935,7 +6935,7 @@ static int igc_probe(struct pci_dev *pdev, */ igc_get_hw_control(adapter); - strncpy(netdev->name, "eth%d", IFNAMSIZ); + strscpy(netdev->name, "eth%d", sizeof(netdev->name)); err = register_netdev(netdev); if (err) goto err_register;