]> git.ipfire.org Git - thirdparty/kernel/linux.git/commitdiff
crypto: lrw - Only add ecb if it is not already there
authorHerbert Xu <herbert@gondor.apana.org.au>
Thu, 15 May 2025 08:28:08 +0000 (16:28 +0800)
committerHerbert Xu <herbert@gondor.apana.org.au>
Mon, 19 May 2025 05:48:20 +0000 (13:48 +0800)
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: 700cb3f5fe75 ("crypto: lrw - Convert to skcipher")
Reported-by: kernel test robot <oliver.sang@intel.com>
Closes: https://lore.kernel.org/oe-lkp/202505151503.d8a6cf10-lkp@intel.com
Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
crypto/lrw.c

index e7f0368f8c97818dd6083be436f38ca98dbc9bb7..dd403b800513b3ff174f9af932dac4c88bae8d16 100644 (file)
@@ -322,7 +322,7 @@ static int lrw_create(struct crypto_template *tmpl, struct rtattr **tb)
 
        err = crypto_grab_skcipher(spawn, skcipher_crypto_instance(inst),
                                   cipher_name, 0, mask);
-       if (err == -ENOENT) {
+       if (err == -ENOENT && memcmp(cipher_name, "ecb(", 4)) {
                err = -ENAMETOOLONG;
                if (snprintf(ecb_name, CRYPTO_MAX_ALG_NAME, "ecb(%s)",
                             cipher_name) >= CRYPTO_MAX_ALG_NAME)
@@ -356,7 +356,7 @@ static int lrw_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(ecb_name, cipher_name + 4, sizeof(ecb_name));