Received: by 2002:a05:7412:d8a:b0:e2:908c:2ebd with SMTP id b10csp1096682rdg; Wed, 11 Oct 2023 14:31:09 -0700 (PDT) X-Google-Smtp-Source: AGHT+IHCsVyXXmbbFjbJt3qKlXodnyyhlE8niZ7mPCSZO+Doa1TYm1RgMw+gBm+1WJs1/j0oAths X-Received: by 2002:a17:90a:d906:b0:27d:1df4:26f3 with SMTP id c6-20020a17090ad90600b0027d1df426f3mr446663pjv.15.1697059869090; Wed, 11 Oct 2023 14:31:09 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1697059869; cv=none; d=google.com; s=arc-20160816; b=Gqc+mcEecMig2GXXzpgf2tuw9qBQM7lu5LFcP7CJUdzFx5glAl75+Ntkal3YJvoJav KR9lg5xqi449py8KMTpMkajE5OOgyfaiyFLduiSJQPXE8O6jJYX9Dz/zZKWsJk3ZWZrZ q5CZD4q9bHxNK9PSVCsncPMjTIToIyczN62rn7Mt/u+SVb5q5I5JbGTriQNXjyPICwyU b+i/YZbJGv5Aovw3K55G8y+vH7IgrK5eSOwB+QrbmkXjesa9GHr9KkNVENL3Oe+ZIMAD vFTGm0zi7YJY/rqmP4nuxbmDcapY2FMAaqy3ptAa9nFk1gNisU+HTvMi1pbtsRJcqLlH NTkg== 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=gPdeSN+UCM0bKxtteCsEuwrT+LDscm/iwtDfjRU9nwc=; fh=ufOUmWWa4elrFMSUasBCjahYxisbOk3UtCakvGN2+Bk=; b=snjTSdmZBxQeLgJMxyVAiFxMP5c9gWrrW2W6sYwKRWiPm9keNz9NXF52mSc2OpGosO GIwpgshj3Uoa62YXl0n1EOYLDVnvKIjO65GmgjPH43mwvu3aCI8aSq5e3ZEfcDwWy10u duEwOmZh+Vza6uR3RFJhz4hmNHQrhM15pqLo9UPxiYfxHSv4Vlz4Nkzh6mY1IIQrttxz GNS+6rYc164dV2rl8OZqorOnfHsWHCbZ4jmB2MdsmNCmjeP4BhIiWTijY8z5Dn0KX87o eAGgYmpdUT+0kFAMEF8tRFFbyfHHvzHrovDQRQG/3BdhetQgotD/dNSc66HnP0Nfk5MK aCBg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@chromium.org header.s=google header.b=K7Xj88b+; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.38 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 fry.vger.email (fry.vger.email. [23.128.96.38]) by mx.google.com with ESMTPS id nl5-20020a17090b384500b0027b0aac2191si776312pjb.15.2023.10.11.14.31.08 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 11 Oct 2023 14:31:09 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.38 as permitted sender) client-ip=23.128.96.38; Authentication-Results: mx.google.com; dkim=pass header.i=@chromium.org header.s=google header.b=K7Xj88b+; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.38 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 fry.vger.email (Postfix) with ESMTP id BF2F48080D4F; Wed, 11 Oct 2023 14:31:06 -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 S233465AbjJKVbA (ORCPT + 99 others); Wed, 11 Oct 2023 17:31:00 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:45926 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233390AbjJKVa7 (ORCPT ); Wed, 11 Oct 2023 17:30:59 -0400 Received: from mail-oo1-xc30.google.com (mail-oo1-xc30.google.com [IPv6:2607:f8b0:4864:20::c30]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 628969E for ; Wed, 11 Oct 2023 14:30:57 -0700 (PDT) Received: by mail-oo1-xc30.google.com with SMTP id 006d021491bc7-57bb0f5d00aso192512eaf.1 for ; Wed, 11 Oct 2023 14:30:57 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; t=1697059856; x=1697664656; 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=gPdeSN+UCM0bKxtteCsEuwrT+LDscm/iwtDfjRU9nwc=; b=K7Xj88b+hXPMjMC0k1QJMzrw77Cb3aBXW9f6kpjs0n/F27xvEvdVDor93w/DjNFBKh UL9e6BRtL6hMkzFJMVd7qi5bZkjrHvMDfcahaq/qyUrsNTiIZDFUpvO4os3+Couej6Fm yGpnoYKDEP6n8/LpR4w3o93Nsd//CpkaaBMLc= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1697059856; x=1697664656; 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=gPdeSN+UCM0bKxtteCsEuwrT+LDscm/iwtDfjRU9nwc=; b=rCOHrOHcBUu31PUhInSPkAvFTpKKAw4EiOj2z+jkEcFyGP8ir2K0WQuiMz844xoSGo 9vleRyUlwEa4WKSZ8o+ceB47MDk8qamS18sSxsQzumWFJBQfbWRAEWplKbzB4BrIkGJp LSa5bthL8sOK6ZYZ/EsESmCc8KgiUhSxBGH58VcoLaYnaIj2jnL+DfqWPWsynoOH2ntF EoX8RVmadXn9Y2Tman619V8Ndnr0QtzLIUmg+EmwQ5IP84//IADBE5jye3lV//mDHyxL LHkhdbDpBCqPX4F+udtLSpbLMi3afe4DvvM3t5OZihTOu6mpDQpcnY5ZBph1UM7qiN00 53dA== X-Gm-Message-State: AOJu0YwVqclweTmNsZgrwqCNWnsfhCV8wdOlknRAtUC2/0cT3214YULD gs7AN/5jp1RH7r8KVWpgmsohfw== X-Received: by 2002:a05:6358:528d:b0:134:c279:c829 with SMTP id g13-20020a056358528d00b00134c279c829mr30279195rwa.18.1697059855858; Wed, 11 Oct 2023 14:30:55 -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 g9-20020a639f09000000b00565dd935938sm309145pge.85.2023.10.11.14.30.55 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 11 Oct 2023 14:30:55 -0700 (PDT) Date: Wed, 11 Oct 2023 14:30:54 -0700 From: Kees Cook To: Justin Stitt Cc: Tariq Toukan , "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/mlx4_core: replace deprecated strncpy with strscpy Message-ID: <202310111430.C419092@keescook> References: <20231011-strncpy-drivers-net-ethernet-mellanox-mlx4-fw-c-v1-1-4d7b5d34c933@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-mlx4-fw-c-v1-1-4d7b5d34c933@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, URIBL_BLOCKED autolearn=no 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]); Wed, 11 Oct 2023 14:31:06 -0700 (PDT) X-Spam-Level: ** On Wed, Oct 11, 2023 at 09:04:37PM +0000, Justin Stitt wrote: > `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. Yup, since it's only use is for the above report. > > 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 Thanks! Reviewed-by: Kees Cook -- Kees Cook