Received: by 2002:a05:7412:d8a:b0:e2:908c:2ebd with SMTP id b10csp533068rdg; Thu, 12 Oct 2023 12:46:25 -0700 (PDT) X-Google-Smtp-Source: AGHT+IHkLwxzOYas80Qj7oEAwPkJlcCxA7HB6rKFBwMlkE4UragkPUA2q+CSFof29TCoCVv7JuQ+ X-Received: by 2002:a05:6358:9226:b0:140:fbfe:d941 with SMTP id d38-20020a056358922600b00140fbfed941mr28051762rwb.20.1697139985261; Thu, 12 Oct 2023 12:46:25 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1697139985; cv=none; d=google.com; s=arc-20160816; b=ycRCsLH3mae5E0awT0+IzzHFG8GVDcaOxBcD/Fp4gneezpYYlcFGk34IXtEr7xlih5 ZjbaAwSKRaL4fP7Dfj3DhtTt8w/hGcCK2kqAymPgGJ7SSF2u73uNdssoUuhHkoiVEnjs 9VjhnubR2rKyABT1f4+QHUWPh5hMYZgxf0YzS7oGgcsE47p0nBCuO8lvy0YVArwQzBZi k3dxl/EGWUgT0HNJ+8TyOxx3FXejO/UcXQLB8BRomKWflDEJuhsdAkat+neQjyiXcKqW 8vTyJPPlpuOMY5XpXNL5HbJGgTV4fRmDnmnSHNsLNwtH/nfPN/vGG1Ru8W6G0SI/N4fs mG9Q== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:content-disposition:mime-version :references:message-id:subject:cc:to:from:date:dkim-signature; bh=Hb8YWFSOkX0NCFe664tfyCaUwbxDGI6uksbPYrW075k=; fh=+lCZWWhx/vLLr40t5iuAZ/s+NUym/My/eLSlCwQ8R/I=; b=Bm0c+Grv+SMSzTuZwH20gd8nIVVuxbjJxnd3gKjBs8qNFjEpI7xr+TCj4rR5RvHyIY jgCypV1pMxIDJF8hdbFwWuxCXEGAYz0jIDTfKmvV0fBeZxCRAmJ5fx1AzxeZXzNpGU3M uiOTM//izROPPkDekEgAwYnvq82VJHdKYvbl63Du+B65TP/kbWLZotREzjeO4WbohelU RgjdhMJxhlw8dnDGXihl/FnYrPoaSq1tacPutIBB7baWKhDQ1MFhsP+2kmGRdscMIwYX 1Lc1Ma7IYL99SiT+oUobxs8kiMRota09QnmloRzzMsHg9v5OShLfJW+9I0PasdpCKJe/ 7hVA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=kZocO850; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:1 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from morse.vger.email (morse.vger.email. [2620:137:e000::3:1]) by mx.google.com with ESMTPS id t185-20020a6381c2000000b0059ff6fc79a4si612950pgd.138.2023.10.12.12.46.24 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 12 Oct 2023 12:46:25 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:1 as permitted sender) client-ip=2620:137:e000::3:1; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=kZocO850; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:1 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by morse.vger.email (Postfix) with ESMTP id 201458065113; Thu, 12 Oct 2023 12:46:21 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at morse.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1442223AbjJLTqL (ORCPT + 99 others); Thu, 12 Oct 2023 15:46:11 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:41706 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1442179AbjJLTqK (ORCPT ); Thu, 12 Oct 2023 15:46:10 -0400 Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id DA656BB; Thu, 12 Oct 2023 12:46:08 -0700 (PDT) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 5BDC0C433C8; Thu, 12 Oct 2023 19:46:08 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1697139968; bh=Hb8YWFSOkX0NCFe664tfyCaUwbxDGI6uksbPYrW075k=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=kZocO850l59r8X57kjE5ZHEhxS1ourUskkUlbF9XsHMaxFYfv7tk1JfGUIilQ95Fm OhT1xN/ZJw+n7cLMGtmRZ7BZynxXKq1JSfN26i+yT3m1yAxRtbCZ/E7aHhpuxNh1+O iZr9TxNVSICEyrmyiII3/f34h+0qIM72vwFfOaKClFKF0BR6hfWLCEmY2YGXDe4rDm 46t5P4lPwm75/s1ZQLQsxzNerThKAs0wWIFCEBlIVREWghjP6K9H6MbtSbWrU0JFEO TvK6dJgsOTMm/VBvksJJ8x6WBFNuAEzY0X0GQ55+axRVirzOFdYJQ7X7cxha/5ZOfm TWBAkonvsJMjQ== Date: Thu, 12 Oct 2023 12:46:07 -0700 From: Saeed Mahameed To: Kees Cook Cc: Justin Stitt , Saeed Mahameed , Leon Romanovsky , "David S. Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni , netdev@vger.kernel.org, linux-rdma@vger.kernel.org, linux-kernel@vger.kernel.org, linux-hardening@vger.kernel.org Subject: Re: [PATCH] net/mlx5: simplify mlx5_set_driver_version string assignments Message-ID: References: <20231011-strncpy-drivers-net-ethernet-mellanox-mlx5-core-main-c-v1-1-90fa39998bb2@google.com> <202310111433.9BCCADED@keescook> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii; format=flowed Content-Disposition: inline In-Reply-To: <202310111433.9BCCADED@keescook> X-Spam-Status: No, score=-1.2 required=5.0 tests=DKIMWL_WL_HIGH,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,MAILING_LIST_MULTI, SPF_HELO_NONE,SPF_PASS autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on morse.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 (morse.vger.email [0.0.0.0]); Thu, 12 Oct 2023 12:46:21 -0700 (PDT) On 11 Oct 14:34, Kees Cook wrote: >On Wed, Oct 11, 2023 at 09:29:57PM +0000, Justin Stitt wrote: >> In total, just assigning this version string takes: >> (1) strncpy()'s >> (5) strlen()'s >> (3) strncat()'s >> (1) snprintf()'s >> (4) max_t()'s >> >> Moreover, `strncpy` is deprecated [1] and `strncat` really shouldn't be >> used either [2]. With this in mind, let's simply use a single >> `snprintf`. > >Yes, please! readability++ > >> >> Link: https://www.kernel.org/doc/html/latest/process/deprecated.html#strncpy-on-nul-terminated-strings [1] >> Link: https://elixir.bootlin.com/linux/v6.6-rc5/source/include/linux/fortify-string.h#L448 [2] >> Link: https://github.com/KSPP/linux/issues/90 >> Cc: linux-hardening@vger.kernel.org >> Cc: Kees Cook >> Signed-off-by: Justin Stitt > >Reviewed-by: Kees Cook Applied to net-next-mlx5.