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>] [day] [month] [year] [list]
Message-Id: <1524061020-32466-1-git-send-email-jingwei.liuxi@gmail.com>
Date:   Wed, 18 Apr 2018 07:17:00 -0700
From:   jingwei.liuxi@...il.com
To:     aryabinin@...tuozzo.com, glider@...gle.com, dvyukov@...gle.com
Cc:     kasan-dev@...glegroups.com, linux-kernel@...r.kernel.org,
        Victor Liu <jingwei.liuxi@...il.com>
Subject: [PATCH] kasan: modify the exception handling if kmalloc or krealloc return NULL

From: Victor Liu <jingwei.liuxi@...il.com>

Both kmalloc and krealloc may return NULL(!ptr1 || !ptr2), and we do not
know which one is.

Signed-off-by: Victor Liu <jingwei.liuxi@...il.com>
---
 lib/test_kasan.c | 25 ++++++++++++++++++-------
 1 file changed, 18 insertions(+), 7 deletions(-)

diff --git a/lib/test_kasan.c b/lib/test_kasan.c
index ec65710..afa10bf 100644
--- a/lib/test_kasan.c
+++ b/lib/test_kasan.c
@@ -153,9 +153,13 @@ static noinline void __init kmalloc_oob_krealloc_more(void)
 
 	pr_info("out-of-bounds after krealloc more\n");
 	ptr1 = kmalloc(size1, GFP_KERNEL);
+	if (!ptr1) {
+		pr_err("Allocation ptr1 failed\n");
+		return;
+	}
 	ptr2 = krealloc(ptr1, size2, GFP_KERNEL);
-	if (!ptr1 || !ptr2) {
-		pr_err("Allocation failed\n");
+	if (!ptr2) {
+		pr_err("Allocation ptr2 failed\n");
 		kfree(ptr1);
 		return;
 	}
@@ -172,9 +176,13 @@ static noinline void __init kmalloc_oob_krealloc_less(void)
 
 	pr_info("out-of-bounds after krealloc less\n");
 	ptr1 = kmalloc(size1, GFP_KERNEL);
+	if (!ptr1) {
+		pr_err("Allocation ptr1 failed\n");
+		return;
+	}
 	ptr2 = krealloc(ptr1, size2, GFP_KERNEL);
-	if (!ptr1 || !ptr2) {
-		pr_err("Allocation failed\n");
+	if (!ptr2) {
+		pr_err("Allocation ptr2 failed\n");
 		kfree(ptr1);
 		return;
 	}
@@ -190,11 +198,14 @@ static noinline void __init kmalloc_oob_16(void)
 
 	pr_info("kmalloc out-of-bounds for 16-bytes access\n");
 	ptr1 = kmalloc(sizeof(*ptr1) - 3, GFP_KERNEL);
+	if (!ptr1) {
+		pr_err("Allocation ptr1 failed\n");
+		return;
+	}
 	ptr2 = kmalloc(sizeof(*ptr2), GFP_KERNEL);
-	if (!ptr1 || !ptr2) {
-		pr_err("Allocation failed\n");
+	if (!ptr2) {
+		pr_err("Allocation ptr2 failed\n");
 		kfree(ptr1);
-		kfree(ptr2);
 		return;
 	}
 	*ptr1 = *ptr2;
-- 
2.7.4

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ