lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Date:   Sat, 21 Oct 2017 19:53:54 +0200
From:   SF Markus Elfring <elfring@...rs.sourceforge.net>
To:     linux-crypto@...r.kernel.org,
        "David S. Miller" <davem@...emloft.net>,
        Herbert Xu <herbert@...dor.apana.org.au>
Cc:     LKML <linux-kernel@...r.kernel.org>,
        kernel-janitors@...r.kernel.org
Subject: [PATCH 1/2] crypto-testmgr: Use common error handling code in
 drbg_cavs_test()

From: Markus Elfring <elfring@...rs.sourceforge.net>
Date: Sat, 21 Oct 2017 19:29:11 +0200

Adjust jump targets so that a bit of exception handling can be better
reused at the end of this function.

This issue was detected by using the Coccinelle software.

Signed-off-by: Markus Elfring <elfring@...rs.sourceforge.net>
---
 crypto/testmgr.c | 31 ++++++++++++++++---------------
 1 file changed, 16 insertions(+), 15 deletions(-)

diff --git a/crypto/testmgr.c b/crypto/testmgr.c
index dd9c7f1c1c7b..76c5128284f8 100644
--- a/crypto/testmgr.c
+++ b/crypto/testmgr.c
@@ -1914,8 +1914,8 @@ static int drbg_cavs_test(const struct drbg_testvec *test, int pr,
 	if (IS_ERR(drng)) {
 		printk(KERN_ERR "alg: drbg: could not allocate DRNG handle for "
 		       "%s\n", driver);
-		kzfree(buf);
-		return -ENOMEM;
+		ret = -ENOMEM;
+		goto free_buffer;
 	}
 
 	test_data.testentropy = &testentropy;
@@ -1924,7 +1924,7 @@ static int drbg_cavs_test(const struct drbg_testvec *test, int pr,
 	ret = crypto_drbg_reset_test(drng, &pers, &test_data);
 	if (ret) {
 		printk(KERN_ERR "alg: drbg: Failed to reset rng\n");
-		goto outbuf;
+		goto free_rng;
 	}
 
 	drbg_string_fill(&addtl, test->addtla, test->addtllen);
@@ -1936,11 +1936,9 @@ static int drbg_cavs_test(const struct drbg_testvec *test, int pr,
 		ret = crypto_drbg_get_bytes_addtl(drng,
 			buf, test->expectedlen, &addtl);
 	}
-	if (ret < 0) {
-		printk(KERN_ERR "alg: drbg: could not obtain random data for "
-		       "driver %s\n", driver);
-		goto outbuf;
-	}
+
+	if (ret < 0)
+		goto report_failure;
 
 	drbg_string_fill(&addtl, test->addtlb, test->addtllen);
 	if (pr) {
@@ -1951,18 +1949,21 @@ static int drbg_cavs_test(const struct drbg_testvec *test, int pr,
 		ret = crypto_drbg_get_bytes_addtl(drng,
 			buf, test->expectedlen, &addtl);
 	}
-	if (ret < 0) {
-		printk(KERN_ERR "alg: drbg: could not obtain random data for "
-		       "driver %s\n", driver);
-		goto outbuf;
-	}
 
-	ret = memcmp(test->expected, buf, test->expectedlen);
+	if (ret < 0)
+		goto report_failure;
 
-outbuf:
+	ret = memcmp(test->expected, buf, test->expectedlen);
+free_rng:
 	crypto_free_rng(drng);
+free_buffer:
 	kzfree(buf);
 	return ret;
+
+report_failure:
+	pr_err("alg: drbg: could not obtain random data for driver %s\n",
+	       driver);
+	goto free_rng;
 }
 
 
-- 
2.14.2

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ