Skip to content

Commit d550448

Browse files
Russell Kinglinux4kix
authored andcommitted
crypto: ensure algif_hash does not pass a zero-sized state
If the algorithm passed a zero statesize, do not pass a valid pointer into the export/import functions. Passing a valid pointer covers up bugs in driver code which then go on to smash the kernel stack. Instead, pass NULL, which will cause any attempt to write to the pointer to fail. Signed-off-by: Russell King <rmk+kernel@arm.linux.org.uk>
1 parent 479e880 commit d550448

2 files changed

Lines changed: 4 additions & 2 deletions

File tree

crypto/ahash.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -465,7 +465,8 @@ static int ahash_prepare_alg(struct ahash_alg *alg)
465465
struct crypto_alg *base = &alg->halg.base;
466466

467467
if (alg->halg.digestsize > PAGE_SIZE / 8 ||
468-
alg->halg.statesize > PAGE_SIZE / 8)
468+
alg->halg.statesize > PAGE_SIZE / 8 ||
469+
alg->halg.statesize == 0)
469470
return -EINVAL;
470471

471472
base->cra_type = &crypto_ahash_type;

crypto/shash.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -589,7 +589,8 @@ static int shash_prepare_alg(struct shash_alg *alg)
589589

590590
if (alg->digestsize > PAGE_SIZE / 8 ||
591591
alg->descsize > PAGE_SIZE / 8 ||
592-
alg->statesize > PAGE_SIZE / 8)
592+
alg->statesize > PAGE_SIZE / 8 ||
593+
alg->statesize == 0)
593594
return -EINVAL;
594595

595596
base->cra_type = &crypto_shash_type;

0 commit comments

Comments
 (0)