Skip to contentSkip to conversation

keys: Replace deprecated strncpy in ecryptfs_fill_auth_tok

PATCH Superseded Thorsten Blum 3 participants 3 messages Oct 9, 2025 – Oct 10, 2025

Subsystems (4)

v1 of 3 Superseded Latest is v3 →

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 keys: Replace deprecated strncpy in ecryptfs_fill_auth_tok

strncpy() is deprecated for NUL-terminated destination buffers; use strscpy_pad() instead.

---
 security/keys/encrypted-keys/ecryptfs_format.c | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)
security/keys/encrypted-keys/ecryptfs_format.c +1 -2
index 8fdd76105ce3..2fc6f3a66135 100644
@@ -54,8 +54,7 @@ int ecryptfs_fill_auth_tok(struct ecryptfs_auth_tok *auth_tok,
 	auth_tok->version = (((uint16_t)(major << 8) & 0xFF00)
 			     | ((uint16_t)minor & 0x00FF));
 	auth_tok->token_type = ECRYPTFS_PASSWORD;
-	strncpy((char *)auth_tok->token.password.signature, key_desc,
-		ECRYPTFS_PASSWORD_SIG_SIZE);
+	strscpy_pad(auth_tok->token.password.signature, key_desc);
 	auth_tok->token.password.session_key_encryption_key_bytes =
 		ECRYPTFS_MAX_KEY_BYTES;
 	/*
Signature · 1 line
2.51.0
maintainer
#1 lore raw
Quoted 5 lines · Thorsten Blum

strncpy() is deprecated for NUL-terminated destination buffers; use strscpy_pad() instead.

Deprecated or not but commit message still should have a better explanation :-) Sure there's also the link too that explains it all but still one should get the gist without cross-referencing into it.

It's a permanent amortized cost as everytime when revisiting this commit (e.g. over the course of bisecting or whatever), you need a web browser in order to make anything out of the message.

Quoted 21 lines
---
 security/keys/encrypted-keys/ecryptfs_format.c | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)
security/keys/encrypted-keys/ecryptfs_format.c +1 -2
index 8fdd76105ce3..2fc6f3a66135 100644
@@ -54,8 +54,7 @@ int ecryptfs_fill_auth_tok(struct ecryptfs_auth_tok *auth_tok,
 	auth_tok->version = (((uint16_t)(major << 8) & 0xFF00)
 			     | ((uint16_t)minor & 0x00FF));
 	auth_tok->token_type = ECRYPTFS_PASSWORD;
-	strncpy((char *)auth_tok->token.password.signature, key_desc,
-		ECRYPTFS_PASSWORD_SIG_SIZE);
+	strscpy_pad(auth_tok->token.password.signature, key_desc);
 	auth_tok->token.password.session_key_encryption_key_bytes =
 		ECRYPTFS_MAX_KEY_BYTES;
 	/*
Signature · 1 line
2.51.0

BR, Jarkko

#2 lore raw
In reply to Thorsten Blum
Quoted 2 lines · Thorsten Blum

strncpy() is deprecated for NUL-terminated destination buffers; use strscpy_pad() instead.

Remember for strncpy->strscpy conversions, the commit message needs to include:

- how did you determine this was a NUL-terminated destination?
- how did you determine the need for padding or not?
- how do you know that final byte truncation is not a problem?

-Kees

Quoted 25 lines
---
 security/keys/encrypted-keys/ecryptfs_format.c | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)
security/keys/encrypted-keys/ecryptfs_format.c +1 -2
index 8fdd76105ce3..2fc6f3a66135 100644
@@ -54,8 +54,7 @@ int ecryptfs_fill_auth_tok(struct ecryptfs_auth_tok *auth_tok,
 	auth_tok->version = (((uint16_t)(major << 8) & 0xFF00)
 			     | ((uint16_t)minor & 0x00FF));
 	auth_tok->token_type = ECRYPTFS_PASSWORD;
-	strncpy((char *)auth_tok->token.password.signature, key_desc,
-		ECRYPTFS_PASSWORD_SIG_SIZE);
+	strscpy_pad(auth_tok->token.password.signature, key_desc);
 	auth_tok->token.password.session_key_encryption_key_bytes =
 		ECRYPTFS_MAX_KEY_BYTES;
 	/*
Signature · 1 line
2.51.0
Signature · 1 line
Kees Cook