Commit babb80b3 authored by Azeem Shaikh's avatar Azeem Shaikh Committed by Herbert Xu

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/89Signed-off-by: default avatarAzeem Shaikh <azeemshaikh38@gmail.com>
Reviewed-by: default avatarKees Cook <keescook@chromium.org>
Signed-off-by: default avatarHerbert Xu <herbert@gondor.apana.org.au>
parent 31ba6dd2
...@@ -357,10 +357,10 @@ static int lrw_create(struct crypto_template *tmpl, struct rtattr **tb) ...@@ -357,10 +357,10 @@ static int lrw_create(struct crypto_template *tmpl, struct rtattr **tb)
* cipher name. * cipher name.
*/ */
if (!strncmp(cipher_name, "ecb(", 4)) { if (!strncmp(cipher_name, "ecb(", 4)) {
unsigned len; int len;
len = strlcpy(ecb_name, cipher_name + 4, sizeof(ecb_name)); len = strscpy(ecb_name, cipher_name + 4, sizeof(ecb_name));
if (len < 2 || len >= sizeof(ecb_name)) if (len < 2)
goto err_free_inst; goto err_free_inst;
if (ecb_name[len - 1] != ')') if (ecb_name[len - 1] != ')')
......
...@@ -396,10 +396,10 @@ static int xts_create(struct crypto_template *tmpl, struct rtattr **tb) ...@@ -396,10 +396,10 @@ static int xts_create(struct crypto_template *tmpl, struct rtattr **tb)
* cipher name. * cipher name.
*/ */
if (!strncmp(cipher_name, "ecb(", 4)) { if (!strncmp(cipher_name, "ecb(", 4)) {
unsigned len; int len;
len = strlcpy(ctx->name, cipher_name + 4, sizeof(ctx->name)); len = strscpy(ctx->name, cipher_name + 4, sizeof(ctx->name));
if (len < 2 || len >= sizeof(ctx->name)) if (len < 2)
goto err_free_inst; goto err_free_inst;
if (ctx->name[len - 1] != ')') if (ctx->name[len - 1] != ')')
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment