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: <20150719105319.GC8410@mwanda>
Date:	Sun, 19 Jul 2015 13:53:19 +0300
From:	Dan Carpenter <dan.carpenter@...cle.com>
To:	Andrew Morton <akpm@...ux-foundation.org>,
	Vladimir Zapolskiy <vladimir_zapolskiy@...tor.com>
Cc:	Catalin Marinas <catalin.marinas@....com>,
	Laura Abbott <lauraa@...eaurora.org>,
	Olof Johansson <olof@...om.net>,
	Rasmus Villemoes <linux@...musvillemoes.dk>,
	Jan Kara <jack@...e.cz>, Toshi Kikuchi <toshik@...omium.org>,
	linux-kernel@...r.kernel.org, kernel-janitors@...r.kernel.org
Subject: [patch] genalloc: freeing const data pointers

"pool->name" can be kmalloc()ed or const so we need to free it with
kfree_const().

I also cleaned up the error path in devm_gen_pool_create() a bit.  With
the current code you have to change the kfree() in multiple places
which is bug prone (my first draft of this patch had a bug).

Fixes: e89a70fd54f2 ('genalloc: add support of multiple gen_pools per device')
Signed-off-by: Dan Carpenter <dan.carpenter@...cle.com>

diff --git a/lib/genalloc.c b/lib/genalloc.c
index 794804b..c729113 100644
--- a/lib/genalloc.c
+++ b/lib/genalloc.c
@@ -253,7 +253,7 @@ void gen_pool_destroy(struct gen_pool *pool)
 
 		kfree(chunk);
 	}
-	kfree(pool->name);
+	kfree_const(pool->name);
 	kfree(pool);
 }
 EXPORT_SYMBOL(gen_pool_destroy);
@@ -631,23 +631,25 @@ struct gen_pool *devm_gen_pool_create(struct device *dev, int min_alloc_order,
 	}
 
 	ptr = devres_alloc(devm_gen_pool_release, sizeof(*ptr), GFP_KERNEL);
-	if (!ptr) {
-		kfree(pool_name);
-		return ERR_PTR(-ENOMEM);
-	}
+	if (!ptr)
+		goto free_pool_name;
 
 	pool = gen_pool_create(min_alloc_order, nid);
-	if (pool) {
-		*ptr = pool;
-		pool->name = pool_name;
-		devres_add(dev, ptr);
-	} else {
-		devres_free(ptr);
-		kfree(pool_name);
-		return ERR_PTR(-ENOMEM);
-	}
+	if (!pool)
+		goto free_devres;
+
+	*ptr = pool;
+	pool->name = pool_name;
+	devres_add(dev, ptr);
 
 	return pool;
+
+free_devres:
+	devres_free(ptr);
+free_pool_name:
+	kfree_const(pool_name);
+
+	return ERR_PTR(-ENOMEM);
 }
 EXPORT_SYMBOL(devm_gen_pool_create);
 
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@...r.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ