Received: by 2002:a05:7412:518d:b0:e2:908c:2ebd with SMTP id fn13csp549570rdb; Thu, 5 Oct 2023 13:52:06 -0700 (PDT) X-Google-Smtp-Source: AGHT+IFUNyMmvNmD3S3qQc3+fCwHWeuw9bKnQ/Y1rQPet9Aym/yXbEg2QsayFxyqFn1l/tp4YwJQ X-Received: by 2002:a17:90b:1112:b0:278:eb1f:5538 with SMTP id gi18-20020a17090b111200b00278eb1f5538mr6148782pjb.46.1696539126611; Thu, 05 Oct 2023 13:52:06 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1696539126; cv=none; d=google.com; s=arc-20160816; b=lGBTWT+qy8pVR2JvXyStbpDkfhL5lS3zJQSZfzZcZinxY0UjyXSVaW7Yyqg61NLEJA JvT3HoAznk+m/ne7SB6OeHlIyKMf8Hfru5eZjNsW4xJXPPZesv0DDuhlq/yRSlBgnuC5 qaQWkUfKIyEXNd8zZ1/pycueiLUAKdZ4ZV3oE8iPA2M9OOhMYJ+xhxpXvGkdm0z3Bh5u urQhQEyiPFTpoVIuRBEt2nJ6uuwfVkrAeMHEGiS5vOZJmJKZKzwNXNctYZ0vdUXBudmM LIGqMYUTnOvcmEnKA/o+A/ZVxMNaZ7ZVM+nbbztD+HyQaAL5AtudrDlUr8vY1SRYWP/9 XGZg== 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=pWpal7Doqq48f7+hvv3YlQfRBTUj+OxMigJ6y40qk1g=; fh=LHfPMpUMVAjX1GRqeBb2cvalpYllxfW1M8v2DYqSmME=; b=V/Oep044gX4CI/rgPNKI9OhbQ7V14n90rRu05+9Wp45aj3/ZEFZPccVPGOd/DPlEW1 T7xxEmaDDhlvZ9610C4AbkXg6vg65YOZjYAI5n2bAdbzizAq7c0QS6411ZvCb01kDIZh K79AD1S2fB4L3pq5H2vl/qOgkJdfkpgnZRKK2J4YLDxnijqBMKiIivGd7M04LvrazhWN ZWHIAhAvHTnWdaYgokQkBWwugGZ/gdzCprZEWUBRu4Y4AtpTflfP0lh0fDXm4hxyElOG OAqU8mXNccKYdzCEyyh39yQf6Cd7nrygW0UorlkWzycezcftFQXV0/5mSIXuXg6tNf2/ YM4g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20230601 header.b=xG+CTsJT; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:8 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 fry.vger.email (fry.vger.email. [2620:137:e000::3:8]) by mx.google.com with ESMTPS id lp13-20020a17090b4a8d00b00274b23c2867si2531926pjb.58.2023.10.05.13.52.05 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 05 Oct 2023 13:52:06 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:8 as permitted sender) client-ip=2620:137:e000::3:8; Authentication-Results: mx.google.com; dkim=pass header.i=@google.com header.s=20230601 header.b=xG+CTsJT; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:8 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 fry.vger.email (Postfix) with ESMTP id 4BF828080E25; Thu, 5 Oct 2023 13:51:58 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at fry.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230137AbjJEUvq (ORCPT + 99 others); Thu, 5 Oct 2023 16:51:46 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:41414 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229526AbjJEUvp (ORCPT ); Thu, 5 Oct 2023 16:51:45 -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 8F67393 for ; Thu, 5 Oct 2023 13:51:43 -0700 (PDT) Received: by mail-yw1-x114a.google.com with SMTP id 00721157ae682-5a1df5b7830so21461467b3.1 for ; Thu, 05 Oct 2023 13:51:43 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1696539103; x=1697143903; darn=vger.kernel.org; h=cc:to:from:subject:message-id:mime-version:date:from:to:cc:subject :date:message-id:reply-to; bh=pWpal7Doqq48f7+hvv3YlQfRBTUj+OxMigJ6y40qk1g=; b=xG+CTsJTTp+oaimkbFjqus/BKGf8TqNesqXt/WXK02iGj+0jNuNqx68rDw+nVpaPS1 V9PZmIScV5m4mDEa72dLtZYhZsTC1wuSQIojR5uteUiZyR31B8okSDRgRY3cSarlM8I5 u+ef1NxW6CA1qId1ztismbL+bUHCuAuwaTB4ZLpzT0ntY0fcoG68PdkAAkeyim9hzC8m /3gj4/jqGTgXepQLdC+pVYdVdRDphoBel7HxVciyCBKyXV6zsg1WwRoUWZiRA/b+fcvZ tHM3uA9Oq5D9irU5YdzgE5Nj+lXXPvIG0OH32Zr98y5XyNjI2/RfJWYvYm8mdxkL8t/H kRWw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1696539103; x=1697143903; h=cc:to:from:subject:message-id:mime-version:date:x-gm-message-state :from:to:cc:subject:date:message-id:reply-to; bh=pWpal7Doqq48f7+hvv3YlQfRBTUj+OxMigJ6y40qk1g=; b=RkyNRro/9ZCF75zBudasHBByevYX9+wxm/rLR3GkK3wdC5c5dy6SPAhYofgJHZt5ju E+J/OCk70WGnfj4GbMR74ttJVuZ3Y26KU8IeB0Wizt0hQmWMUNbuufg3v0UDB6REkLyR 2d7pTKpRBnz62ZBMkDNW5tPfbcSz64rN8RK8cSC8HJrjvzznJnkYmMcKSwe3nHm79anc HuUX7wzQiHxHuLKDkB5Eh2yStWQejoi+MK7oUsgzWgq9FSslPbARDvAU8eTlf7gm1OIl ZY764UlrkQtkWicuy1LlcTHPDVfsEacFmSgJ54YSgFVW5VUZiAFmI5vlLBRLgD60BI1Z e2Eg== X-Gm-Message-State: AOJu0Yycc2O+c21SPwY4q7MT+QaP4g0nIRXWHvVswo7HfVyH3wyi9m/R 70xQlXYoTtQoMsf3ZyIq6BzZ0xGZ8TsbBUJtnw== X-Received: from jstitt-linux1.c.googlers.com ([fda3:e722:ac3:cc00:2b:ff92:c0a8:23b5]) (user=justinstitt job=sendgmr) by 2002:a81:8d46:0:b0:59b:ec33:ec6d with SMTP id w6-20020a818d46000000b0059bec33ec6dmr120908ywj.5.1696539102785; Thu, 05 Oct 2023 13:51:42 -0700 (PDT) Date: Thu, 05 Oct 2023 20:51:40 +0000 Mime-Version: 1.0 X-B4-Tracking: v=1; b=H4sIANshH2UC/x2NQQqDMBBFryKz7kBiqtBepZQSJ9M6CxOZBEkR7 97Y3Xtv8f8OmVU4w73bQXmTLCk2sZcOaPbxwyihOfSmd9aYAXPRSOsXg8rGmjFyQS4z6wmTJh8 oLTjRMrpaX3xWQuNvAwXn7HU00KZX5bfU/+3jeRw/mVzKc4YAAAA= X-Developer-Key: i=justinstitt@google.com; a=ed25519; pk=tC3hNkJQTpNX/gLKxTNQKDmiQl6QjBNCGKJINqAdJsE= X-Developer-Signature: v=1; a=ed25519-sha256; t=1696539101; l=2256; i=justinstitt@google.com; s=20230717; h=from:subject:message-id; bh=HxayhA1aIuyooSvwu5FkzbNfRLctZ8S9IVA9YM7wlQ4=; b=cNbM0i4jK1A3lEG+pC81fjLHqpJikLXzKR/UUwfLOkhbplaGtwiOVGPOSKdIomtH14tQ9TAvl +Iyswe7yIH0DdajsI7UZ9M2Jp/MQSYuZlg9bAaeb5E2g3FXhQMaWt5V X-Mailer: b4 0.12.3 Message-ID: <20231005-strncpy-drivers-net-ethernet-broadcom-bcm63xx_enet-c-v1-1-6823b3c3c443@google.com> Subject: [PATCH] bcm63xx_enet: replace deprecated strncpy with strscpy From: Justin Stitt To: "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 fry.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 (fry.vger.email [0.0.0.0]); Thu, 05 Oct 2023 13:51: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. A suitable replacement is strscpy() [2] due to the fact that it guarantees NUL-termination on the destination buffer without unnecessarily NUL-padding. bcm_enet_get_drvinfo() already uses strscpy(), let's match it's implementation: | static void bcm_enet_get_drvinfo(struct net_device *netdev, | struct ethtool_drvinfo *drvinfo) | { | strscpy(drvinfo->driver, bcm_enet_driver_name, sizeof(drvinfo->driver)); | strscpy(drvinfo->bus_info, "bcm63xx", sizeof(drvinfo->bus_info)); | } Note that now bcm_enet_get_drvinfo() and bcm_enetsw_get_drvinfo() do the exact same thing. 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 --- drivers/net/ethernet/broadcom/bcm63xx_enet.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/drivers/net/ethernet/broadcom/bcm63xx_enet.c b/drivers/net/ethernet/broadcom/bcm63xx_enet.c index a741070f1f9a..8b18493759bf 100644 --- a/drivers/net/ethernet/broadcom/bcm63xx_enet.c +++ b/drivers/net/ethernet/broadcom/bcm63xx_enet.c @@ -2531,8 +2531,8 @@ static int bcm_enetsw_get_sset_count(struct net_device *netdev, static void bcm_enetsw_get_drvinfo(struct net_device *netdev, struct ethtool_drvinfo *drvinfo) { - strncpy(drvinfo->driver, bcm_enet_driver_name, sizeof(drvinfo->driver)); - strncpy(drvinfo->bus_info, "bcm63xx", sizeof(drvinfo->bus_info)); + strscpy(drvinfo->driver, bcm_enet_driver_name, sizeof(drvinfo->driver)); + strscpy(drvinfo->bus_info, "bcm63xx", sizeof(drvinfo->bus_info)); } static void bcm_enetsw_get_ethtool_stats(struct net_device *netdev, --- base-commit: cbf3a2cb156a2c911d8f38d8247814b4c07f49a2 change-id: 20231005-strncpy-drivers-net-ethernet-broadcom-bcm63xx_enet-c-0a95cd331460 Best regards, -- Justin Stitt