From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id ABF2CCDB483 for ; Wed, 11 Oct 2023 21:31:01 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233549AbjJKVbA (ORCPT ); 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-Google-Smtp-Source: AGHT+IHgiaS0J9V8G4ieZfMxkP6YJcYFtXZ8HWNnNVZcyH53BKixjx9bhz+wn0W15U33LD4O25xHlw== 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> Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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