Skip to contentSkip to conversation

crypto: algboss - avoid creating duplicated cipher instances

PATCH New [email protected] 2 participants 2 messages Dec 6, 2023 – Dec 7, 2023 Crypto API

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 crypto: algboss - avoid creating duplicated cipher instances

From: Ovidiu Panait <[email protected]>

Currently, it is possible to create duplicated /proc/crypto entries for the same algorithm with the following test program:
"""
#include <sys/socket.h>
#include <linux/if_alg.h>

  int main(void)
  {
          struct sockaddr_alg sa = {
                  .salg_family = AF_ALG,
                  .salg_type = "skcipher",
                  .salg_name = "xts(ecb(aes-generic))extra-bytes",
          };
          int tfmfd;
          tfmfd = socket(AF_ALG, SOCK_SEQPACKET, 0);
          bind(tfmfd, (struct sockaddr *)&sa, sizeof(sa));

}
"""

When the alg name contains extra bogus characters after a valid template, the bind() call fails, but a duplicated entry is still registered (in this case xts(ecb(aes-generic))).

To fix this, add a check in cryptomgr_schedule_probe() for trailing characters after a valid template.

---
 crypto/algboss.c | 6 +++++-
 1 file changed, 5 insertions(+), 1 deletion(-)
crypto/algboss.c +5 -1
index 0de1e6697949..8e8039b845a3 100644
@@ -131,8 +131,12 @@ static int cryptomgr_schedule_probe(struct crypto_larval *larval)
 		if (i >= CRYPTO_MAX_ATTRS)
 			goto err_free_param;
 
-		if (*p == ')')
+		if (*p == ')') {
+			if (*++p)
+				goto err_free_param;
+
 			break;
+		}
 
 		if (*p != ',')
 			goto err_free_param;
Signature · 1 line
2.34.1
maintainer
#1 lore raw

PATCH 1/1 crypto: api - Disallow identical driver names

Quoted 7 lines · On Wed, Dec 06, 2023 at 10:37:43PM +0200, [email protected] wrote:

When the alg name contains extra bogus characters after a valid template, the bind() call fails, but a duplicated entry is still registered (in this case xts(ecb(aes-generic))).

To fix this, add a check in cryptomgr_schedule_probe() for trailing characters after a valid template.

Thanks for the report!

This is definitely not good. However, I think it's an existing bug in the algorithm registration code:

---8<---
Disallow registration of two algorithms with identical driver names.

crypto/algapi.c +1 -0
index 4fe95c448047..85bc279b4233 100644
@@ -341,6 +341,7 @@ __crypto_register_alg(struct crypto_alg *alg, struct list_head *algs_to_put)
 		}
 
 		if (!strcmp(q->cra_driver_name, alg->cra_name) ||
+		    !strcmp(q->cra_driver_name, alg->cra_driver_name) ||
 		    !strcmp(q->cra_name, alg->cra_driver_name))
 			goto err;
 	}
Signature · 3 lines
Email: Herbert Xu <[email protected]>
Home Page: http://gondor.apana.org.au/~herbert/
PGP Key: http://gondor.apana.org.au/~herbert/pubkey.txt