diff mbox

[v2,17/25] crypto: testmgr - Don't crash if CPRNG test result is large

Message ID d1fea6f576325fdcbb03a7dca6df79165f20516f.1417951990.git.linux@horizon.com (mailing list archive)
State RFC
Delegated to: Herbert Xu
Headers show

Commit Message

George Spelvin Dec. 7, 2014, 12:26 p.m. UTC
The idea is to catch as many programmer mistakes as possible.

Signed-off-by: George Spelvin <linux@horizon.com>
---
 crypto/testmgr.c | 5 +++++
 1 file changed, 5 insertions(+)
diff mbox

Patch

diff --git a/crypto/testmgr.c b/crypto/testmgr.c
index 9faf265f..6bf43682 100644
--- a/crypto/testmgr.c
+++ b/crypto/testmgr.c
@@ -1459,6 +1459,11 @@  static int test_cprng(struct crypto_rng *tfm,
 	u8 result[32];
 
 	for (i = 0; i < tcount; i++) {
+		if (template[i].rlen > sizeof(result)) {
+			printk(KERN_CRIT "alg: cprng: Cannot test %s\n", algo);
+			err = -EOVERFLOW;
+			break;
+		}
 		memset(result, 0, sizeof result);
 
 		err = crypto_rng_reset(tfm, template[i].seed, template[i].slen);