From nobody Sun Feb 8 05:40:26 2026 Received: from out-173.mta1.migadu.com (out-173.mta1.migadu.com [95.215.58.173]) (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 4521D7262A for ; Sun, 11 Jan 2026 13:13:47 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=95.215.58.173 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1768137228; cv=none; b=IQ8cAqeVgIXYICE9pVb2pPGyCGGagDESqNRaqu/Ts5NdBjnoS/7tKumhmG0Mj6FZcyexPDSqUxHl36qQ6xTSz67zU4kpTKpNUes89jgcvP22XZwYWW+TJ1ugVlUvTXSBp7LqBQbHVm73gfjlndclmv3cSgVGisxU0rFsn6DWsKU= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1768137228; c=relaxed/simple; bh=CgWO6Id73rCP6/y2Y8fou5Y0+7K5wwfPfaPW8MUDL48=; h=From:To:Cc:Subject:Date:Message-ID:MIME-Version; b=HYrDtQ3EcwCCuB329xsu4I4GvHtSGAmX3LXo9I41zQ5V4Bj+7h65tmK5RsAtU083fTEK5Y6KtOje9sTuqQjp1mns9ihurmg6+CAwZoNYK6WdRLH5z948udwWU+/Ztiqcss4vVsq32jk8dxDVCRgV7kdSigkn3CRbLUj9yuin0f4= 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=jrj7zW5k; arc=none smtp.client-ip=95.215.58.173 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="jrj7zW5k" 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=1768137215; 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=GGUP682yaNROfHL+XCP9B1qwuZ5gOAf9MVFN1gTeSiQ=; b=jrj7zW5kWBso9CqwcpIaWI/SNXkQH7gaNIdwI5nOtki0NRm2YTSs5qacCeiWzcfs0StZdp ZODFfdtgavzygzD0A21/h4C2KOBOflpQKgz10hDCSQy7cxRS+Lf7I6Jo8zXUmW2J1mpqL9 FQEr8lsreID6gln0rapctB9A+Nk87nk= From: Thorsten Blum To: Tyler Hicks , Thorsten Blum , Ard Biesheuvel , Christian Brauner , Eric Biggers , Zipeng Zhang Cc: ecryptfs@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH] ecryptfs: Replace memcpy + NUL termination in ecryptfs_copy_filename Date: Sun, 11 Jan 2026 14:12:58 +0100 Message-ID: <20260111131301.548411-1-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 kmemdup_nul() to copy 'name' instead of using memcpy() followed by a manual NUL termination. Remove the local return variable and the goto label to simplify the code. No functional changes. Signed-off-by: Thorsten Blum Acked-by: Tyler Hicks --- fs/ecryptfs/crypto.c | 18 ++++-------------- 1 file changed, 4 insertions(+), 14 deletions(-) diff --git a/fs/ecryptfs/crypto.c b/fs/ecryptfs/crypto.c index d49cdf7292ab..82fc5e1b6324 100644 --- a/fs/ecryptfs/crypto.c +++ b/fs/ecryptfs/crypto.c @@ -1422,21 +1422,11 @@ ecryptfs_encrypt_filename(struct ecryptfs_filename = *filename, static int ecryptfs_copy_filename(char **copied_name, size_t *copied_name_= size, const char *name, size_t name_size) { - int rc =3D 0; - - (*copied_name) =3D kmalloc((name_size + 1), GFP_KERNEL); - if (!(*copied_name)) { - rc =3D -ENOMEM; - goto out; - } - memcpy((void *)(*copied_name), (void *)name, name_size); - (*copied_name)[(name_size)] =3D '\0'; /* Only for convenience - * in printing out the - * string in debug - * messages */ + (*copied_name) =3D kmemdup_nul(name, name_size, GFP_KERNEL); + if (!(*copied_name)) + return -ENOMEM; (*copied_name_size) =3D name_size; -out: - return rc; + return 0; } =20 /** --=20 Thorsten Blum GPG: 1D60 735E 8AEF 3BE4 73B6 9D84 7336 78FD 8DFE EAD4