Received: by 2002:a05:7412:8d10:b0:f3:1519:9f41 with SMTP id bj16csp1954276rdb; Thu, 7 Dec 2023 13:39:15 -0800 (PST) X-Google-Smtp-Source: AGHT+IHITBrZWoLHtVZnhD0khv9GDRSqQV4UTWZ6RH6qngFfYF77mWahSNPFMeHUMv5fjTnrzxT0 X-Received: by 2002:a17:902:e80a:b0:1d0:c502:e0b6 with SMTP id u10-20020a170902e80a00b001d0c502e0b6mr3415584plg.103.1701985155377; Thu, 07 Dec 2023 13:39:15 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1701985155; cv=none; d=google.com; s=arc-20160816; b=Hl4XzK/2t+LHt8Li5GO+3p4GiBNdZVA6dFBbd3w5JG4WaBRhVFlC9tV86CKoNu1HSa tHHaWKpDWDYYTAO4OdhiHcfOBUDAW2Tlh/K+e1jm147c3LuOAVFCDQY1WnLBnuZrcJhh KQJRBd+Ex356Frex1qGNVrvKS4qV4iT5VsYVu7lZSC8x4ppkRoovbnVpezo1/7wehpSU Wyn4hCJiMQw5NflOt9OzOxM+4KlG+4iWAC64zAYStqvtMEowcKqcpgUZ/YP3lkbF17Ex 58HamBdIYApk12nJPWLKbFNUsgTQowpWhe3nXWDCaNbvCUphcBmptkJPoCRGEv/BuWlr Av6g== 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=+dxQ+lFxuekIJsQrZiGvKP2+R83S4w5OOR8cyBrT1oo=; fh=+OUo/PzwcJKu1Fgs9b6msIhcO3wUdtMNASRynnq6q6M=; b=dC0ymMsuLcjvnQPW6Y3Bp3ZE2pHw9wcesv8v24kAhEsvNNML44tWs/yH8cSE5vYeKO 0ctAylrb5uljkfXHFIR9Z+VXsl75za4jPmgRfUQXDFNAxbAqhIHO/I/BMG+b6OSykdbe XbMNVWtAsqfAA/IJD9S5UolBfpFm5zU1BzdSSYtL6u+8lLMeTawtyRkJEfYzQ9cen3W1 lAV+LHLpI9Tau+4yPzRjJJuKC927pEOBh1yQFa1Qid9T4MvBAxeJgdEl309jnscgr+IL XMw0HJTOVPp/Yn9JlkfH4LTWv9IErqUdM6Dn059mkxkhJaoA7QpRYCOzetns8e7ALKcS JJbg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20230601 header.b=s+igP09J; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:5 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 groat.vger.email (groat.vger.email. [2620:137:e000::3:5]) by mx.google.com with ESMTPS id p19-20020a170902b09300b001c36018fdaasi372080plr.219.2023.12.07.13.39.15 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 07 Dec 2023 13:39:15 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:5 as permitted sender) client-ip=2620:137:e000::3:5; Authentication-Results: mx.google.com; dkim=pass header.i=@google.com header.s=20230601 header.b=s+igP09J; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:5 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 groat.vger.email (Postfix) with ESMTP id A266480236C9; Thu, 7 Dec 2023 13:39:10 -0800 (PST) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.11 at groat.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1444054AbjLGVi3 (ORCPT + 99 others); Thu, 7 Dec 2023 16:38:29 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:45602 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235761AbjLGViI (ORCPT ); Thu, 7 Dec 2023 16:38:08 -0500 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 BDFDC47B5 for ; Thu, 7 Dec 2023 13:34:44 -0800 (PST) Received: by mail-yw1-x1149.google.com with SMTP id 00721157ae682-5d33b70fce8so15744377b3.0 for ; Thu, 07 Dec 2023 13:34:44 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1701984884; x=1702589684; darn=vger.kernel.org; h=cc:to:from:subject:message-id:mime-version:date:from:to:cc:subject :date:message-id:reply-to; bh=+dxQ+lFxuekIJsQrZiGvKP2+R83S4w5OOR8cyBrT1oo=; b=s+igP09JeB7W1ja3SIjcYioWkjyYxBhF6Hb8HT7jCDIrnyMsSGw8J0vAg1jr38+en8 mHLGLx3SYCzuMHzIB1LjVdqQwNv6o5X5G+0IKfFct9lhqb/TZ7M+B3PWYiCSQspjDNsa RpRs/TYJw9NgXe8HklByOP3c8+bNQ4TRncB/4MAXH9OURwcjjtBNLWsFOB+LqVFSsfm0 5SBxEPX5RhtTznqN0kWawiWTYSNBNJpq3N9pz4H4GjMO4qr02WB0EDOy0WJxWHWTHVpB 5eWyM34jkZ9bM0Nid4lQdzsuPT6iIswPjRl/TYASTGBv+XiMR55rFSmeKMBXYl6FvkZp VOqQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1701984884; x=1702589684; h=cc:to:from:subject:message-id:mime-version:date:x-gm-message-state :from:to:cc:subject:date:message-id:reply-to; bh=+dxQ+lFxuekIJsQrZiGvKP2+R83S4w5OOR8cyBrT1oo=; b=WT7hOYiMwlTZRuSVsr92/+djzYJOYI+ZD/VhVAYBDDjzWIKDp1JFvEMK478YWVTAX8 fr1/nn/OV5j1+kIY40R8nFLJc4Tp6TdFQysMLUCQBKLKyYNccYuCCMfPQFfsrm8gpXQR v6GU5jv3Br8udvrO211FSAMEnIVyzhyiQcycrrpSlpXf/M8XgLplSo0hprd+h7hdGLfy OQlKfdY970LgmxXZVNEalaE3fUjuD6tFtMhn7s7GEiuJ4B60hAtBHvUkYcfbWIBQV5oa 29KVc9T0QxJWkNlIO9yDFRZGTZ1TfSUmJoNg3DbB9EJhbFKSy48tc33bctTWB9Cbszq5 Hw3g== X-Gm-Message-State: AOJu0YySPM2Vvsvi1m1kd/CYKqzMFfoef4ClHTBd5TVvkPPG53g4EO+E VGL21BVG1aIbHnlKXtJrDKdDszSyTXuUHyQQRg== X-Received: from jstitt-linux1.c.googlers.com ([fda3:e722:ac3:cc00:2b:ff92:c0a8:23b5]) (user=justinstitt job=sendgmr) by 2002:a25:3144:0:b0:db3:f436:5714 with SMTP id x65-20020a253144000000b00db3f4365714mr45374ybx.0.1701984883901; Thu, 07 Dec 2023 13:34:43 -0800 (PST) Date: Thu, 07 Dec 2023 21:34:42 +0000 Mime-Version: 1.0 X-B4-Tracking: v=1; b=H4sIAHE6cmUC/6WOTQ6DIBSEr2JY9zVgKf6seo/GNBRflaSCeRBSa 7x70St0Mcl8s5iZlQUki4G1xcoIkw3WuwzlqWBm1G5AsH1mVvLyIji/QojkzLxATzYhBXAYAeO ItBs96a93gE7veuSoxwQGlJE1l1IprSuWq2fCl/0cs/cu82hD9LQcL5LY0z8HkwABTy3rqmkqK RS/Dd4PbzwbP7Fu27YfgaQtMPkAAAA= X-Developer-Key: i=justinstitt@google.com; a=ed25519; pk=tC3hNkJQTpNX/gLKxTNQKDmiQl6QjBNCGKJINqAdJsE= X-Developer-Signature: v=1; a=ed25519-sha256; t=1701984883; l=2405; i=justinstitt@google.com; s=20230717; h=from:subject:message-id; bh=NfdFJEILBicX+cKI9Lam0xi1N5rwWJPZbrcrKRNR7ek=; b=USHVW9EnVVap8XHQCQKZwCMqui5mXIlCs8pOQqrQSBk37cDVheZxNNOSUifYJos12XxU1VyCf mt+BoGh3e/1Bu0+A0U+bcdSiCoC3A3xOy3rdcwDhwzLsK7PZ95BW9iF X-Mailer: b4 0.12.3 Message-ID: <20231207-strncpy-drivers-net-ethernet-amazon-ena-ena_netdev-c-v2-1-a1f2893d1b70@google.com> Subject: [PATCH v2] net: ena: replace deprecated strncpy with strscpy From: justinstitt@google.com To: Shay Agroskin , Arthur Kiyanovski , David Arinzon , Noam Dagan , Saeed Bishara , "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,T_SCC_BODY_TEXT_LINE, 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 groat.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 (groat.vger.email [0.0.0.0]); Thu, 07 Dec 2023 13:39:11 -0800 (PST) `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. host_info allocation is done in ena_com_allocate_host_info() via dma_alloc_coherent() and is not zero initialized by alloc_etherdev_mq(). However zero initialization of the destination doesn't matter in this case, because strscpy() guarantees a NULL termination. 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 --- Changes in v2: - update commit message, dropping inaccurate statement about allocation (thanks Arthur) - copy/paste Arthur's explanation regarding host_info allocation into - rebased onto mainline - Link to v1: https://lore.kernel.org/r/20231005-strncpy-drivers-net-ethernet-amazon-ena-ena_netdev-c-v1-1-ba4879974160@google.com --- Note: build-tested only. --- drivers/net/ethernet/amazon/ena/ena_netdev.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/drivers/net/ethernet/amazon/ena/ena_netdev.c b/drivers/net/ethernet/amazon/ena/ena_netdev.c index b5bca4814830..4a41efcc996b 100644 --- a/drivers/net/ethernet/amazon/ena/ena_netdev.c +++ b/drivers/net/ethernet/amazon/ena/ena_netdev.c @@ -3276,8 +3276,8 @@ static void ena_config_host_info(struct ena_com_dev *ena_dev, struct pci_dev *pd strscpy(host_info->kernel_ver_str, utsname()->version, sizeof(host_info->kernel_ver_str) - 1); host_info->os_dist = 0; - strncpy(host_info->os_dist_str, utsname()->release, - sizeof(host_info->os_dist_str) - 1); + strscpy(host_info->os_dist_str, utsname()->release, + sizeof(host_info->os_dist_str)); host_info->driver_version = (DRV_MODULE_GEN_MAJOR) | (DRV_MODULE_GEN_MINOR << ENA_ADMIN_HOST_INFO_MINOR_SHIFT) | --- base-commit: bee0e7762ad2c6025b9f5245c040fcc36ef2bde8 change-id: 20231005-strncpy-drivers-net-ethernet-amazon-ena-ena_netdev-c-6c4804466aa7 Best regards, -- Justin Stitt