Skip to content

Commit 7bcb87b

Browse files
jstancekherbertx
authored andcommitted
crypto: testmgr - add guard to dst buffer for ahash_export
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 <jstancek@redhat.com> Cc: Herbert Xu <herbert@gondor.apana.org.au> Cc: Marcelo Cerri <marcelo.cerri@canonical.com> Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
1 parent 3387879 commit 7bcb87b

1 file changed

Lines changed: 4 additions & 1 deletion

File tree

‎crypto/testmgr.c‎

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -209,16 +209,19 @@ static int ahash_partial_update(struct ahash_request **preq,
209209
char *state;
210210
struct ahash_request *req;
211211
int statesize, ret = -EINVAL;
212+
const char guard[] = { 0x00, 0xba, 0xad, 0x00 };
212213

213214
req = *preq;
214215
statesize = crypto_ahash_statesize(
215216
crypto_ahash_reqtfm(req));
216-
state = kmalloc(statesize, GFP_KERNEL);
217+
state = kmalloc(statesize + sizeof(guard), GFP_KERNEL);
217218
if (!state) {
218219
pr_err("alt: hash: Failed to alloc state for %s\n", algo);
219220
goto out_nostate;
220221
}
222+
memcpy(state + statesize, guard, sizeof(guard));
221223
ret = crypto_ahash_export(req, state);
224+
WARN_ON(memcmp(state + statesize, guard, sizeof(guard)));
222225
if (ret) {
223226
pr_err("alt: hash: Failed to export() for %s\n", algo);
224227
goto out;

0 commit comments

Comments
 (0)