Received: by 2002:a05:7412:d8a:b0:e2:908c:2ebd with SMTP id b10csp1084337rdg; Wed, 11 Oct 2023 14:04:45 -0700 (PDT) X-Google-Smtp-Source: AGHT+IFPwt4ELV2pmAz3I1gt+FmcHsBoiqKmdUsrxF5LJbPoQzYg3wFQZ7+Xm+avadJSRVQlREeq X-Received: by 2002:a17:902:c952:b0:1c5:d8a3:8783 with SMTP id i18-20020a170902c95200b001c5d8a38783mr31757219pla.11.1697058285192; Wed, 11 Oct 2023 14:04:45 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1697058285; cv=none; d=google.com; s=arc-20160816; b=n/O7FFQMbkkZi3W6iljdKNwJZa+oe3X9/GfVMYR3X9tSe14+BShdQtb6owUVhj0gDV 24I8DsVTKSgrRS007SLB9jXHS0lGBW+aEdRB3sr//gkBnVZA3kO8L1SWUuqOTY1w766T K3j7xIrt/FjQ3XKpvDe4g9sauP+a6ATqh+MwXzBdss7jQHFPDvgyVRTJkY7nqiq8dIHy NEPjsE6m2bc6y4hhooPY/kEWb1TUt2undxuxhtG44f/fzf1+lmGtTyab5GrKNi7qQ0qH qiooERBi4B7GWt7xg9mz9TMilYwC/Z7CZQusGWewBVBpt3IulISTwsAxPc+bbZRJkHXh XW3A== 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=BxaWGDSeY2dIkY2twK1W0ApQNsW9w47t9mTViMZ06zU=; fh=YOPw4mrbEJF6u05F1aiKjCmJ86cucN77OowfTW0L8OU=; b=D6je774tUrWu210pqb0M4hgwJjA8ur0kJ4mN967cLhqVQHVERhxwTIepNiFPmM12yM tK7Cb5O7llODJP1TX+UM26/pQ531B1pm2A07MnFnmzKkzf36jlPVTdQXcHlRNrC8DbD/ QlcEftcx1F52AIaC4eaz0alFhbrfzC6J+gU7Eox77rhcgeNSmtDKsmUwVFgDes9dUWhi +FRu2BvkOEfAXrtMeVImFAmxaGA+8BHTKoSz/+fn3S98jNmK/+kVD/ydz2pDu0t7Ogvd vYSx8Z5rrzRiT3b63FFY942FU7wmhZk3TZB+yO6dzxwIsar+MERmc4TomS9UiMxne7fn 4DNw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20230601 header.b=pTRnspRK; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:7 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 snail.vger.email (snail.vger.email. [2620:137:e000::3:7]) by mx.google.com with ESMTPS id k16-20020a170902761000b001bbcddc33dasi499581pll.180.2023.10.11.14.04.44 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 11 Oct 2023 14:04:45 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:7 as permitted sender) client-ip=2620:137:e000::3:7; Authentication-Results: mx.google.com; dkim=pass header.i=@google.com header.s=20230601 header.b=pTRnspRK; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:7 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 snail.vger.email (Postfix) with ESMTP id 484F081E5917; Wed, 11 Oct 2023 14:04:44 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at snail.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233306AbjJKVEm (ORCPT + 99 others); Wed, 11 Oct 2023 17:04:42 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:57114 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233278AbjJKVEk (ORCPT ); Wed, 11 Oct 2023 17:04:40 -0400 Received: from mail-yw1-x114a.google.com (mail-yw1-x114a.google.com [IPv6:2607:f8b0:4864:20::114a]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 7ED4E9E for ; Wed, 11 Oct 2023 14:04:39 -0700 (PDT) Received: by mail-yw1-x114a.google.com with SMTP id 00721157ae682-5a7ac9c1522so4467247b3.0 for ; Wed, 11 Oct 2023 14:04:39 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1697058278; x=1697663078; darn=vger.kernel.org; h=cc:to:from:subject:message-id:mime-version:date:from:to:cc:subject :date:message-id:reply-to; bh=BxaWGDSeY2dIkY2twK1W0ApQNsW9w47t9mTViMZ06zU=; b=pTRnspRKfDoJ3DiY2sGbABeR0vRBs5KytRvmTbcy4qcz8mCnaD0IYssPeKUbiiHpet 3OKQFgagX6LnyqJvGsspp6CmB1ev/hyu70aR9Bg7E4iy76wnfgiQMTyR+zr3M68bdgaB OZLQGZYPp9LgUn7FlK5ZhhXyso8TtDFDi8JE077S1FM1ZpBvhQHIcUOReZ7swkbcrw/F f+vM/4grWm0UNcGJ8BGaIOtuJ2daMqvGjm4pnFCYc5/76L54TyiLe0uw1i/Rq0ygVWah 35FfXP2T51hzFniuT/KAJbhXuFwXVhp5QNhQMmkDELd1TLjqPQV4VB4dbyJHD2E4Xrm2 /qXg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1697058278; x=1697663078; h=cc:to:from:subject:message-id:mime-version:date:x-gm-message-state :from:to:cc:subject:date:message-id:reply-to; bh=BxaWGDSeY2dIkY2twK1W0ApQNsW9w47t9mTViMZ06zU=; b=CnqOuhDVt2eYkhyLlKk+vMlBJS5JXYYPN13l2oMlhXd+dVYTbLPn9jmkd3GyJGE2jb eM5/QXZ9S/XdDhbjaM2T39wEO6lVcENohki3hspKqPGdRpT5JciOEdhmkJWaxzp8cxKV Aq+HZgKL+YtfDi1iq3qBHE0CwfXoYIadaZn4g5cOXlZocuYgSCMqrcOTJtN6Sx0MmFee trNr1yUcnk2ZnXYYPyPb9z2KyHMVwUOTdqetj2AS+n7yiZhB6eTjsj9EWaniCsWjfTNe uThL8wi+9QozhXQrf3aw8j2fW5kobRFZq/9jUDjOnCQtzpvoe/YJwfrViotw73ZfPs8R xJDQ== X-Gm-Message-State: AOJu0Yy2Xa1OP/FkzTZIp/p1ZwkeSnGKftgVlyKl41/fpXQ+Ppr3zzN0 gRTyehm99nxJ5vluFUoIMjk9PqRu9BJZ1Z7FEQ== X-Received: from jstitt-linux1.c.googlers.com ([fda3:e722:ac3:cc00:2b:ff92:c0a8:23b5]) (user=justinstitt job=sendgmr) by 2002:a81:a909:0:b0:59b:e97e:f7e3 with SMTP id g9-20020a81a909000000b0059be97ef7e3mr403659ywh.2.1697058278584; Wed, 11 Oct 2023 14:04:38 -0700 (PDT) Date: Wed, 11 Oct 2023 21:04:37 +0000 Mime-Version: 1.0 X-B4-Tracking: v=1; b=H4sIAOUNJ2UC/x2NQQ6CMBAAv0L27CYtiopfIR6adpFNykK2DdYQ/ m71NnOZ2SGRMiV4NDsobZx4kSr21ICfnLwIOVSH1rRna6zFlFX8+sGgvJEmFMpIeSL9wUwxOlk KzrFccHyjx+vtbvqu60OwDmp1VRq5/I/D8zi+U+4EDIEAAAA= X-Developer-Key: i=justinstitt@google.com; a=ed25519; pk=tC3hNkJQTpNX/gLKxTNQKDmiQl6QjBNCGKJINqAdJsE= X-Developer-Signature: v=1; a=ed25519-sha256; t=1697058277; l=1896; i=justinstitt@google.com; s=20230717; h=from:subject:message-id; bh=iM4RgTWWhWZP4eA/MAnbDxA0QWNmel85KFAk0bSECCw=; b=Mi1kOWdyu5N3mq/FWAZBWweOspZuCsbEWolDFFAMzhwq3MN2xlS5N+hX0SBc+sEuxPp+FXaxs S1P44k6m1RVCBibuSe6W6nXbwXsKcpeyoPtF3ALMhXIAUT5jMNiVGKY X-Mailer: b4 0.12.3 Message-ID: <20231011-strncpy-drivers-net-ethernet-mellanox-mlx4-fw-c-v1-1-4d7b5d34c933@google.com> Subject: [PATCH] net/mlx4_core: replace deprecated strncpy with strscpy From: Justin Stitt To: Tariq Toukan , "David S. Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni Cc: netdev@vger.kernel.org, linux-rdma@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=-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 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 (snail.vger.email [0.0.0.0]); Wed, 11 Oct 2023 14:04:44 -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 `dst` to be NUL-terminated based on its use with format strings: | mlx4_dbg(dev, "Reporting Driver Version to FW: %s\n", dst); Moreover, NUL-padding is not required. 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. Found with: $ rg "strncpy\(" --- drivers/net/ethernet/mellanox/mlx4/fw.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/drivers/net/ethernet/mellanox/mlx4/fw.c b/drivers/net/ethernet/mellanox/mlx4/fw.c index fe48d20d6118..0005d9e2c2d6 100644 --- a/drivers/net/ethernet/mellanox/mlx4/fw.c +++ b/drivers/net/ethernet/mellanox/mlx4/fw.c @@ -1967,7 +1967,7 @@ int mlx4_INIT_HCA(struct mlx4_dev *dev, struct mlx4_init_hca_param *param) if (dev->caps.flags2 & MLX4_DEV_CAP_FLAG2_DRIVER_VERSION_TO_FW) { u8 *dst = (u8 *)(inbox + INIT_HCA_DRIVER_VERSION_OFFSET / 4); - strncpy(dst, DRV_NAME_FOR_FW, INIT_HCA_DRIVER_VERSION_SZ - 1); + strscpy(dst, DRV_NAME_FOR_FW, INIT_HCA_DRIVER_VERSION_SZ); mlx4_dbg(dev, "Reporting Driver Version to FW: %s\n", dst); } --- base-commit: cbf3a2cb156a2c911d8f38d8247814b4c07f49a2 change-id: 20231011-strncpy-drivers-net-ethernet-mellanox-mlx4-fw-c-67809559dd1a Best regards, -- Justin Stitt