From nobody Tue Dec 2 01:06:06 2025 Received: from out-186.mta0.migadu.com (out-186.mta0.migadu.com [91.218.175.186]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id E374F2248B9 for ; Fri, 21 Nov 2025 16:20:13 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=91.218.175.186 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1763742016; cv=none; b=N4z5jGn01VpkWQQlESPNedOGAGe7B8wqa7ENdcDfDDNA5plWR7YF9OED2qFxAJ7L3PObTSzT6+7Q/ZOxkLlWe5FpfmoNMOso/nC+9dxTppyDe68bGQtnHWAEszWBokfBX4050U0i2J7AB5OYtRdLipLiQaqsiAtxPWtdBBcYbtk= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1763742016; c=relaxed/simple; bh=J/5S/u6Q+OIzq+Q+wU7ePKaK014Vl8L/R9/eMFGqH14=; h=From:To:Cc:Subject:Date:Message-ID:MIME-Version; b=KS6B5Hwq5T9cHdXW6U5INTqea8MbK8tihwzXDqDUeP1rR5rl4i0Ii0uRSDl43yLq8COlDjnLeZodRKjUYNyBWW49ppy8UkYkz1h42G28wKgxy/UK6osJu1QDiW9Rx5dRwICqXuDkv+iVgab0B1psBxx4/hkd7VFKJCIm2LyeQMM= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.dev; spf=pass smtp.mailfrom=linux.dev; dkim=pass (1024-bit key) header.d=linux.dev header.i=@linux.dev header.b=LdFDw/ag; arc=none smtp.client-ip=91.218.175.186 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.dev Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linux.dev Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linux.dev header.i=@linux.dev header.b="LdFDw/ag" X-Report-Abuse: Please report any abuse attempt to abuse@migadu.com and include these headers. DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.dev; s=key1; t=1763742000; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding; bh=eEjfhRUSaGwQCWk0YFKSL1lurIZX+cS+kJYHPQWEiUY=; b=LdFDw/agTalgjoX/1E1NgR5U+v0VGYA/Ibo+ZFAPEEzgfv1d4SJlhNO/kvnAFwFIXcb420 7jP7rezWut5trAbgmjy+DWoS3bsDKOA/xojTu3EX1/9hwUzTLxxgmPpwBW1SEG3RjwzZUI w3J30IODfj72pFW+uoH1fA1FQEppbMo= From: Thorsten Blum To: Tyler Hicks , Christian Brauner , Eric Biggers , Ard Biesheuvel Cc: Thorsten Blum , ecryptfs@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH] ecryptfs: Replace memcpy + NUL termination in ecryptfs_new_file_context Date: Fri, 21 Nov 2025 17:19:21 +0100 Message-ID: <20251121161923.44719-2-thorsten.blum@linux.dev> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Migadu-Flow: FLOW_OUT Content-Type: text/plain; charset="utf-8" Use strscpy() to copy the NUL-terminated '->global_default_cipher_name' to the destination buffer instead of using memcpy() followed by a manual NUL termination. Remove the now-unused local variable 'cipher_name_len'. Signed-off-by: Thorsten Blum --- fs/ecryptfs/crypto.c | 9 ++------- 1 file changed, 2 insertions(+), 7 deletions(-) diff --git a/fs/ecryptfs/crypto.c b/fs/ecryptfs/crypto.c index c99fc60a4e3b..2af9ed4c7ed7 100644 --- a/fs/ecryptfs/crypto.c +++ b/fs/ecryptfs/crypto.c @@ -751,7 +751,6 @@ int ecryptfs_new_file_context(struct inode *ecryptfs_in= ode) struct ecryptfs_mount_crypt_stat *mount_crypt_stat =3D &ecryptfs_superblock_to_private( ecryptfs_inode->i_sb)->mount_crypt_stat; - int cipher_name_len; int rc =3D 0; =20 ecryptfs_set_default_crypt_stat_vals(crypt_stat, mount_crypt_stat); @@ -765,12 +764,8 @@ int ecryptfs_new_file_context(struct inode *ecryptfs_i= node) "to the inode key sigs; rc =3D [%d]\n", rc); goto out; } - cipher_name_len =3D - strlen(mount_crypt_stat->global_default_cipher_name); - memcpy(crypt_stat->cipher, - mount_crypt_stat->global_default_cipher_name, - cipher_name_len); - crypt_stat->cipher[cipher_name_len] =3D '\0'; + strscpy(crypt_stat->cipher, + mount_crypt_stat->global_default_cipher_name); crypt_stat->key_size =3D mount_crypt_stat->global_default_cipher_key_size; ecryptfs_generate_new_key(crypt_stat); --=20 2.51.1