strncpy() is deprecated for use on NUL-terminated destination strings [1] and as such we should prefer more robust and less ambiguous string interfaces.
This modification is mainly due to the concerns on https://github.com/KSPP/linux/issues/336, where it was mentioned that strncpy_from_user is confusingly named as it does not NUL-pad the destination, but it does NOT guarantee NUL-termination. With this approach/patch we can always ensure that the dst buffer is NUL terminated. My initial guess was to create a separate function, something like strscpy_from_user that would use strscpy_chunk_from_user which would inturn use strscpy instead of the strncpy (like in this patch). But I'm new quite unsure about adding new functions to kernel code. I'm open to other ideas and/or approach as well, since I'm quit sure there might be a better way to handle this. [1]: https://www.kernel.org/doc/html/latest/process/deprecated.html#strncpy-on-nul-terminated-strings Signed-off-by: Brahmajit Das <[email protected]> --- arch/um/kernel/skas/uaccess.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/arch/um/kernel/skas/uaccess.c b/arch/um/kernel/skas/uaccess.c index 198269e384c4..c00ef385591c 100644 --- a/arch/um/kernel/skas/uaccess.c +++ b/arch/um/kernel/skas/uaccess.c @@ -170,7 +170,7 @@ static int strncpy_chunk_from_user(unsigned long from, int len, void *arg) char **to_ptr = arg, *to = *to_ptr; int n; - strncpy(to, (void *) from, len); + strscpy(to, (void *) from, len); n = strnlen(to, len); *to_ptr += n; -- 2.49.0
