summaryrefslogtreecommitdiff
path: root/crypto/xts.c
diff options
context:
space:
mode:
authorAzeem Shaikh <azeemshaikh38@gmail.com>2023-06-20 20:08:32 +0000
committerHerbert Xu <herbert@gondor.apana.org.au>2023-07-14 18:23:14 +1000
commit04902aa6217b01e858cc7cd8f287da39418ede3a (patch)
tree23e0060cb0c1c0d56dc306f70cce196b55c83fc4 /crypto/xts.c
parent2d439db8f7402cd2fa3b848f308f503300bb6a73 (diff)
downloadlinux-crypto-04902aa6217b01e858cc7cd8f287da39418ede3a.tar.gz
linux-crypto-04902aa6217b01e858cc7cd8f287da39418ede3a.zip
crypto: lrw,xts - Replace strlcpy with strscpy
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>
Diffstat (limited to 'crypto/xts.c')
-rw-r--r--crypto/xts.c6
1 files changed, 3 insertions, 3 deletions
diff --git a/crypto/xts.c b/crypto/xts.c
index 09be909a..548b302c 100644
--- a/crypto/xts.c
+++ b/crypto/xts.c
@@ -396,10 +396,10 @@ static int xts_create(struct crypto_template *tmpl, struct rtattr **tb)
* cipher name.
*/
if (!strncmp(cipher_name, "ecb(", 4)) {
- unsigned len;
+ int len;
- len = strlcpy(ctx->name, cipher_name + 4, sizeof(ctx->name));
- if (len < 2 || len >= sizeof(ctx->name))
+ len = strscpy(ctx->name, cipher_name + 4, sizeof(ctx->name));
+ if (len < 2)
goto err_free_inst;
if (ctx->name[len - 1] != ')')