Received: by 2002:ab2:b82:0:b0:1f3:401:3cfb with SMTP id 2csp857996lqh; Thu, 28 Mar 2024 21:09:09 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCV5u8SD70+s+T6z+08vCs3hcJIcwi0eu0drXJhvSWqFMOfXUGpyo/C5EiCj9cneRUoUuugpRt7ZUkP6Fpvegv102gdrCQ3ZW4P8XtDNiA== X-Google-Smtp-Source: AGHT+IHwlA/i+ay3W0UW09In7C44UjzC+bzqVWT1MohLAGWHB0mv04yO5OFZI86m5wbSA1TkH13m X-Received: by 2002:a05:6402:3593:b0:567:3ed0:47ec with SMTP id y19-20020a056402359300b005673ed047ecmr786000edc.23.1711685349100; Thu, 28 Mar 2024 21:09:09 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1711685349; cv=pass; d=google.com; s=arc-20160816; b=TxHrmU+7KfndNhP5Cff6Oyje/0jtx4ymd3s8EtzG3d5s+DY0TRLAUqEHrpZZxljw2J TyAeZJky9Uros+iuozJMhuK7IcdNRVEtWfs2N/xhWRftEf0OdVFyJI9qjvdH/gWx0e92 XGtDwR3jAuM+TqFkjLSXUl03gvT+LhUjYpLWjTa358C0zRFYP3zRYNGd8eoAV+kFqckd G203f5HlDVsq9BBwo+Nbb9SEUolncGLlNHexSpqoxO1p+yioFqioxMttLg04/Mho/T8L mNmmCSggc9E7OuRnFA0abEQubzulad/IfBW/ZZCSyODs/zTzLvWomthYqb2BcFeh2UTd +LWw== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=in-reply-to:content-disposition:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:references:message-id:subject:cc :to:from:date:dkim-signature; bh=8GSIx6Wus4ZS9m3axSqWoJpxC8q7r1Pna+YZvaf3a1g=; fh=DbyABTb2kxT+w3ox6UuybHcxpIFf/eikzRkB3YjO0yU=; b=L80D/kRBi6czz6tnwwkGaB12KUyWrOGhD9+wIXiPHEuz0jVw0DjXP8AKODYIhfV8UI VU+4AMhNpIPhwJUAZyr+Bx6esns46c1S0vbOENdeIhcNnN7lGbumR5tmdEGJStwFy505 lB3avK2l0WJj3kbptZ6uJwACvoJPJh6zRoeJRHZ0BhXuvou853gVWnjPPGYG8IujEN44 DOtaHOS0MPYYgYfh076ts/UcqVzzjGFqGteAOC3N3fqLJliN4oH5AHtx++vDf2mHygUy FmtGo8sITaxRblYC8iyd99EXGupTcRqs6dvITFqVzZZaGrXXSt6/naUDyGrwfc6Ygn9M aDUw==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@chromium.org header.s=google header.b=aBzFRUOc; arc=pass (i=1 spf=pass spfdomain=chromium.org dkim=pass dkdomain=chromium.org dmarc=pass fromdomain=chromium.org); spf=pass (google.com: domain of linux-kernel+bounces-124108-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-124108-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=chromium.org Return-Path: Received: from am.mirrors.kernel.org (am.mirrors.kernel.org. [147.75.80.249]) by mx.google.com with ESMTPS id u7-20020a50d507000000b0056bcecba4a6si1459650edi.552.2024.03.28.21.09.09 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 28 Mar 2024 21:09:09 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-124108-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) client-ip=147.75.80.249; Authentication-Results: mx.google.com; dkim=pass header.i=@chromium.org header.s=google header.b=aBzFRUOc; arc=pass (i=1 spf=pass spfdomain=chromium.org dkim=pass dkdomain=chromium.org dmarc=pass fromdomain=chromium.org); spf=pass (google.com: domain of linux-kernel+bounces-124108-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-124108-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=chromium.org Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by am.mirrors.kernel.org (Postfix) with ESMTPS id BF2C91F225CD for ; Fri, 29 Mar 2024 04:09:08 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id A86293A1D4; Fri, 29 Mar 2024 04:09:02 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=chromium.org header.i=@chromium.org header.b="aBzFRUOc" Received: from mail-pf1-f181.google.com (mail-pf1-f181.google.com [209.85.210.181]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 763392C9A for ; Fri, 29 Mar 2024 04:09:00 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.210.181 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1711685341; cv=none; b=gplxdnB3jgbbXNH0i1hk6aE/Ksl6ve5zqMu3MX0iO0b8TY6Y+ssZswfdqTjDwESy4wQAAgIi65NdrMGi2dejFqWQkVkZMKf4VdA9+T9Z+6wdEU9hEx2MdnX087MTE+AiQeScYo1t6mAHc3/11BnlI0Tm2tUh4BNbRNqs4pz6j9I= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1711685341; c=relaxed/simple; bh=AIXz6hFwPMo/63AZqDwu1il7uoR6aFXlxyvNoJ9wDyc=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=k8pGD55RDRAEvV1Vu2IFzSVmFQArkqxFrsZakEpAmpRpmLakI11/s7a99gOUa+8wZJf+ZvQkb6jqUTfg6gqKVMnF2xwGYWrt1a6hJKnAqkWIRVlo4oo25rB/SNVS7Ks54qSyq46cKXuK08XCDQ4OofCTCZL4J5tBtdUgho1N0TQ= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=chromium.org; spf=pass smtp.mailfrom=chromium.org; dkim=pass (1024-bit key) header.d=chromium.org header.i=@chromium.org header.b=aBzFRUOc; arc=none smtp.client-ip=209.85.210.181 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=chromium.org Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=chromium.org Received: by mail-pf1-f181.google.com with SMTP id d2e1a72fcca58-6e7425a6714so1432025b3a.0 for ; Thu, 28 Mar 2024 21:09:00 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; t=1711685340; x=1712290140; 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=8GSIx6Wus4ZS9m3axSqWoJpxC8q7r1Pna+YZvaf3a1g=; b=aBzFRUOc9XA1X8SoUnr+RreRFORyhYpIxnJyOAkGVi4acPKUgigblZlQTB+bKaL3zU ir/Qqaf5GdrzALbB+cQ8GOFTmyP636z/jLTGdrAPa7asCIXU1CmI/V/1U2fwfqK6nS5s WfhWet3OoHiyMbd0mCLdeZKSqkjNLhkISwsdw= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1711685340; x=1712290140; 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=8GSIx6Wus4ZS9m3axSqWoJpxC8q7r1Pna+YZvaf3a1g=; b=rqutJ4UMKLqMRdGUTFY0MYKWHQu6AoI9UsgLMDkrNegW48FQWW7vDXEveslC0MqVSU 5cgKrqV+qR+rYebfQuKwUVoqV1op49Xa5U1hIJC+gHeiUSjqpEBJSqes/2SgxCLXHHXG OCO4tYUho9VddDDNxMG82slLcMZ6ZcXW+pjC8OnXtwNAb2smNopc/qEBCAllj35Zkvrj cMfw20S/GTRorCKYRQaBb5UQAJyKprjBjZbwZiq10KtXkud/L561D+9aM0Uw5k6YY7lS 1BlSVwYoeWwhPg3Am4qcjE+FldfpTiwoToGXfGLDp13FEMt9DH+PPhKzweBpJOuVsdvu JCWw== X-Forwarded-Encrypted: i=1; AJvYcCXu3qP7POR++a8itmutw3KzJ+aNa6Fec1TM0JC52JFibJSwOLPamAzs+XZKrURA/vR3NL8kND2bv9WMpP2goUPWMpXKx6TJIIzaevnb X-Gm-Message-State: AOJu0YzMjXwFT5WXBke6nbtcopco/oaAvOY5T4cCESQLBf7ug7wM7nxA UWwas5+HqTgBMc2e6sXK29BP/zJ+hc3F8GoN8tpTDoNCfIll6NQcpFRQdy9Qda6eNPfKePZUyxw = X-Received: by 2002:a05:6a21:a59a:b0:1a3:ac89:d478 with SMTP id gd26-20020a056a21a59a00b001a3ac89d478mr1468090pzc.1.1711685339835; Thu, 28 Mar 2024 21:08:59 -0700 (PDT) Received: from www.outflux.net ([198.0.35.241]) by smtp.gmail.com with ESMTPSA id im15-20020a170902bb0f00b001da15580ca8sm2516369plb.52.2024.03.28.21.08.59 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 28 Mar 2024 21:08:59 -0700 (PDT) Date: Thu, 28 Mar 2024 21:08:58 -0700 From: Kees Cook To: Justin Stitt Cc: Tyler Hicks , ecryptfs@vger.kernel.org, linux-kernel@vger.kernel.org, linux-hardening@vger.kernel.org Subject: Re: [PATCH] fs: ecryptfs: replace deprecated strncpy with strscpy Message-ID: <202403282108.7FF7CE596C@keescook> References: <20240321-strncpy-fs-ecryptfs-crypto-c-v1-1-d78b74c214ac@google.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20240321-strncpy-fs-ecryptfs-crypto-c-v1-1-d78b74c214ac@google.com> On Thu, Mar 21, 2024 at 12:38:54AM +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. A good alternative is strscpy() as it guarantees > NUL-termination on the destination buffer. > > In crypto.c: > We expect cipher_name to be NUL-terminated based on its use with > the C-string format specifier %s and with other string apis like > strlen(): > | printk(KERN_ERR "Error attempting to initialize key TFM " > | "cipher with name = [%s]; rc = [%d]\n", > | tmp_tfm->cipher_name, rc); > and > | int cipher_name_len = strlen(cipher_name); > > In main.c: > We can remove the manual NUL-byte assignments as well as the pointers to > destinations (which I assume only existed to trim down on line length?) > in favor of directly using the destination buffer which allows the > compiler to get size information -- enabling the usage of the new > 2-argument strscpy(). > > Note that this patch relies on the _new_ 2-argument versions of > strscpy() and strscpy_pad() introduced in Commit e6584c3964f2f ("string: > Allow 2-argument strscpy()"). > > 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 Looks correct. I don't see any need for padding. Reviewed-by: Kees Cook -- Kees Cook