crypto: lrw,xts - Replace strlcpy with strscpy
authorAzeem Shaikh <azeemshaikh38@gmail.com>
Tue, 20 Jun 2023 20:08:32 +0000 (20:08 +0000)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Sat, 23 Sep 2023 09:11:01 +0000 (11:11 +0200)
commitad58d7ebbf936c3e9730cc3164af9753b276851c
tree3fd11b3aa29bd2d55f114356163fc5c89bc64d1f
parentac70101e5b94912c413e2e4d2e7e9d30ad38ea36
crypto: lrw,xts - Replace strlcpy with strscpy

[ Upstream commit babb80b3ecc6f40c962e13c654ebcd27f25ee327 ]

strlcpy() reads the entire source buffer first.
This read may exceed the destination size limit.
This is both inefficient and can lead to linear read
overflows if a source string is not NUL-terminated [1].
In an effort to remove strlcpy() completely [2], replace
strlcpy() here with strscpy().

Direct replacement is safe here since return value of -errno
is used to check for truncation instead of sizeof(dest).

[1] https://www.kernel.org/doc/html/latest/process/deprecated.html#strlcpy
[2] https://github.com/KSPP/linux/issues/89

Signed-off-by: Azeem Shaikh <azeemshaikh38@gmail.com>
Reviewed-by: Kees Cook <keescook@chromium.org>
Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
Signed-off-by: Sasha Levin <sashal@kernel.org>
crypto/lrw.c
crypto/xts.c