Skip to content

Commit

Permalink
crypto: testmgr - add guard to dst buffer for ahash_export
Browse files Browse the repository at this point in the history
Add a guard to 'state' buffer and warn if its consistency after
call to crypto_ahash_export() changes, so that any write that
goes beyond advertised statesize (and thus causing potential
memory corruption [1]) is more visible.

[1] https://marc.info/?l=linux-crypto-vger&m=147467656516085

Signed-off-by: Jan Stancek <[email protected]>
Cc: Herbert Xu <[email protected]>
Cc: Marcelo Cerri <[email protected]>
Signed-off-by: Herbert Xu <[email protected]>
  • Loading branch information
jstancek authored and herbertx committed Oct 2, 2016
1 parent 3387879 commit 7bcb87b
Showing 1 changed file with 4 additions and 1 deletion.
5 changes: 4 additions & 1 deletion crypto/testmgr.c
Original file line number Diff line number Diff line change
Expand Up @@ -209,16 +209,19 @@ static int ahash_partial_update(struct ahash_request **preq,
char *state;
struct ahash_request *req;
int statesize, ret = -EINVAL;
const char guard[] = { 0x00, 0xba, 0xad, 0x00 };

req = *preq;
statesize = crypto_ahash_statesize(
crypto_ahash_reqtfm(req));
state = kmalloc(statesize, GFP_KERNEL);
state = kmalloc(statesize + sizeof(guard), GFP_KERNEL);
if (!state) {
pr_err("alt: hash: Failed to alloc state for %s\n", algo);
goto out_nostate;
}
memcpy(state + statesize, guard, sizeof(guard));
ret = crypto_ahash_export(req, state);
WARN_ON(memcmp(state + statesize, guard, sizeof(guard)));
if (ret) {
pr_err("alt: hash: Failed to export() for %s\n", algo);
goto out;
Expand Down

0 comments on commit 7bcb87b

Please sign in to comment.