Received: by 2002:a05:7412:da14:b0:e2:908c:2ebd with SMTP id fe20csp5008rdb; Thu, 5 Oct 2023 14:33:43 -0700 (PDT) X-Google-Smtp-Source: AGHT+IFwbtB9ncHWvRh7B27hfl8Dr/U96txfkDBJodmBKSfPGbftG95tvSOS9clfcrlEpfGsJhDV X-Received: by 2002:a9d:6c0f:0:b0:6c4:d08c:6a2 with SMTP id f15-20020a9d6c0f000000b006c4d08c06a2mr6255726otq.9.1696541622862; Thu, 05 Oct 2023 14:33:42 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1696541622; cv=none; d=google.com; s=arc-20160816; b=LsCX3X7LjKFMJbZ/aEAjKsskT5ER4hg0KwQqntgj9wuL7uCZlC2NDpAoGmwVYfDSJh M528vs9ZLz8cCqU4SDZ5XqLPFAlEp72Gv9cSMm4+6aPQHTxNsBOdFx8mIthymBfrbwmn KyA93CF/EeaJAlLVpP+ApGd8dIcbShRVoGFG5ELSqqLQjS4trKfI/gUBb+S6sXEObNzr 1kBLJ2usPdr9h1DD77LxSbXTDubl/ce+wy0YOAWzvgL2U4YfAHO0cGsRTTzesXrLrbQF WoLqNzc0C4IBxtn0vDsezbW1mbOkYzEEdITrRZxKajGVBkHI2gBPTDIvdmMaNGSy+Ira mxFg== 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=DBeGsTEWaeHMVhG88NcKDZwFuePbfbjL4RyYq3i7W/U=; fh=k0DJpSVuFxhYTyKz71bivhLvl6X/Bx5Sm302pubg0Zg=; b=AB1F9Q/Q84zidQUZ65EHoZ/hJcEpvWdgKg3Mvgo3OljrXx9VOg92ztICwsm/Wcyp9F K0LWHT7iZ5FqLWChqeTxwoN8CiRAcRfmwYL3rGQKQ2I18L6YevWd9My/5TFKqkc68iqP XtLpSaK1vwqkJM/QMQtoY38vfvbpxxY3qYGLTtFbxnM01gWVyMiXWWn3AU8SJtZDg7SX eqx0PHs20OhsM0XvkaEzmTCE5fHI4K8A4D3WSIqZJcGCPuN+bBr91VAUXjeDWTNTfxnt z6HYMrVAGJ7oUxA80tdr4xDhG+3KR8D0ib9qouG/fmkwIHaZZWjm8vv2lbG+qbihmqUk b7qQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20230601 header.b="w7WfL1/G"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.34 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 howler.vger.email (howler.vger.email. [23.128.96.34]) by mx.google.com with ESMTPS id w63-20020a638242000000b00585527553a4si2176924pgd.130.2023.10.05.14.33.42 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 05 Oct 2023 14:33:42 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.34 as permitted sender) client-ip=23.128.96.34; Authentication-Results: mx.google.com; dkim=pass header.i=@google.com header.s=20230601 header.b="w7WfL1/G"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.34 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 howler.vger.email (Postfix) with ESMTP id 5F85380C9DFF; Thu, 5 Oct 2023 14:33:40 -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 S231665AbjJEVdY (ORCPT + 99 others); Thu, 5 Oct 2023 17:33:24 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:59366 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229750AbjJEVdX (ORCPT ); Thu, 5 Oct 2023 17:33:23 -0400 Received: from mail-oo1-xc49.google.com (mail-oo1-xc49.google.com [IPv6:2607:f8b0:4864:20::c49]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id C4D06E9 for ; Thu, 5 Oct 2023 14:33:20 -0700 (PDT) Received: by mail-oo1-xc49.google.com with SMTP id 006d021491bc7-57b739e5637so1762320eaf.2 for ; Thu, 05 Oct 2023 14:33:20 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1696541600; x=1697146400; darn=vger.kernel.org; h=cc:to:from:subject:message-id:mime-version:date:from:to:cc:subject :date:message-id:reply-to; bh=DBeGsTEWaeHMVhG88NcKDZwFuePbfbjL4RyYq3i7W/U=; b=w7WfL1/G6/y1GScimOJYHT+87Q8GMHJNBFsijTmekIyEQMcgZEcTh815QBNPe8vhUD J83dm8TvK7umU+fVBL7mDSyWfYlZX3OVkCvu4a58MXdRkFIqi1lT4IBq3rbbS3LZHg+4 /9Ya1TbRfR5EFgoDapnJDipaTzGaAXv474aJj71A9jt4qC9kOvD2v4LbVGjkKY2PuPIF bSQKwZK/0FrFQs+5Tyids8wKoaVVe8lGJY52MpD8/qcp5TGX4sydFZxaUMBEfH1Mab3G QQEkNkrZFWymaSuqfShJc2qjAUF4S+ZeJn7bFvEQfQAawSTa6ENKyH+j6pMd1LEcsPvL EVeg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1696541600; x=1697146400; h=cc:to:from:subject:message-id:mime-version:date:x-gm-message-state :from:to:cc:subject:date:message-id:reply-to; bh=DBeGsTEWaeHMVhG88NcKDZwFuePbfbjL4RyYq3i7W/U=; b=oTPUVOB17hUMh2+znSlVw6zETzsn6OcW4nOxtA5Fbq4iIXtOBa+i8vCqNTDq617zvt UP0uS0mfS1bpHhpYWHnECulSi8hYDZIXKuBvdsWcgZSCBCxDUf9gO99TBfjdwphNo96b bcFZIvimrrUW8wX+ys8cvOB+tfTBFdxHMPOvOfF92nEyyfKT4Rnt3y9bdxThoQApv4u0 TM8OigTlBeMI97Vg5LfPoa6dR3Gmm/ipc8cOWSdFvUr87FFKdbXAy42B5HRwe94kOl8z qbydmUiLk/B5VPEocykD+p8iJILLXM+x66JZiynD3faOCLiZQ5Qomc+DLth8McS6jm0c u4WA== X-Gm-Message-State: AOJu0YybqPH9gR+XHVE+7UOgkPEUvX8I6pxrebnyXjKjcVW3RucFGm0Q j+ED1QODB7uyZz+V7VQ/mZJMOH60EDeha9gTjA== X-Received: from jstitt-linux1.c.googlers.com ([fda3:e722:ac3:cc00:2b:ff92:c0a8:23b5]) (user=justinstitt job=sendgmr) by 2002:a4a:4f42:0:b0:57b:3840:4c85 with SMTP id c63-20020a4a4f42000000b0057b38404c85mr2335028oob.1.1696541600124; Thu, 05 Oct 2023 14:33:20 -0700 (PDT) Date: Thu, 05 Oct 2023 21:33:19 +0000 Mime-Version: 1.0 X-B4-Tracking: v=1; b=H4sIAJ4rH2UC/x2NQQrCMBAAv1L27EKSoqhfEZGabOxCTepuGpTSv xu9zTCHWUFJmBTO3QpClZVzamJ3HfhxSA9CDs3BGddbY/aoRZKfPxiEK4liooJURpIf+KHy8sS JXwsHzg3yrcWS84Qe74dT77yJRxMttMEsFPn9n1+u2/YFMCiAn4wAAAA= X-Developer-Key: i=justinstitt@google.com; a=ed25519; pk=tC3hNkJQTpNX/gLKxTNQKDmiQl6QjBNCGKJINqAdJsE= X-Developer-Signature: v=1; a=ed25519-sha256; t=1696541598; l=2730; i=justinstitt@google.com; s=20230717; h=from:subject:message-id; bh=PKPsb45o8cJUMR1NbV9bY/ZXdX56wnhP8PdDKS7CtXE=; b=V1BHnD4OOJXpH/xgsaKnRxTqiT9ViCdlfEibIwEOSbm+ZYxyvmHL5E4Z4Ng26ZmlHpUNgDba/ +ghPh0uvDd3Cp21R6QwP2QMeWaE/vV57KKgtRZYIt+iUrL/D/xjBytE X-Mailer: b4 0.12.3 Message-ID: <20231005-strncpy-drivers-net-ethernet-cavium-liquidio-lio_ethtool-c-v1-1-ab565ab4d197@google.com> Subject: [PATCH] liquidio: replace deprecated strncpy/strcpy with strscpy From: Justin Stitt To: Derek Chickles , Satanand Burla , Felix Manlunas , "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=-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-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (howler.vger.email [0.0.0.0]); Thu, 05 Oct 2023 14:33:40 -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. NUL-padding is not required as drvinfo is memset to 0: | memset(drvinfo, 0, sizeof(struct ethtool_drvinfo)); 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/cavium/liquidio/lio_ethtool.c | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) diff --git a/drivers/net/ethernet/cavium/liquidio/lio_ethtool.c b/drivers/net/ethernet/cavium/liquidio/lio_ethtool.c index 9d56181a301f..d3e07b6ed5e1 100644 --- a/drivers/net/ethernet/cavium/liquidio/lio_ethtool.c +++ b/drivers/net/ethernet/cavium/liquidio/lio_ethtool.c @@ -442,10 +442,11 @@ lio_get_drvinfo(struct net_device *netdev, struct ethtool_drvinfo *drvinfo) oct = lio->oct_dev; memset(drvinfo, 0, sizeof(struct ethtool_drvinfo)); - strcpy(drvinfo->driver, "liquidio"); - strncpy(drvinfo->fw_version, oct->fw_info.liquidio_firmware_version, - ETHTOOL_FWVERS_LEN); - strncpy(drvinfo->bus_info, pci_name(oct->pci_dev), 32); + strscpy(drvinfo->driver, "liquidio", sizeof(drvinfo->driver)); + strscpy(drvinfo->fw_version, oct->fw_info.liquidio_firmware_version, + sizeof(drvinfo->fw_version)); + strscpy(drvinfo->bus_info, pci_name(oct->pci_dev), + sizeof(drvinfo->bus_info)); } static void @@ -458,10 +459,11 @@ lio_get_vf_drvinfo(struct net_device *netdev, struct ethtool_drvinfo *drvinfo) oct = lio->oct_dev; memset(drvinfo, 0, sizeof(struct ethtool_drvinfo)); - strcpy(drvinfo->driver, "liquidio_vf"); - strncpy(drvinfo->fw_version, oct->fw_info.liquidio_firmware_version, - ETHTOOL_FWVERS_LEN); - strncpy(drvinfo->bus_info, pci_name(oct->pci_dev), 32); + strscpy(drvinfo->driver, "liquidio_vf", sizeof(drvinfo->driver)); + strscpy(drvinfo->fw_version, oct->fw_info.liquidio_firmware_version, + sizeof(drvinfo->fw_version)); + strscpy(drvinfo->bus_info, pci_name(oct->pci_dev), + sizeof(drvinfo->bus_info)); } static int --- base-commit: cbf3a2cb156a2c911d8f38d8247814b4c07f49a2 change-id: 20231005-strncpy-drivers-net-ethernet-cavium-liquidio-lio_ethtool-c-b6932c0f80f1 Best regards, -- Justin Stitt