Skip to content

Commit 48a9927

Browse files
pdxChenherbertx
authored andcommitted
crypto: mcryptd - Check mcryptd algorithm compatibility
Algorithms not compatible with mcryptd could be spawned by mcryptd with a direct crypto_alloc_tfm invocation using a "mcryptd(alg)" name construct. This causes mcryptd to crash the kernel if an arbitrary "alg" is incompatible and not intended to be used with mcryptd. It is an issue if AF_ALG tries to spawn mcryptd(alg) to expose it externally. But such algorithms must be used internally and not be exposed. We added a check to enforce that only internal algorithms are allowed with mcryptd at the time mcryptd is spawning an algorithm. Link: http://marc.info/?l=linux-crypto-vger&m=148063683310477&w=2 Cc: [email protected] Reported-by: Mikulas Patocka <[email protected]> Signed-off-by: Tim Chen <[email protected]> Signed-off-by: Herbert Xu <[email protected]>
1 parent 0c1e16c commit 48a9927

File tree

1 file changed

+12
-7
lines changed

1 file changed

+12
-7
lines changed

crypto/mcryptd.c

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -254,18 +254,22 @@ static void *mcryptd_alloc_instance(struct crypto_alg *alg, unsigned int head,
254254
goto out;
255255
}
256256

257-
static inline void mcryptd_check_internal(struct rtattr **tb, u32 *type,
257+
static inline bool mcryptd_check_internal(struct rtattr **tb, u32 *type,
258258
u32 *mask)
259259
{
260260
struct crypto_attr_type *algt;
261261

262262
algt = crypto_get_attr_type(tb);
263263
if (IS_ERR(algt))
264-
return;
265-
if ((algt->type & CRYPTO_ALG_INTERNAL))
266-
*type |= CRYPTO_ALG_INTERNAL;
267-
if ((algt->mask & CRYPTO_ALG_INTERNAL))
268-
*mask |= CRYPTO_ALG_INTERNAL;
264+
return false;
265+
266+
*type |= algt->type & CRYPTO_ALG_INTERNAL;
267+
*mask |= algt->mask & CRYPTO_ALG_INTERNAL;
268+
269+
if (*type & *mask & CRYPTO_ALG_INTERNAL)
270+
return true;
271+
else
272+
return false;
269273
}
270274

271275
static int mcryptd_hash_init_tfm(struct crypto_tfm *tfm)
@@ -492,7 +496,8 @@ static int mcryptd_create_hash(struct crypto_template *tmpl, struct rtattr **tb,
492496
u32 mask = 0;
493497
int err;
494498

495-
mcryptd_check_internal(tb, &type, &mask);
499+
if (!mcryptd_check_internal(tb, &type, &mask))
500+
return -EINVAL;
496501

497502
halg = ahash_attr_alg(tb[1], type, mask);
498503
if (IS_ERR(halg))

0 commit comments

Comments
 (0)