]> git.ipfire.org Git - thirdparty/kernel/stable.git/commitdiff
crypto: xts - Only add ecb if it is not already there
authorHerbert Xu <herbert@gondor.apana.org.au>
Thu, 15 May 2025 08:34:04 +0000 (16:34 +0800)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Fri, 27 Jun 2025 10:04:01 +0000 (11:04 +0100)
[ Upstream commit 270b6f13454cb7f2f7058c50df64df409c5dcf55 ]

Only add ecb to the cipher name if it isn't already ecb.

Also use memcmp instead of strncmp since these strings are all
stored in an array of length CRYPTO_MAX_ALG_NAME.

Fixes: f1c131b45410 ("crypto: xts - Convert to skcipher")
Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
Signed-off-by: Sasha Levin <sashal@kernel.org>
crypto/xts.c

index 74dc199d5486707399f64777b13be14376589a50..a4677e1a1611f2f7663f4a5491bf6fbff1d24670 100644 (file)
@@ -360,7 +360,7 @@ static int xts_create(struct crypto_template *tmpl, struct rtattr **tb)
 
        err = crypto_grab_skcipher(&ctx->spawn, skcipher_crypto_instance(inst),
                                   cipher_name, 0, mask);
-       if (err == -ENOENT) {
+       if (err == -ENOENT && memcmp(cipher_name, "ecb(", 4)) {
                err = -ENAMETOOLONG;
                if (snprintf(ctx->name, CRYPTO_MAX_ALG_NAME, "ecb(%s)",
                             cipher_name) >= CRYPTO_MAX_ALG_NAME)
@@ -394,7 +394,7 @@ static int xts_create(struct crypto_template *tmpl, struct rtattr **tb)
        /* Alas we screwed up the naming so we have to mangle the
         * cipher name.
         */
-       if (!strncmp(cipher_name, "ecb(", 4)) {
+       if (!memcmp(cipher_name, "ecb(", 4)) {
                int len;
 
                len = strscpy(ctx->name, cipher_name + 4, sizeof(ctx->name));