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]
Date:   Thu, 17 Aug 2017 14:54:20 +0300
From:   Dan Carpenter <dan.carpenter@...cle.com>
To:     Andrew Morton <akpm@...ux-foundation.org>,
        Matthew Wilcox <mawilcox@...rosoft.com>
Cc:     Stephen Rothwell <sfr@...b.auug.org.au>,
        Kees Cook <keescook@...omium.org>,
        Matthew Wilcox <mawilcox@...rosoft.com>,
        Bjorn Helgaas <bhelgaas@...gle.com>,
        Mauro Carvalho Chehab <mchehab@...nel.org>,
        Heikki Krogerus <heikki.krogerus@...ux.intel.com>,
        Daniel Micay <danielmicay@...il.com>,
        linux-kernel@...r.kernel.org, kernel-janitors@...r.kernel.org
Subject: [PATCH] lib/string.c: check for kmalloc() failure

This is mostly to keep the number of static checker warnings down so
we can spot new bugs instead of them being drowned in noise.  This
function doesn't return normal kernel error codes but instead the return
value is used to display exactly which memory failed.  I chose -1 as
hopefully that's a helpful thing to print.

Signed-off-by: Dan Carpenter <dan.carpenter@...cle.com>

diff --git a/lib/string.c b/lib/string.c
index 661a6a6173c0..59e112cbcf22 100644
--- a/lib/string.c
+++ b/lib/string.c
@@ -1058,7 +1058,11 @@ EXPORT_SYMBOL(fortify_overflow);
 static __init int memset16_selftest(void)
 {
 	unsigned i, j, k;
-	u16 v, *p = kmalloc(256 * 2 * 2, GFP_KERNEL);
+	u16 v, *p;
+
+	p = kmalloc(256 * 2 * 2, GFP_KERNEL);
+	if (!p)
+		return -1;
 
 	for (i = 0; i < 256; i++) {
 		for (j = 0; j < 256; j++) {
@@ -1090,7 +1094,11 @@ static __init int memset16_selftest(void)
 static __init int memset32_selftest(void)
 {
 	unsigned i, j, k;
-	u32 v, *p = kmalloc(256 * 2 * 4, GFP_KERNEL);
+	u32 v, *p;
+
+	p = kmalloc(256 * 2 * 4, GFP_KERNEL);
+	if (!p)
+		return -1;
 
 	for (i = 0; i < 256; i++) {
 		for (j = 0; j < 256; j++) {
@@ -1122,7 +1130,11 @@ static __init int memset32_selftest(void)
 static __init int memset64_selftest(void)
 {
 	unsigned i, j, k;
-	u64 v, *p = kmalloc(256 * 2 * 8, GFP_KERNEL);
+	u64 v, *p;
+
+	p = kmalloc(256 * 2 * 8, GFP_KERNEL);
+	if (!p)
+		return -1;
 
 	for (i = 0; i < 256; i++) {
 		for (j = 0; j < 256; j++) {

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ