Received: by 2002:a05:7412:d8a:b0:e2:908c:2ebd with SMTP id b10csp1098034rdg; Wed, 11 Oct 2023 14:34:18 -0700 (PDT) X-Google-Smtp-Source: AGHT+IFs+L5yImr+f+cKTXi2O/Xau/W7GpzcEVeCyUvIk2/H2LBERskA/HXqL61uFdXUOnv1Czgu X-Received: by 2002:a05:6a00:cc4:b0:68f:d6db:5d66 with SMTP id b4-20020a056a000cc400b0068fd6db5d66mr23987014pfv.16.1697060058643; Wed, 11 Oct 2023 14:34:18 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1697060058; cv=none; d=google.com; s=arc-20160816; b=RMCg9QtSaRsMG0c/+ODs6fAlfRgW2krMC+GNLVBcB9k+147Pe0jYnKj5FHwInb7WiC Klyozxh27hwfvzQowFEC4poqlS7Zn/r+OZ1nEqoEjFpw/dVKh4m9MmMNfrHMng4jmKZA S3ZRyJJjUEXm4FYiPDdYJrOy4JkHoZJN98passRPKLS9C54btV/tXaJAv8yuYwHqZh42 NgkqTPuYi8X8DRM8k5YpDUaeXCT7HGWuQUeYamFzmebli7aw574rLQaunCnAneOOgrol DjiEpOCcf1A1eu/4FtWjLqaaSPUDUwDXHljQmNI2MA4Df39fqZ1HjAcKEm9n2UlLGRxk Dueg== 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=eQIwabRI/uNovp4wm52uUbIH+HnR4FRH6bY2+vy0apE=; fh=MHemj/JEoVJAwCVYlvsnjSfLCw9TpaIXf5q9fSW7sDI=; b=WT9UA8CNJgup7Go70XC++oQi809uMVZYtR+WzTU0UUxcz50ZFDfH8A/9GPXUHvOviu FP30G8N9VSdrF0+1BM03qOYGqrwqFgUksC8pfnegFVdH9PeYweGcM65t7jhfSnZufovo rc9+Vw4wOModmsMXGihMQdxNTVqHFhsxNVy4Xyhg1ZKEGwqwW/FKTOJskoOwXGAE1y5+ IdWag+Jd1mnIV94c3Y/FkDEPCvg1LDZknYJIumg20j3zEwKKwHzLnSGiP+SwrmExqrAF v9Um3xvAXCUJaPdKimo96i9D0xD5V5J7R9lPwYmZS2tYBT/gG/pJ9XZovd9CQI79JNpL PXPQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@chromium.org header.s=google header.b=J6+RQtGu; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:3 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=chromium.org Return-Path: Received: from lipwig.vger.email (lipwig.vger.email. [2620:137:e000::3:3]) by mx.google.com with ESMTPS id e12-20020a63db0c000000b00578b40703bcsi666050pgg.885.2023.10.11.14.34.18 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 11 Oct 2023 14:34:18 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:3 as permitted sender) client-ip=2620:137:e000::3:3; Authentication-Results: mx.google.com; dkim=pass header.i=@chromium.org header.s=google header.b=J6+RQtGu; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:3 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=chromium.org Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by lipwig.vger.email (Postfix) with ESMTP id DF5F781FDBB0; Wed, 11 Oct 2023 14:34:14 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at lipwig.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233426AbjJKVeF (ORCPT + 99 others); Wed, 11 Oct 2023 17:34:05 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:56236 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233321AbjJKVeE (ORCPT ); Wed, 11 Oct 2023 17:34:04 -0400 Received: from mail-oa1-x2c.google.com (mail-oa1-x2c.google.com [IPv6:2001:4860:4864:20::2c]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id B12DAB6 for ; Wed, 11 Oct 2023 14:34:02 -0700 (PDT) Received: by mail-oa1-x2c.google.com with SMTP id 586e51a60fabf-1dd71c0a41fso148069fac.2 for ; Wed, 11 Oct 2023 14:34:02 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; t=1697060042; x=1697664842; darn=vger.kernel.org; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:from:to:cc:subject:date:message-id:reply-to; bh=eQIwabRI/uNovp4wm52uUbIH+HnR4FRH6bY2+vy0apE=; b=J6+RQtGumTMkfg8tgi7jcQS+eWbAO24O99KVnh9jaKR99+ZJZY6JAio7wsqBvUe15e 1NjEniI4g/pQjCqBFo9Ge5bmiAISbilAmNwVssdZGvGbsGbk3hQLCTnstwRhkaiwuMIm XgxrDvYSvt7senZaIjSD9IqGyPhBYgOkLCWuc= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1697060042; x=1697664842; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to; bh=eQIwabRI/uNovp4wm52uUbIH+HnR4FRH6bY2+vy0apE=; b=JyMw7U15+hy8GcyTCyoRsemhWXBTOthHCsvM33jgi+4TxDuZw27AEaeFjsI8Oy3+FF ndZwfmEIdP/Hq91lc6taztAu+9jAphad/AkDX7BtWqT161H/jEN9zGtcHdkLG/UajrWG NA884XSFGbqbgGjLOhy/DF16sZdok2YmUpx4hh79VfWvcV1VNqomTzszti5S8XEG6sju jFs2935Nl5yj3FOpN1lm0vmxcKguejZ1EabDnLBCzLUdncIVdM139L+2HPY2w145QGdF M1tTJwRsYeHmapUglB1mTLmhCh53GmXC5BrkyEVYJR+gySilPONq7CiNep+YKOYVXMd1 cs5Q== X-Gm-Message-State: AOJu0Yy7tfrPJEl/WsFED6AVZYSjZK/N9zxustEJYM84yOZ+QSGGaInN dHghvvELq5yEfk0zLDb5xFbUHA== X-Received: by 2002:a05:6870:7ec2:b0:1e9:7037:6445 with SMTP id wz2-20020a0568707ec200b001e970376445mr5055718oab.20.1697060042036; Wed, 11 Oct 2023 14:34:02 -0700 (PDT) Received: from www.outflux.net (198-0-35-241-static.hfc.comcastbusiness.net. [198.0.35.241]) by smtp.gmail.com with ESMTPSA id r27-20020a638f5b000000b0056b27af8715sm320743pgn.43.2023.10.11.14.34.01 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 11 Oct 2023 14:34:01 -0700 (PDT) Date: Wed, 11 Oct 2023 14:34:00 -0700 From: Kees Cook To: Justin Stitt Cc: 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: <202310111433.9BCCADED@keescook> References: <20231011-strncpy-drivers-net-ethernet-mellanox-mlx5-core-main-c-v1-1-90fa39998bb2@google.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20231011-strncpy-drivers-net-ethernet-mellanox-mlx5-core-main-c-v1-1-90fa39998bb2@google.com> X-Spam-Status: No, score=2.7 required=5.0 tests=DKIMWL_WL_HIGH,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,RCVD_IN_SBL_CSS,SPF_HELO_NONE,SPF_PASS autolearn=no autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lipwig.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 (lipwig.vger.email [0.0.0.0]); Wed, 11 Oct 2023 14:34:15 -0700 (PDT) X-Spam-Level: ** 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 -- Kees Cook