Skip to content

Commit a0a76e3

Browse files
tobluxjarkkojs
authored andcommitted
keys: Replace deprecated strncpy in ecryptfs_fill_auth_tok
strncpy() is deprecated for NUL-terminated destination buffers; use strscpy_pad() instead to retain the NUL-padding behavior of strncpy(). The destination buffer is initialized using kzalloc() with a 'signature' size of ECRYPTFS_PASSWORD_SIG_SIZE + 1. strncpy() then copies up to ECRYPTFS_PASSWORD_SIG_SIZE bytes from 'key_desc', NUL-padding any remaining bytes if needed, but expects the last byte to be zero. strscpy_pad() also copies the source string to 'signature', and NUL-pads the destination buffer if needed, but ensures it's always NUL-terminated without relying on it being zero-initialized. strscpy_pad() automatically determines the size of the fixed-length destination buffer via sizeof() when the optional size argument is omitted, making an explicit size unnecessary. In encrypted_init(), the source string 'key_desc' is validated by valid_ecryptfs_desc() before calling ecryptfs_fill_auth_tok(), and is therefore NUL-terminated and satisfies the __must_be_cstr() requirement of strscpy_pad(). Link: KSPP/linux#90 Signed-off-by: Thorsten Blum <thorsten.blum@linux.dev> Reviewed-by: Kees Cook <kees@kernel.org> Reviewed-by: Jarkko Sakkinen <jarkko@kernel.org> Reviewed-by: Paul Menzel <pmenzel@molgen.mpg.de> Signed-off-by: Jarkko Sakkinen <jarkko@kernel.org>
1 parent 58b4621 commit a0a76e3

1 file changed

Lines changed: 1 addition & 2 deletions

File tree

security/keys/encrypted-keys/ecryptfs_format.c

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -54,8 +54,7 @@ int ecryptfs_fill_auth_tok(struct ecryptfs_auth_tok *auth_tok,
5454
auth_tok->version = (((uint16_t)(major << 8) & 0xFF00)
5555
| ((uint16_t)minor & 0x00FF));
5656
auth_tok->token_type = ECRYPTFS_PASSWORD;
57-
strncpy((char *)auth_tok->token.password.signature, key_desc,
58-
ECRYPTFS_PASSWORD_SIG_SIZE);
57+
strscpy_pad(auth_tok->token.password.signature, key_desc);
5958
auth_tok->token.password.session_key_encryption_key_bytes =
6059
ECRYPTFS_MAX_KEY_BYTES;
6160
/*

0 commit comments

Comments
 (0)