crypto: algboss - avoid creating duplicated cipher instances
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
@@ -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
Herbert Xu
maintainerPATCH 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
@@ -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